From: Alexey Gladkov <legion@kernel.org>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Palmer Dabbelt <palmer@sifive.com>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH] fchmodat2: add support for AT_EMPTY_PATH
Date: Fri, 28 Jul 2023 15:05:06 +0200 [thread overview]
Message-ID: <ZMO9AgYcfsR2MIa3@example.org> (raw)
In-Reply-To: <20230728-fchmodat2-at_empty_path-v1-1-f3add31d3516@cyphar.com>
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
next prev parent reply other threads:[~2023-07-28 13:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 11:58 [PATCH] fchmodat2: add support for AT_EMPTY_PATH Aleksa Sarai
2023-07-28 13:05 ` Alexey Gladkov [this message]
2023-07-28 14:49 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZMO9AgYcfsR2MIa3@example.org \
--to=legion@kernel.org \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=palmer@sifive.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).