linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fchmodat2: add support for AT_EMPTY_PATH
@ 2023-07-28 11:58 Aleksa Sarai
  2023-07-28 13:05 ` Alexey Gladkov
  2023-07-28 14:49 ` Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Aleksa Sarai @ 2023-07-28 11:58 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner
  Cc: linux-fsdevel, linux-kernel, Palmer Dabbelt, Alexey Gladkov,
	Arnd Bergmann, Aleksa Sarai

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 <cyphar@cyphar.com>
---
 fs/open.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/open.c b/fs/open.c
index e52d78e5a333..b8883ec286f5 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -678,10 +678,12 @@ static int do_fchmodat(int dfd, const char __user *filename, umode_t mode,
 	int error;
 	unsigned int lookup_flags;
 
-	if (unlikely(flags & ~AT_SYMLINK_NOFOLLOW))
+	if (unlikely(flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)))
 		return -EINVAL;
 
 	lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
+	if (flags & AT_EMPTY_PATH)
+		lookup_flags |= LOOKUP_EMPTY;
 
 retry:
 	error = user_path_at(dfd, filename, lookup_flags, &path);

---
base-commit: 4859c257d295949c23f4074850a8c2ec31357abb
change-id: 20230728-fchmodat2-at_empty_path-310cf40c921f

Best regards,
-- 
Aleksa Sarai <cyphar@cyphar.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fchmodat2: add support for AT_EMPTY_PATH
  2023-07-28 11:58 [PATCH] fchmodat2: add support for AT_EMPTY_PATH Aleksa Sarai
@ 2023-07-28 13:05 ` Alexey Gladkov
  2023-07-28 14:49 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Alexey Gladkov @ 2023-07-28 13:05 UTC (permalink / raw)
  To: Aleksa Sarai
  Cc: Alexander Viro, Christian Brauner, linux-fsdevel, linux-kernel,
	Palmer Dabbelt, Arnd Bergmann

On Fri, Jul 28, 2023 at 09:58:26PM +1000, Aleksa Sarai wrote:
> 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 <cyphar@cyphar.com>

It seems to me that this makes sense for fchmodat2.

Acked-by: Alexey Gladkov <legion@kernel.org>

> ---
>  fs/open.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/open.c b/fs/open.c
> index e52d78e5a333..b8883ec286f5 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -678,10 +678,12 @@ static int do_fchmodat(int dfd, const char __user *filename, umode_t mode,
>  	int error;
>  	unsigned int lookup_flags;
>  
> -	if (unlikely(flags & ~AT_SYMLINK_NOFOLLOW))
> +	if (unlikely(flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)))
>  		return -EINVAL;
>  
>  	lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
> +	if (flags & AT_EMPTY_PATH)
> +		lookup_flags |= LOOKUP_EMPTY;
>  
>  retry:
>  	error = user_path_at(dfd, filename, lookup_flags, &path);
> 
> ---
> base-commit: 4859c257d295949c23f4074850a8c2ec31357abb
> change-id: 20230728-fchmodat2-at_empty_path-310cf40c921f
> 
> Best regards,
> -- 
> Aleksa Sarai <cyphar@cyphar.com>
> 

-- 
Rgrds, legion


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fchmodat2: add support for AT_EMPTY_PATH
  2023-07-28 11:58 [PATCH] fchmodat2: add support for AT_EMPTY_PATH Aleksa Sarai
  2023-07-28 13:05 ` Alexey Gladkov
@ 2023-07-28 14:49 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2023-07-28 14:49 UTC (permalink / raw)
  To: Aleksa Sarai
  Cc: Christian Brauner, linux-fsdevel, linux-kernel, Palmer Dabbelt,
	Alexey Gladkov, Arnd Bergmann, Alexander Viro

On Fri, 28 Jul 2023 21:58:26 +1000, Aleksa Sarai wrote:
> 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):
> 
> [...]

A follow-up patch with selftests would be appreciated.

---

Applied to the vfs.fchmodat2 branch of the vfs/vfs.git tree.
Patches in the vfs.fchmodat2 branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fchmodat2

[1/1] fchmodat2: add support for AT_EMPTY_PATH
      https://git.kernel.org/vfs/vfs/c/5daeb41a6fc9

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-28 14:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-28 11:58 [PATCH] fchmodat2: add support for AT_EMPTY_PATH Aleksa Sarai
2023-07-28 13:05 ` Alexey Gladkov
2023-07-28 14:49 ` Christian Brauner

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).