Skip to contentSkip to conversation

permission() bug?

PATCH Andreas Gruenbacher 3 participants 4 messages Feb 1, 2004 – Feb 2, 2004

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hello Andrew,

the fix for permission() that makes it compliant with POSIX.1-2001 apparently was lost. Here is the patch I sent before. (The relevant lines from the standard text are cited in
http://www.ussg.iu.edu/hypermail/linux/kernel/0310.2/0286.html. The fix proposed in that posting did not handle directories without execute permissions correctly.)

Could you please apply the attached patch to mainline? Thanks.

Regards,

Signature · 2 lines
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX AG

Make permission check conform to POSIX.1-2001

The access(2) function does not conform to POSIX.1-2001: For root and a file with no permissions, access(file, MAY_READ|MAY_EXEC) returns 0 (it should return -1).

fs/jfs/acl.c +2 -1
Index: linux-2.6.0+fix/fs/jfs/acl.c
===================================================================
@@ -191,7 +191,8 @@ check_capabilities:
 	 * Read/write DACs are always overridable.
 	 * Executable DACs are overridable if at least one exec bit is set.
 	 */
-	if ((mask & (MAY_READ|MAY_WRITE)) || (inode->i_mode & S_IXUGO))
+	if (!(mask & MAY_EXEC) ||
+	    (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
 		if (capable(CAP_DAC_OVERRIDE))
 			return 0;
 
fs/xfs/xfs_inode.c +2 -1
Index: linux-2.6.0+fix/fs/xfs/xfs_inode.c
===================================================================
@@ -3722,7 +3722,8 @@ xfs_iaccess(
 	 * Read/write DACs are always overridable.
 	 * Executable DACs are overridable if at least one exec bit is set.
 	 */
-	if ((orgmode & (S_IRUSR|S_IWUSR)) || (inode->i_mode & S_IXUGO))
+	if (!(orgmode & S_IXUSR) || (inode->i_mode & S_IXUGO) ||
+	    (ip->i_d.di_mode & S_IFMT) == S_IFDIR)
 		if (capable_cred(cr, CAP_DAC_OVERRIDE))
 			return 0;
 
fs/ext2/acl.c +2 -1
Index: linux-2.6.0+fix/fs/ext2/acl.c
===================================================================
@@ -322,7 +322,8 @@ check_groups:
 
 check_capabilities:
 	/* Allowed to override Discretionary Access Control? */
-	if ((mask & (MAY_READ|MAY_WRITE)) || (inode->i_mode & S_IXUGO))
+	if (!(mask & MAY_EXEC) ||
+	    (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
 		if (capable(CAP_DAC_OVERRIDE))
 			return 0;
 	/* Read and search granted if capable(CAP_DAC_READ_SEARCH) */
fs/ext3/acl.c +2 -1
Index: linux-2.6.0+fix/fs/ext3/acl.c
===================================================================
@@ -327,7 +327,8 @@ check_groups:
 
 check_capabilities:
 	/* Allowed to override Discretionary Access Control? */
-	if ((mask & (MAY_READ|MAY_WRITE)) || (inode->i_mode & S_IXUGO))
+	if (!(mask & MAY_EXEC) ||
+	    (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
 		if (capable(CAP_DAC_OVERRIDE))
 			return 0;
 	/* Read and search granted if capable(CAP_DAC_READ_SEARCH) */
fs/namei.c +2 -1
Index: linux-2.6.0+fix/fs/namei.c
===================================================================
@@ -190,7 +190,8 @@ int vfs_permission(struct inode * inode,
 	 * Read/write DACs are always overridable.
 	 * Executable DACs are overridable if at least one exec bit is set.
 	 */
-	if ((mask & (MAY_READ|MAY_WRITE)) || (inode->i_mode & S_IXUGO))
+	if (!(mask & MAY_EXEC) ||
+	    (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
 		if (capable(CAP_DAC_OVERRIDE))
 			return 0;
 
#1 lore raw
Quoted 7 lines · Andreas Gruenbacher

the fix for permission() that makes it compliant with POSIX.1-2001 apparently was lost. Here is the patch I sent before. (The relevant lines from the standard text are cited in
http://www.ussg.iu.edu/hypermail/linux/kernel/0310.2/0286.html. The fix proposed in that posting did not handle directories without execute permissions correctly.)

Question is: should we fix it? I'm not aware of any bug reports against this behaviour, and there is the possibility that changing it now will break some applications.

Yes, those applications are presumably broken on other OS's but that's different.

Given that this has been a longstanding misbehaviour in Linux (yes?) maybe the most prudent path is to remain bug-compatible?

I'll add the patch to -mm so we can pick up any obvious userspace breakage, but it is likely that such problems will take a long time to emerge.

Quoted 3 lines

The access(2) function does not conform to POSIX.1-2001: For root and a file with no permissions, access(file, MAY_READ|MAY_EXEC) returns 0 (it should return -1).

So are you saying that in this case access() is, in effect, returning

	access(file, MAY_READ) || access(file, MAY_EXEC)

whereas it should be returning

	access(file, MAY_READ) && access(file, MAY_EXEC)

?

#2 lore raw
Quoted 5 lines · Andrew Morton
Quoted 1 line

the fix for permission() that makes it compliant with POSIX.1-2001

Question is: should we fix it? I'm not aware of any bug reports against this behaviour, and there is the possibility that changing it now will break some applications.

Quite apart from this particular case, the general answer to such questions should be Yes.

It must not be the case that Linux is roughly speaking POSIX-conforming but deviates in a thousand obscure ways.

When a deviation is noticed, changing to be POSIX-conforming should be the default action. Of course, some POSIX requirements are rather unfortunate, and in individual cases there can be a good reason not to change. Such individual cases should be discussed and well documented.

In a case like this, where it is clear that Linux is buggy, the bug should just be fixed. Of course it is your call to choose between fixing a bug and keeping a stable interface. If you choose the latter this must be fixed in 2.7.

(By the way - 2.0.34 and 2.2.19 do not have this bug, 2.4.18 has.)

Andries

#3 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Andreas Gruenbacher

the fix for permission() that makes it compliant with POSIX.1-2001 apparently was lost. Here is the patch I sent before. (The relevant lines from the standard text are cited in
http://www.ussg.iu.edu/hypermail/linux/kernel/0310.2/0286.html. The fix proposed in that posting did not handle directories without execute permissions correctly.)

Quoted 3 lines

Question is: should we fix it? I'm not aware of any bug reports against this behaviour, and there is the possibility that changing it now will break some applications.

We certainly should fix this bug. Michael Kerrisk has compared other UNIXes in
http://linux.derkeiler.com/Mailing-Lists/Kernel/2003-10/6030.html; this shows slightly better what is wrong. That message does not cover the directory case though; for directories, execute access is always granted to privileged users.

I don't expect any applications to break. We have had the patch I attached to the previous message (not the one in the old messages!) in the SUSE 2.6 kernel since roughtly two months now; it has undergone a lot of testing.

Quoted 5 lines

Yes, those applications are presumably broken on other OS's but that's different.

Given that this has been a longstanding misbehaviour in Linux (yes?) maybe the most prudent path is to remain bug-compatible?

Andries has already answered this. (Thank you!)

Quoted 3 lines

I'll add the patch to -mm so we can pick up any obvious userspace breakage, but it is likely that such problems will take a long time to emerge. file, MAY_EXEC)

I'm fine with that as well, but I think the patch should go straight to mainline.

Cheers,

Signature · 2 lines
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX AG