* [PATCH 0/2] vfs: POSIX-compliant version of fchmodat with flag argument @ 2011-12-31 0:26 Andrew Ayer 2011-12-31 0:26 ` [PATCH 1/2] vfs: Add POSIX-compliant version of fchmodat syscall Andrew Ayer 2011-12-31 0:26 ` [PATCH 2/2] x86: Hook up new fchmodat4 syscall Andrew Ayer 0 siblings, 2 replies; 4+ messages in thread From: Andrew Ayer @ 2011-12-31 0:26 UTC (permalink / raw) To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel Hi, The below patches implement a 4 argument version of fchmodat (fchmodat4) that supports a flag argument, as specified by POSIX. Currently, the glibc wrapper has a flag argument, but fails with EOPNOTSUPP if you specify AT_SYMLINK_NOFOLLOW. POSIX says that fchmodat should only fail with EOPNOTSUPP if you specify AT_SYMLINK_NOFOLLOW and the path actually refers to a symbolic link (and the system doesn't support changing the mode of symbolic links). Unfortunately glibc can't do better because the current syscall doesn't have a flag argument. In addition to supporting AT_SYMLINK_NOFOLLOW, this also supports the AT_EMPTY_PATH flag, just like fchownat. Besides the POSIX-compliance, this patch will make it possible to ensure, in a race-free way, that you do not follow symlinks when chmodding. Previously, you could open a file with O_NOFOLLOW and fchmod it, but this only worked if you had read or write permissions on the file. Now you can open the file with O_PATH|O_NOFOLLOW and do fchmodat with AT_EMPTY_PATH. Any feedback is welcome. Cheers, Andrew ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] vfs: Add POSIX-compliant version of fchmodat syscall 2011-12-31 0:26 [PATCH 0/2] vfs: POSIX-compliant version of fchmodat with flag argument Andrew Ayer @ 2011-12-31 0:26 ` Andrew Ayer 2011-12-31 0:26 ` [PATCH 2/2] x86: Hook up new fchmodat4 syscall Andrew Ayer 1 sibling, 0 replies; 4+ messages in thread From: Andrew Ayer @ 2011-12-31 0:26 UTC (permalink / raw) To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel This adds a 4 argument version of fchmodat (fchmodat4) that supports a flag argument, as specified by POSIX. It supports the same two flags as fchownat: AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH. Signed-off-by: Andrew Ayer <agwa@andrewayer.name> --- fs/open.c | 21 +++++++++++++++++++-- include/linux/syscalls.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 22c41b5..c3dfdaa 100644 --- a/fs/open.c +++ b/fs/open.c @@ -452,6 +452,9 @@ static int chmod_common(struct path *path, umode_t mode) struct iattr newattrs; int error; + if (S_ISLNK(inode->i_mode)) + return -EOPNOTSUPP; + error = mnt_want_write(path->mnt); if (error) return error; @@ -484,10 +487,24 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode) SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode) { + return sys_fchmodat4(dfd, filename, mode, 0); +} + +SYSCALL_DEFINE4(fchmodat4, int, dfd, const char __user *, filename, + mode_t, mode, int, flag) +{ struct path path; int error; + int lookup_flags; + + if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0) + return -EINVAL; - error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path); + lookup_flags = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW; + if (flag & AT_EMPTY_PATH) + lookup_flags |= LOOKUP_EMPTY; + + error = user_path_at(dfd, filename, lookup_flags, &path); if (!error) { error = chmod_common(&path, mode); path_put(&path); @@ -497,7 +514,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode) SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode) { - return sys_fchmodat(AT_FDCWD, filename, mode); + return sys_fchmodat4(AT_FDCWD, filename, mode, 0); } static int chown_common(struct path *path, uid_t user, gid_t group) diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 86a24b1..c84795b 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -770,6 +770,8 @@ asmlinkage long sys_futimesat(int dfd, const char __user *filename, asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode); asmlinkage long sys_fchmodat(int dfd, const char __user * filename, mode_t mode); +asmlinkage long sys_fchmodat4(int dfd, const char __user * filename, + mode_t mode, int flag); asmlinkage long sys_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, int flag); asmlinkage long sys_openat(int dfd, const char __user *filename, int flags, -- 1.7.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] x86: Hook up new fchmodat4 syscall 2011-12-31 0:26 [PATCH 0/2] vfs: POSIX-compliant version of fchmodat with flag argument Andrew Ayer 2011-12-31 0:26 ` [PATCH 1/2] vfs: Add POSIX-compliant version of fchmodat syscall Andrew Ayer @ 2011-12-31 0:26 ` Andrew Ayer 1 sibling, 0 replies; 4+ messages in thread From: Andrew Ayer @ 2011-12-31 0:26 UTC (permalink / raw) To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel Signed-off-by: Andrew Ayer <agwa@andrewayer.name> --- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 3 ++- arch/x86/include/asm/unistd_64.h | 2 ++ arch/x86/kernel/syscall_table_32.S | 1 + 4 files changed, 6 insertions(+), 1 deletions(-) diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S index a6253ec..32248c5 100644 --- a/arch/x86/ia32/ia32entry.S +++ b/arch/x86/ia32/ia32entry.S @@ -852,4 +852,5 @@ ia32_sys_call_table: .quad sys_setns .quad compat_sys_process_vm_readv .quad compat_sys_process_vm_writev + .quad sys_fchmodat4 ia32_syscall_end: diff --git a/arch/x86/include/asm/unistd_32.h b/arch/x86/include/asm/unistd_32.h index 599c77d..112b299 100644 --- a/arch/x86/include/asm/unistd_32.h +++ b/arch/x86/include/asm/unistd_32.h @@ -354,10 +354,11 @@ #define __NR_setns 346 #define __NR_process_vm_readv 347 #define __NR_process_vm_writev 348 +#define __NR_fchmodat4 349 #ifdef __KERNEL__ -#define NR_syscalls 349 +#define NR_syscalls 350 #define __ARCH_WANT_IPC_PARSE_VERSION #define __ARCH_WANT_OLD_READDIR diff --git a/arch/x86/include/asm/unistd_64.h b/arch/x86/include/asm/unistd_64.h index 0431f19..21564f9 100644 --- a/arch/x86/include/asm/unistd_64.h +++ b/arch/x86/include/asm/unistd_64.h @@ -686,6 +686,8 @@ __SYSCALL(__NR_getcpu, sys_getcpu) __SYSCALL(__NR_process_vm_readv, sys_process_vm_readv) #define __NR_process_vm_writev 311 __SYSCALL(__NR_process_vm_writev, sys_process_vm_writev) +#define __NR_fchmodat4 312 +__SYSCALL(__NR_fchmodat4, sys_fchmodat4) #ifndef __NO_STUBS #define __ARCH_WANT_OLD_READDIR diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S index 9a0e312..bff82a6 100644 --- a/arch/x86/kernel/syscall_table_32.S +++ b/arch/x86/kernel/syscall_table_32.S @@ -348,3 +348,4 @@ ENTRY(sys_call_table) .long sys_setns .long sys_process_vm_readv .long sys_process_vm_writev + .long sys_fchmodat4 -- 1.7.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 0/2 RESEND] POSIX-compliant version of fchmodat with flag argument @ 2012-01-13 1:53 Andrew Ayer 2012-01-13 1:53 ` [PATCH 2/2] x86: Hook up new fchmodat4 syscall Andrew Ayer 0 siblings, 1 reply; 4+ messages in thread From: Andrew Ayer @ 2012-01-13 1:53 UTC (permalink / raw) To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel Hi, The below patches implement a 4 argument version of fchmodat (fchmodat4) that has a flag argument, as specified by POSIX. This is needed to implement a proper glibc wrapper. fchmodat4 supports the same two flags as fchownat: AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH. Besides the POSIX-compliance, this patch will make it possible to ensure, in a race-free way, that you do not follow symlinks when chmodding. Previously, you could open a file with O_NOFOLLOW and fchmod it, but this only worked if you had read or write permissions on the file. Now you can open the file with O_PATH|O_NOFOLLOW and do fchmodat with AT_EMPTY_PATH. Could this patch be applied? Any feedback is welcome. Cheers, Andrew ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] x86: Hook up new fchmodat4 syscall 2012-01-13 1:53 [PATCH 0/2 RESEND] POSIX-compliant version of fchmodat with flag argument Andrew Ayer @ 2012-01-13 1:53 ` Andrew Ayer 0 siblings, 0 replies; 4+ messages in thread From: Andrew Ayer @ 2012-01-13 1:53 UTC (permalink / raw) To: Alexander Viro; +Cc: linux-fsdevel, linux-kernel Signed-off-by: Andrew Ayer <agwa@andrewayer.name> --- arch/x86/ia32/ia32entry.S | 1 + arch/x86/include/asm/unistd_32.h | 3 ++- arch/x86/include/asm/unistd_64.h | 2 ++ arch/x86/kernel/syscall_table_32.S | 1 + 4 files changed, 6 insertions(+), 1 deletions(-) diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S index 3e27456..f026e9f 100644 --- a/arch/x86/ia32/ia32entry.S +++ b/arch/x86/ia32/ia32entry.S @@ -847,4 +847,5 @@ ia32_sys_call_table: .quad sys_setns .quad compat_sys_process_vm_readv .quad compat_sys_process_vm_writev + .quad sys_fchmodat4 ia32_syscall_end: diff --git a/arch/x86/include/asm/unistd_32.h b/arch/x86/include/asm/unistd_32.h index 599c77d..112b299 100644 --- a/arch/x86/include/asm/unistd_32.h +++ b/arch/x86/include/asm/unistd_32.h @@ -354,10 +354,11 @@ #define __NR_setns 346 #define __NR_process_vm_readv 347 #define __NR_process_vm_writev 348 +#define __NR_fchmodat4 349 #ifdef __KERNEL__ -#define NR_syscalls 349 +#define NR_syscalls 350 #define __ARCH_WANT_IPC_PARSE_VERSION #define __ARCH_WANT_OLD_READDIR diff --git a/arch/x86/include/asm/unistd_64.h b/arch/x86/include/asm/unistd_64.h index 0431f19..21564f9 100644 --- a/arch/x86/include/asm/unistd_64.h +++ b/arch/x86/include/asm/unistd_64.h @@ -686,6 +686,8 @@ __SYSCALL(__NR_getcpu, sys_getcpu) __SYSCALL(__NR_process_vm_readv, sys_process_vm_readv) #define __NR_process_vm_writev 311 __SYSCALL(__NR_process_vm_writev, sys_process_vm_writev) +#define __NR_fchmodat4 312 +__SYSCALL(__NR_fchmodat4, sys_fchmodat4) #ifndef __NO_STUBS #define __ARCH_WANT_OLD_READDIR diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S index 9a0e312..bff82a6 100644 --- a/arch/x86/kernel/syscall_table_32.S +++ b/arch/x86/kernel/syscall_table_32.S @@ -348,3 +348,4 @@ ENTRY(sys_call_table) .long sys_setns .long sys_process_vm_readv .long sys_process_vm_writev + .long sys_fchmodat4 -- 1.7.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-01-13 1:53 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-12-31 0:26 [PATCH 0/2] vfs: POSIX-compliant version of fchmodat with flag argument Andrew Ayer 2011-12-31 0:26 ` [PATCH 1/2] vfs: Add POSIX-compliant version of fchmodat syscall Andrew Ayer 2011-12-31 0:26 ` [PATCH 2/2] x86: Hook up new fchmodat4 syscall Andrew Ayer -- strict thread matches above, loose matches on Subject: below -- 2012-01-13 1:53 [PATCH 0/2 RESEND] POSIX-compliant version of fchmodat with flag argument Andrew Ayer 2012-01-13 1:53 ` [PATCH 2/2] x86: Hook up new fchmodat4 syscall Andrew Ayer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).