access(...,X_OK) for root

Wes Cowley (
Wed, 11 Oct 1995 22:21:21 -0400 (EDT)

I ran into what looked to be a bug in pdksh's "test -x" when running as
root. pdksh will pass that test for any file, where bash will (correctly I
think) recognize a file that doesn't have executable permission for any user
as not executable by root.

I've traced pdksh's behaviour back to ext2_permission() in fs/ext2/acl.c:

int ext2_permission (struct inode * inode, int mask)
unsigned short mode = inode->i_mode;

* Nobody gets write access to an immutable file
if ((mask & S_IWOTH) && IS_IMMUTABLE(inode))
return -EACCES;
* Special case, access is always granted for root
-----> if (fsuser())
-----> return 0;
* If no ACL, checks using the file mode
else if (current->fsuid == inode->i_uid)
mode >>= 6;
else if (in_group_p (inode->i_gid))
mode >>= 3;
if (((mode & mask & S_IRWXO) == mask))
return 0;
return -EACCES;

It seems to me that the exemption for root shouldn't apply if mask is
X_OK, rather it should return 0 only if the file is executable by anyone
and -EACCES otherwise.

Perhaps (untested):

if (fsuser())
/* S_IXOTH really should be X_OK but that doesn't seem to be
visible here */
if (mask == S_IXOTH && !(mode & S_IXUGO))
return -EACCESS;
return 0;

Does this make sense, or is there a reason for the current behaviour?