Skip to content

Commit 5daeb41

Browse files
cypharbrauner
authored andcommitted
fchmodat2: add support for AT_EMPTY_PATH
This allows userspace to avoid going through /proc/self/fd when dealing with all types of file descriptors for chmod(), and makes fchmodat2() a proper superset of all other chmod syscalls. The primary difference between fchmodat2(AT_EMPTY_PATH) and fchmod() is that fchmod() doesn't operate on O_PATH file descriptors by design. To quote open(2): > O_PATH (since Linux 2.6.39) > [...] > The file itself is not opened, and other file operations (e.g., > read(2), write(2), fchmod(2), fchown(2), fgetxattr(2), ioctl(2), > mmap(2)) fail with the error EBADF. However, procfs has allowed userspace to do this operation ever since the introduction of O_PATH through magic-links, so adding this feature is only an improvement for programs that have to mess around with /proc/self/fd/$n today to get this behaviour. In addition, fchownat(AT_EMPTY_PATH) has existed since the introduction of O_PATH and allows chown() operations directly on O_PATH descriptors. Signed-off-by: Aleksa Sarai <[email protected]> Acked-by: Alexey Gladkov <[email protected]> Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 4859c25 commit 5daeb41

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/open.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,12 @@ static int do_fchmodat(int dfd, const char __user *filename, umode_t mode,
678678
int error;
679679
unsigned int lookup_flags;
680680

681-
if (unlikely(flags & ~AT_SYMLINK_NOFOLLOW))
681+
if (unlikely(flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)))
682682
return -EINVAL;
683683

684684
lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
685+
if (flags & AT_EMPTY_PATH)
686+
lookup_flags |= LOOKUP_EMPTY;
685687

686688
retry:
687689
error = user_path_at(dfd, filename, lookup_flags, &path);

0 commit comments

Comments
 (0)