Re: [PATCH net-next 1/2] net: add sockopt_expand_out()

From: Stanislav Fomichev

Date: Fri Sep 11 2026 - 17:17:55 EST


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?