Re: [PATCH v6 1/4] openat2: new OPENAT2_REGULAR flag support
Aleksa Sarai <[email protected]> Thu, 16 Apr 2026 21:41:12 +1000
| Newsgroups | dev.linux.lists.gfs2,dev.linux.lists.v9fs,org.kernel.vger.ceph-devel,org.kernel.vger.linux-api,org.kernel.vger.linux-cifs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.kernel.vger.linux-nfs |
|---|---|
| Message-ID | <[email protected]> |
On 2026-03-28, Dorjoy Chowdhury <[email protected]> wrote: > This flag indicates the path should be opened if it's a regular file. > This is useful to write secure programs that want to avoid being > tricked into opening device nodes with special semantics while thinking > they operate on regular files. This is a requested feature from the > uapi-group[1]. > > A corresponding error code EFTYPE has been introduced. For example, if > openat2 is called on path /dev/null with OPENAT2_REGULAR in the flag > param, it will return -EFTYPE. EFTYPE is already used in BSD systems > like FreeBSD, macOS. > > When used in combination with O_CREAT, either the regular file is > created, or if the path already exists, it is opened if it's a regular > file. Otherwise, -EFTYPE is returned. > > When OPENAT2_REGULAR is combined with O_DIRECTORY, -EINVAL is returned > as it doesn't make sense to open a path that is both a directory and a > regular file. > > [1]: https://uapi-group.org/kernel-features/#ability-to-only-open-regular-files > > Signed-off-by: Dorjoy Chowdhury <[email protected]> > --- Aside from the nit below, feel free to take a Reviewed-by: Aleksa Sarai <[email protected]> > diff --git a/fs/open.c b/fs/open.c > index 681d405bc61e..a6f445f72181 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -960,7 +960,7 @@ static int do_dentry_open(struct file *f, > if (f->f_mapping->a_ops && f->f_mapping->a_ops->direct_IO) > f->f_mode |= FMODE_CAN_ODIRECT; > > - f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); > + f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | OPENAT2_REGULAR); It's not clear to me why you dropped this, I didn't see a review mentioning it either. (General note: Ideally the cover letter changelog would mention who suggested a change in brackets after the changelog line so it's easier to track where a change might've come from.) I would personally keep it since O_DIRECTORY is not dropped (I do find it interesting that O_EXCL is dropped too -- you could imagine a userspace program wanting to know that the file was opened with O_EXCL, though it provides you very little information). -- Aleksa Sarai https://www.cyphar.com/
signature.asc
(application/pgp-signature, 265 B)
-----BEGIN PGP SIGNATURE----- iJEEABYKADkWIQS2TklVsp+j1GPyqQYol/rSt+lEbwUCaeDK2BsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMiwyLDIACgkQKJf60rfpRG+0aQEAmwzPPQPnvabbHhUf0fph pJ6P46S5QXpATvNGjZyCr+8BAJ6lJf8lp5gf9hbdzip1EZghre/B+AfvsiTxQSXn uF4A =Z/uP -----END PGP SIGNATURE-----