Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-04-07
04:37 • Ticket [930225ffff] access() - safe to use? status still Closed with 4 other... artifact: da5161678c user: dkf
03:59 • Ticket [930225ffff]: 4 changes artifact: bfedb3f66f user: dgp
03:29 • Closed ticket [930225ffff]. artifact: 7e532d07c5 user: dgp
2004-04-06
21:38 • Ticket [930225ffff]: 4 changes artifact: 708c29db03 user: dkf
20:40 • Ticket [930225ffff]: 4 changes artifact: 13c78716c4 user: dgp
16:36 • Ticket [930225ffff]: 4 changes artifact: e43fca3828 user: dkf
14:26 • Ticket [930225ffff]: 5 changes artifact: 339a27b884 user: vincentdarley
05:13 • New ticket [930225ffff]. artifact: c8a2079af6 user: dgp

access() - safe to use?

Closed / Wont Fix930225ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2004-04-06 05:13:52
While reading man pages on the
access() system call, I came across:

CAVEAT
     Access() is a potential security hole and should
never be used.

Yet, the access() call is the implementation
of Tcl_FSAccess() on native Unix filesystems
in tcl/unix/tclUnixFile.c
vincentdarleyplain2004-04-06 14:26:10
Logged In: YES 
user_id=32170

I know nothing about such unix-specific technicalities (and
don't really want to learn ;-)... assigning to someone who does.
dkfplain2004-04-06 16:36:42
Logged In: YES 
user_id=79902

Which OS states this in its manpages?

The security problems of access() only really bite when
running setuid/setgid, since you otherwise go through the
same set of checks internally when you manipulate the file
with open(), etc.  Luckily, that's not a normal
configuration of Tcl so we can ignore it for now.

The alternatives are to stat() and check the permissions on
the file ourselves (which has exactly the same security
problems) or open the file and either check the result or do
an fstat(), which has its own set of problems (especially
when writing a file.)

Everything gets *much* more complex when you use AFS or some
other filesystem with ACLs, and it turns out that the
access(2) manpage on RH9 is wrong (as access() checks ACLs)
and is therefore not replacable with any *stat() based solution.

I think the only "fix" is to warn people writing scripts
that run setuid/setgid to be very careful.  And beware of
scaremongering manual pages.
dgpplain2004-04-06 20:40:21
Logged In: YES 
user_id=80530

I was on a Mac OS X Panther
system when I read that.

I think the man page originally
came from some BSD.
dkfplain2004-04-06 21:38:30
Logged In: YES 
user_id=79902

OK, access(2) is broken-by-design but we can't substitute
for anything else.  Solution is for *users* to avoid it when
running in a Tcl interpreter with non-trivial privileges. 
In theory we could enforce this by refusing to call access()
when the real and effective [ug]ids are different, but that
would be very intrusive.

A better solution would be to provide access to something
like fstat() so that code could check that it has opened
what it thinks it has opened...?
dgpplain2004-04-07 03:29:06
Logged In: YES 
user_id=80530

Fair enough.

For the record, besides Tcl_FSAccess()
and  Tcl_Access()
itself, this will impact the built-in commands

[file executable|writable|readable|link], [cd],
[load] on all platforms, and [exec] and [open "|..."] 
on Windows.
dgpplain2004-04-07 03:59:31
Logged In: YES 
user_id=80530

Ignore the part  of my last comment
about Windows.  access() is not used
there.
dkfplain2004-04-07 04:37:47
Logged In: YES 
user_id=79902

Neither [cd] nor [load] are affected on native filesystems.
 OTOH, [file executable] etc are, but that's because they're
just a wrapper round access()'s basic functionality.

In general, if you can it is better to just [open] (with the
right options; with the wrong ones you still have a security
hole) or [exec] the file and check for errors in the process.
Log in (anonymous is fine) to add a comment.