From: Stefan Metzmacher <metze@samba.org>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: linux-kernel@vger.kernel.org,
Dmitry Safonov <0x7f454c46@gmail.com>,
Dmitry Safonov <dima@arista.com>,
Salam Noureddine <noureddine@arista.com>,
David Ahern <dsahern@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Michal Luczaj <mhal@rbox.co>, David Wei <dw@davidwei.uk>,
Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Marcel Holtmann <marcel@holtmann.org>,
Xin Long <lucien.xin@gmail.com>,
Eric Dumazet <edumazet@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Neal Cardwell <ncardwell@google.com>,
Jakub Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Kees Cook <keescook@chromium.org>,
netdev@vger.kernel.org, linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 1/5] uaccess: fix ignored_trailing logic in copy_struct_to_user()
Date: Thu, 9 Apr 2026 11:01:12 +0200 [thread overview]
Message-ID: <5405849b-ad9e-4c64-9259-2071f4e36c8a@samba.org> (raw)
In-Reply-To: <2026-04-08-ditzy-organic-yowl-croc-yWsgIE@cyphar.com>
Hi Aleksa,
> On 2026-04-07, Stefan Metzmacher <metze@samba.org> wrote:
>> Currently all callers pass ignored_trailing=NULL, but I have
>> code that will make use of.
>>
>> Now it actually behaves like documented:
>>
>> * If @usize < @ksize, then the kernel is trying to pass userspace a newer
>> struct than it supports. Thus we only copy the interoperable portions
>> (@usize) and ignore the rest (but @ignored_trailing is set to %true if
>> any of the trailing (@ksize - @usize) bytes are non-zero).
>
> Good catch, though I want to mention that the current API design for
> copy_struct_to_user() is a bit of a compromise -- I was trying to think
> of a way of making it generic but what information you need really
> depends on your API.
>
> For request-flag APIs (like statx) then you can just unset the bits in
> the response mask for fields past usize and so it is a non-fatal error,
> but it requires knowing which field offsets map to which flags.
>
> My initial idea for ignored_trailing was for it to return the offset
> memchr_inv() gives you -- but unfortunately, this doesn't help in the
> more generic case where you have multiple non-zero bits that need to
> unset multiple flags.
I guess the caller could use if (ignored_trailing) { ... }
to check more complex stuff and then decide ignore or return an error.
> Out of interest, how did you plan on using it? It might be a good idea
> to rethink this API before it starts getting used "in anger" in a way
> that leaks to uAPIs we can't change.
Currently I only use it with WARN_ON_ONCE(ignored_trailing);
in order to catch internal errors. See
https://git.samba.org/?p=metze/linux/wip.git;a=blob;f=fs/smb/common/smbdirect/smbdirect_proto.c;h=ce7c78eb6795041ba672da434ffb01db73269cb7;hb=37c61ef9758f3e113d4078220d8fc2aee366c955#l1625
But I guess I will at least change it to
if (WARN_ON_ONCE(ignored_trailing))
return...
And in general I thought it would be good practice to
check that case in new code in order to avoid unexpected
behavior.
> In any case, for this patch feel free to take my
>
> Reviewed-by: Aleksa Sarai <aleksa@amutable.com>
Thanks!
metze
next prev parent reply other threads:[~2026-04-09 9:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 16:03 [PATCH 0/5] uaccess/sockptr: copy_struct_ fixes and more helpers Stefan Metzmacher
2026-04-07 16:03 ` [PATCH 1/5] uaccess: fix ignored_trailing logic in copy_struct_to_user() Stefan Metzmacher
2026-04-09 6:33 ` Aleksa Sarai
2026-04-09 9:01 ` Stefan Metzmacher [this message]
2026-04-07 16:03 ` [PATCH 2/5] sockptr: fix usize check in copy_struct_from_sockptr() for user pointers Stefan Metzmacher
2026-04-09 6:37 ` Aleksa Sarai
2026-04-09 6:39 ` Aleksa Sarai
2026-04-07 16:03 ` [PATCH 3/5] uaccess: add copy_struct_{from,to}_bounce_buffer() helpers Stefan Metzmacher
2026-04-07 18:25 ` David Laight
2026-04-09 8:47 ` Stefan Metzmacher
2026-04-07 16:03 ` [PATCH 4/5] sockptr: let copy_struct_from_sockptr() use copy_struct_from_bounce_buffer() Stefan Metzmacher
2026-04-07 16:03 ` [PATCH 5/5] sockptr: introduce copy_struct_to_sockptr() Stefan Metzmacher
2026-04-09 13:05 ` [PATCH 0/5] uaccess/sockptr: copy_struct_ fixes and more helpers 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=5405849b-ad9e-4c64-9259-2071f4e36c8a@samba.org \
--to=metze@samba.org \
--cc=0x7f454c46@gmail.com \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=davem@davemloft.net \
--cc=dima@arista.com \
--cc=dsahern@kernel.org \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=luiz.dentz@gmail.com \
--cc=luiz.von.dentz@intel.com \
--cc=marcel@holtmann.org \
--cc=mhal@rbox.co \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=noureddine@arista.com \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/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