Skip to content

Commit

Permalink
posix: remove R_OK from InodeMustBeSearchableDir()
Browse files Browse the repository at this point in the history
Checking for read permissions (via R_OK) in InodeMustBeSearchableDir()
is either redundant or incorrect.  Remove it.

Assume dirfd is a file descriptor for a directory whose permission bits
are 0111 (i.e., search permissions only).  Consider the following API
calls:

1. red_openat(dirfd, "..", RED_O_RDONLY)
2. red_openat(dirfd, "./..", RED_O_RDONLY)
3. red_openat(dirfd, ".", RED_O_RDONLY)

Both #1 and #2 should succeed (assuming dirfd's parent directory has
read permissions).  However, InodeMustBeSearchableDir() would cause
both #1 and #2 to fail, since it will check whether dirfd has read
permissions, even though those aren't required.

Case #3 should fail, and does fail, but InodeMustBeSearchableDir() does
not need to be the place where this failure originates, because the
check for read permissions will occur later, in FildesOpen().  The R_OK
check in InodeMustBeSearchableDir() is redundant.

See also commit 80c2c79, the origin of the relevant code.
  • Loading branch information
danielrlewis committed Mar 8, 2023
1 parent 250f06f commit e7f26e7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions posix/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ static bool IsDotOrDotDot(
@retval 0 Operation was successful: @p ulInode is a directory.
@retval -RED_EACCES #REDCONF_POSIX_OWNER_PERM is true and @p ulInode is
a directory without read or search permissions.
a directory without search permissions.
@retval -RED_EBADF @p ulInode is not a valid inode.
@retval -RED_EIO A disk I/O error occurred.
@retval -RED_ENOTDIR @p ulInode is not a directory.
Expand Down Expand Up @@ -1335,7 +1335,7 @@ static REDSTATUS InodeMustBeSearchableDir(
#if REDCONF_POSIX_OWNER_PERM == 1
if(ret == 0)
{
ret = RedPermCheck(RED_X_OK | RED_R_OK, sb.st_mode, sb.st_uid, sb.st_gid);
ret = RedPermCheck(RED_X_OK, sb.st_mode, sb.st_uid, sb.st_gid);
}
#endif
}
Expand Down

0 comments on commit e7f26e7

Please sign in to comment.