From: Aleksa Sarai <cyphar@cyphar.com>
To: Alexey Gladkov <legion@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org,
viro@zeniv.linux.org.uk, James.Bottomley@hansenpartnership.com,
acme@kernel.org, alexander.shishkin@linux.intel.com,
axboe@kernel.dk, benh@kernel.crashing.org,
borntraeger@de.ibm.com, bp@alien8.de, catalin.marinas@arm.com,
christian@brauner.io, dalias@libc.org, davem@davemloft.net,
deepa.kernel@gmail.com, deller@gmx.de, dhowells@redhat.com,
fenghua.yu@intel.com, fweimer@redhat.com, geert@linux-m68k.org,
glebfm@altlinux.org, gor@linux.ibm.com, hare@suse.com,
hpa@zytor.com, ink@jurassic.park.msu.ru, jhogan@kernel.org,
kim.phillips@arm.com, ldv@altlinux.org,
linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org,
linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org,
linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org,
linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
linux@armlinux.org.uk, linuxppc-dev@lists.ozlabs.org,
luto@kernel.org, mattst88@gmail.com, mingo@redhat.com,
monstr@monstr.eu, mpe@ellerman.id.au, namhyung@kernel.org,
paulus@samba.org, peterz@infradead.org, ralf@linux-mips.org,
sparclinux@vger.kernel.org, stefan@agner.ch, tglx@linutronix.de,
tony.luck@intel.com, tycho@tycho.ws, will@kernel.org,
x86@kernel.org, ysato@users.sourceforge.jp,
Palmer Dabbelt <palmer@sifive.com>
Subject: Re: [PATCH v4 2/5] fs: Add fchmodat2()
Date: Fri, 28 Jul 2023 03:12:24 +1000 [thread overview]
Message-ID: <20230727.041348-imposing.uptake.velvet.nylon-712tDwzCAbCCoSGx@cyphar.com> (raw)
In-Reply-To: <ZMEjlDNJkFpYERr1@example.org>
[-- Attachment #1: Type: text/plain, Size: 4000 bytes --]
On 2023-07-26, Alexey Gladkov <legion@kernel.org> wrote:
> On Wed, Jul 26, 2023 at 02:36:25AM +1000, Aleksa Sarai wrote:
> > On 2023-07-11, Alexey Gladkov <legion@kernel.org> wrote:
> > > On the userspace side fchmodat(3) is implemented as a wrapper
> > > function which implements the POSIX-specified interface. This
> > > interface differs from the underlying kernel system call, which does not
> > > have a flags argument. Most implementations require procfs [1][2].
> > >
> > > There doesn't appear to be a good userspace workaround for this issue
> > > but the implementation in the kernel is pretty straight-forward.
> > >
> > > The new fchmodat2() syscall allows to pass the AT_SYMLINK_NOFOLLOW flag,
> > > unlike existing fchmodat.
> > >
> > > [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/fchmodat.c;h=17eca54051ee28ba1ec3f9aed170a62630959143;hb=a492b1e5ef7ab50c6fdd4e4e9879ea5569ab0a6c#l35
> > > [2] https://git.musl-libc.org/cgit/musl/tree/src/stat/fchmodat.c?id=718f363bc2067b6487900eddc9180c84e7739f80#n28
> > >
> > > Co-developed-by: Palmer Dabbelt <palmer@sifive.com>
> > > Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
> > > Signed-off-by: Alexey Gladkov <legion@kernel.org>
> > > Acked-by: Arnd Bergmann <arnd@arndb.de>
> > > ---
> > > fs/open.c | 18 ++++++++++++++----
> > > include/linux/syscalls.h | 2 ++
> > > 2 files changed, 16 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/fs/open.c b/fs/open.c
> > > index 0c55c8e7f837..39a7939f0d00 100644
> > > --- a/fs/open.c
> > > +++ b/fs/open.c
> > > @@ -671,11 +671,11 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
> > > return err;
> > > }
> > >
> > > -static int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
> > > +static int do_fchmodat(int dfd, const char __user *filename, umode_t mode, int lookup_flags)
> >
> > I think it'd be much neater to do the conversion of AT_ flags here and
> > pass 0 as a flags argument for all of the wrappers (this is how most of
> > the other xyz(), fxyz(), fxyzat() syscall wrappers are done IIRC).
>
> I just addressed the Al Viro's suggestion.
>
> https://lore.kernel.org/lkml/20190717014802.GS17978@ZenIV.linux.org.uk/
I think Al misspoke, because he also said "pass it 0 as an extra
argument", but you actually have to pass LOOKUP_FOLLOW from the
wrappers. If you look at how faccessat2 and faccessat are implemented,
it follows the behaviour I described.
> > > {
> > > struct path path;
> > > int error;
> > > - unsigned int lookup_flags = LOOKUP_FOLLOW;
> > > +
> > > retry:
> > > error = user_path_at(dfd, filename, lookup_flags, &path);
> > > if (!error) {
> > > @@ -689,15 +689,25 @@ static int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
> > > return error;
> > > }
> > >
> > > +SYSCALL_DEFINE4(fchmodat2, int, dfd, const char __user *, filename,
> > > + umode_t, mode, int, flags)
> > > +{
> > > + if (unlikely(flags & ~AT_SYMLINK_NOFOLLOW))
> > > + return -EINVAL;
> >
> > We almost certainly want to support AT_EMPTY_PATH at the same time.
> > Otherwise userspace will still need to go through /proc when trying to
> > chmod a file handle they have.
>
> I'm not sure I understand. Can you explain what you mean?
You should add support for AT_EMPTY_PATH (LOOKUP_EMPTY) as well as
AT_SYMLINK_NOFOLLOW. It would only require something like:
unsigned int lookup_flags = LOOKUP_FOLLOW;
if (flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW))
return -EINVAL;
if (flags & AT_EMPTY_PATH)
lookup_flags |= LOOKUP_EMPTY;
if (flags & AT_SYMLINK_NOFOLLOW)
lookup_flags &= ~LOOKUP_FOLLOW;
/* ... */
This would be effectively equivalent to fchmod(fd, mode). (I was wrong
when I said this wasn't already possible -- I forgot about fchmod(2).)
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2023-07-27 17:13 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-17 1:27 Add a new fchmodat4() syscall, v2 Palmer Dabbelt
2019-07-17 1:27 ` [PATCH v2 1/4] Non-functional cleanup of a "__user * filename" Palmer Dabbelt
2019-07-17 1:27 ` [PATCH v2 2/4] Add fchmodat4(), a new syscall Palmer Dabbelt
2019-07-17 1:48 ` Al Viro
2019-07-17 2:12 ` Palmer Dabbelt
2019-07-17 2:40 ` Rich Felker
2019-07-17 3:02 ` Al Viro
2019-07-17 1:27 ` [PATCH v2 3/4] arch: Register fchmodat4, usually as syscall 434 Palmer Dabbelt
2019-07-17 1:27 ` [PATCH v2 4/4] tools: Add fchmodat4 Palmer Dabbelt
2019-07-17 12:39 ` Arnaldo Carvalho de Melo
2020-06-09 13:52 ` Add a new fchmodat4() syscall, v2 Florian Weimer
2023-07-11 11:25 ` [PATCH v3 0/5] Add a new fchmodat4() syscall Alexey Gladkov
2023-07-11 11:25 ` [PATCH v3 1/5] Non-functional cleanup of a "__user * filename" Alexey Gladkov
2023-07-11 11:32 ` Arnd Bergmann
2023-07-11 11:25 ` [PATCH v3 2/5] fs: Add fchmodat4() Alexey Gladkov
2023-07-11 11:42 ` Arnd Bergmann
2023-07-11 11:52 ` Christian Brauner
2023-07-11 12:51 ` Alexey Gladkov
2023-07-11 14:01 ` Christian Brauner
2023-07-11 15:23 ` Alexey Gladkov
2023-07-11 12:28 ` Matthew Wilcox
2023-07-11 12:49 ` Alexey Gladkov
2023-07-11 11:25 ` [PATCH v3 3/5] arch: Register fchmodat4, usually as syscall 451 Alexey Gladkov
2023-07-11 11:31 ` Arnd Bergmann
2023-07-11 11:25 ` [PATCH v3 4/5] tools headers UAPI: Sync files changed by new fchmodat4 syscall Alexey Gladkov
2023-07-11 11:25 ` [PATCH v3 5/5] selftests: add fchmodat4(2) selftest Alexey Gladkov
2023-07-11 12:10 ` Florian Weimer
2023-07-11 13:38 ` Alexey Gladkov
2023-07-11 12:24 ` [PATCH v3 0/5] Add a new fchmodat4() syscall Florian Weimer
2023-07-11 15:14 ` Christian Brauner
2023-07-25 11:05 ` Alexey Gladkov
2023-07-25 12:05 ` Christian Brauner
2023-07-11 16:16 ` [PATCH v4 0/5] Add a new fchmodat2() syscall Alexey Gladkov
2023-07-11 16:16 ` [PATCH v4 1/5] Non-functional cleanup of a "__user * filename" Alexey Gladkov
2023-07-11 16:16 ` [PATCH v4 2/5] fs: Add fchmodat2() Alexey Gladkov
2023-07-11 17:05 ` Christian Brauner
2023-07-25 16:36 ` Aleksa Sarai
2023-07-26 13:45 ` Alexey Gladkov
2023-07-27 10:26 ` Christian Brauner
2023-07-27 17:12 ` Aleksa Sarai [this message]
2023-07-27 17:39 ` Aleksa Sarai
2023-07-28 8:43 ` David Laight
2023-07-28 18:42 ` dalias
2023-07-27 9:01 ` David Laight
2023-07-27 16:28 ` Andreas Schwab
2023-07-27 17:02 ` Christian Brauner
2023-07-27 17:13 ` dalias
2023-07-27 17:36 ` Christian Brauner
2023-07-27 16:31 ` dalias
2023-07-11 16:16 ` [PATCH v4 3/5] arch: Register fchmodat2, usually as syscall 452 Alexey Gladkov
2023-07-11 16:26 ` Arnd Bergmann
2023-07-25 7:16 ` Geert Uytterhoeven
2023-07-25 16:43 ` Aleksa Sarai
2023-07-27 10:37 ` Christian Brauner
2023-07-27 17:42 ` Aleksa Sarai
2023-07-11 16:16 ` [PATCH v4 4/5] tools headers UAPI: Sync files changed by new fchmodat2 syscall Alexey Gladkov
2023-07-11 17:19 ` Namhyung Kim
2023-07-11 17:23 ` Alexey Gladkov
2023-07-11 16:16 ` [PATCH v4 5/5] selftests: Add fchmodat2 selftest Alexey Gladkov
2023-07-11 17:36 ` (subset) [PATCH v4 0/5] Add a new fchmodat2() syscall Christian Brauner
2023-07-12 2:42 ` Rich Felker
2023-07-25 15:58 ` Add fchmodat2() - or add a more general syscall? David Howells
2023-07-25 16:10 ` Florian Weimer
2023-07-25 16:50 ` Aleksa Sarai
2023-07-25 18:39 ` David Howells
2023-07-25 18:44 ` Rich Felker
2023-07-26 13:30 ` Christian Brauner
2023-07-27 3:57 ` Eric Biggers
2023-07-27 10:27 ` 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=20230727.041348-imposing.uptake.velvet.nylon-712tDwzCAbCCoSGx@cyphar.com \
--to=cyphar@cyphar.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=benh@kernel.crashing.org \
--cc=borntraeger@de.ibm.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=christian@brauner.io \
--cc=dalias@libc.org \
--cc=davem@davemloft.net \
--cc=deepa.kernel@gmail.com \
--cc=deller@gmx.de \
--cc=dhowells@redhat.com \
--cc=fenghua.yu@intel.com \
--cc=fweimer@redhat.com \
--cc=geert@linux-m68k.org \
--cc=glebfm@altlinux.org \
--cc=gor@linux.ibm.com \
--cc=hare@suse.com \
--cc=hpa@zytor.com \
--cc=ink@jurassic.park.msu.ru \
--cc=jhogan@kernel.org \
--cc=kim.phillips@arm.com \
--cc=ldv@altlinux.org \
--cc=legion@kernel.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=luto@kernel.org \
--cc=mattst88@gmail.com \
--cc=mingo@redhat.com \
--cc=monstr@monstr.eu \
--cc=mpe@ellerman.id.au \
--cc=namhyung@kernel.org \
--cc=palmer@sifive.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=ralf@linux-mips.org \
--cc=sparclinux@vger.kernel.org \
--cc=stefan@agner.ch \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=tycho@tycho.ws \
--cc=viro@zeniv.linux.org.uk \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=ysato@users.sourceforge.jp \
/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).