Re: [PATCH] net: check the return value of the copy_from_sockptr
From: Stanislav Fomichev
Date: Sat Sep 14 2024 - 14:01:41 EST
On 09/13, Cong Wang wrote:
> On Wed, Sep 11, 2024 at 01:05:27PM -0700, Stanislav Fomichev wrote:
> > On 09/11, Cong Wang wrote:
> > > On Wed, Sep 11, 2024 at 11:49:32AM -0700, Stanislav Fomichev wrote:
> > > > Can you explain what is not correct?
> > > >
> > > > Calling BPF_CGROUP_RUN_PROG_GETSOCKOPT with max_optlen=0 should not be
> > > > a problem I think? (the buffer simply won't be accessible to the bpf prog)
> > >
> > > Sure. Sorry for not providing all the details.
> > >
> > > If I understand the behavior of copy_from_user() correctly, it may
> > > return partially copied data in case of error, which then leads to a
> > > partially-copied 'max_optlen'.
> > >
> > > So, do you expect a partially-copied max_optlen to be passed to the
> > > eBPF program meanwhile the user still expects a complete one (since no
> > > -EFAULT)?
> > >
> > > Thanks.
> >
> > Partial copy is basically the same as user giving us garbage input, right?
> > That should still be handled correctly I think.
>
> Not to me.
>
> For explict garbage input, users (mostly syzbot) already expect it is a
> garbage.
>
> For partial copy, users expect either an error (like EFAULT) or a success
> with the _original_ value.
>
> It is all about expectation of the API.
>
> Thanks.
The best way to move this forward is for you to showcase what is exactly
broken by adding a test case to one of the tools/testing/selftests/bpf/*sockopt*
files.
We can then discuss whether it warrants the copy_from_sockptr check or
some other remediation.