Re: [PATCH net-next 1/2] net: add sockopt_expand_out()
From: Breno Leitao
Date: Mon Sep 14 2026 - 07:43:04 EST
On Fri, Sep 11, 2026 at 02:17:41PM -0700, Stanislav Fomichev wrote:
> On 09/11, Breno Leitao wrote:
> > On Fri, Sep 11, 2026 at 08:56:23AM -0700, Stanislav Fomichev wrote:
> > > On 09/10, Breno Leitao wrote:
> > > >
> > > > + if (size <= iov_iter_count(&opt->iter_out))
> > > > + return 0;
> > > > +
> > > > + if (WARN_ON_ONCE(!iter_is_ubuf(&opt->iter_out)))
> > > > + return -EINVAL;
> > >
> > > nit: if you end up re-spinning for some reason, maybe swap these two?
> >
> > I am not sure we want to swap these two. This is the reason:
> >
> > 1) The first check (size <= iov_iter_count(&opt->iter_out)), check if we
> > need the "hack" or not.
> >
> > a) If we don't need the tack, then we are fine and this could be called
> > from user or kernel.
> >
> > b) for the hack (which happens in the next line -- iov_iter_ubuf()), it
> > needs to be ubuf.
> >
> > So, this force kernel callers to use the right optlen, avoiding hitting
> > the same issue as userspace.
>
> Hmm, that feels a bit too magical :-/ Who are the kernel callers? Do we
> have any? Is it reachable via bpf or something else?
We don't have any kernel callers today, but this conversion will
enable kernel users to call it.
That said, the WARN_ON_ONCE() protects future kernel callers from
making the same mistake as userspace: not passing a large enough
optlen.
Once the whole conversion is done, BPF and io_uring will be able to
call these options.
So the WARN is an assert against a future in-kernel caller that gets
optlen wrong, not something reachable today.