[PATCH v4] linux: Add openat2 (BZ 31664)

Aleksa Sarai cyphar@cyphar.com
Mon Aug 25 22:28:48 GMT 2025


On 2025-08-25, Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> wrote:
> On 25/08/25 16:22, Adhemerval Zanella Netto wrote:
> > 
> > 
> > On 25/08/25 11:53, Paul Eggert wrote:
> >> On 2025-08-21 10:28, Paul Eggert wrote:
> >>> On 8/21/25 06:38, Adhemerval Zanella wrote:
> >>>> +extern int openat2 (int __dfd, const char *__filename, struct open_how *__how,
> >>>> +            size_t __usize)
> >>>> +     __nonnull ((2, 3));
> >>>
> >>> The pointer arguments should be marked with __restrict, for the
> >>> same reason similar syscalls mark them that way.
> >>>
> >>> The __how argument should be pointer to const.
> >>
> >> Oh, sorry, I contradicted myself. If __how is marked 'const' then
> >> '__restrict' should not be added, for the same reason syscalls like
> >> utimensat lack '__restrict' (all pointer args are
> >> pointer-to-const). So please just add 'const' and don't add
> >> '__restrict'.
> > 
> > Alright, I have figure out this but thanks for confirm it.
> 
> So I double checked the Linux source and open_how is indeed not marked
> as const.  The current syscall implementation only operates over a
> temporary object and never sync back the result back (with a
> copy_struct_to_user).
> 
> So I am not sure if this is an overlook from kernel developers, or if
> this was done intentionally to allow some extension to change the
> input howto operation to also return information.  The initial patch
> (fddb5d430ad9fa91b49b1d34d0202ffe2fa0e179) is not explicit if some
> future extension would allow it.
> 
> I am ccing Aleksa to give us some light whether the idea is to really
> allow the syscall to extend the howto to eventually allow it kernel
> to return information.

This was originally (i.e., v1 of the patch) unintentional, but one
extension idea I had while working on openat2() was CHECK_FIELDS.

CHECK_FIELDS is an extension I proposed to most extensible-struct
syscalls that would let userspace query which bit patterns are valid,
allowing you to very cheaply get a set of kernel features (rather than
the current guess-and-check approach we have). This would require being
able to write to the structure when CHECK_FIELDS is requested.

I believe I sent a new version of this patch late last year, but I would
need to dig through my emails to find it. We also had a chat about this
online at LPC 2020 but we couldn't come to an agreement on the entire
idea of the utility of this kind of thing, so I only ended up sending a
new version last year.

-- 
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
https://www.cyphar.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 265 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250826/c48a7fb9/attachment.sig>


More information about the Libc-alpha mailing list