netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pull-request: bpf 2023-11-30
@ 2023-11-29 23:49 Daniel Borkmann
  2023-11-30  3:50 ` patchwork-bot+netdevbpf
  2023-11-30 14:53 ` Eric Dumazet
  0 siblings, 2 replies; 8+ messages in thread
From: Daniel Borkmann @ 2023-11-29 23:49 UTC (permalink / raw)
  To: davem; +Cc: kuba, pabeni, edumazet, daniel, ast, andrii, martin.lau, netdev,
	bpf

Hi David, hi Jakub, hi Paolo, hi Eric,

The following pull-request contains BPF updates for your *net* tree.

We've added 5 non-merge commits during the last 7 day(s) which contain
a total of 10 files changed, 66 insertions(+), 15 deletions(-).

The main changes are:

1) Fix AF_UNIX splat from use after free in BPF sockmap, from John Fastabend.

2) Fix a syzkaller splat in netdevsim by properly handling offloaded programs (and
   not device-bound ones), from Stanislav Fomichev.

3) Fix bpf_mem_cache_alloc_flags() to initialize the allocation hint, from Hou Tao.

4) Fix netkit by rejecting IFLA_NETKIT_PEER_INFO in changelink, from Daniel Borkmann.

Please consider pulling these changes from:

  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git tags/for-netdev

Thanks a lot!

Also thanks to reporters, reviewers and testers of commits in this pull-request:

Jakub Kicinski, Jakub Sitnicki, Nikolay Aleksandrov, Yonghong Song

----------------------------------------------------------------

The following changes since commit d3fa86b1a7b4cdc4367acacea16b72e0a200b3d7:

  Merge tag 'net-6.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2023-11-23 10:40:13 -0800)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git tags/for-netdev

for you to fetch changes up to 51354f700d400e55b329361e1386b04695e6e5c1:

  bpf, sockmap: Add af_unix test with both sockets in map (2023-11-30 00:25:25 +0100)

----------------------------------------------------------------
bpf-for-netdev

----------------------------------------------------------------
Daniel Borkmann (1):
      netkit: Reject IFLA_NETKIT_PEER_INFO in netkit_change_link

Hou Tao (1):
      bpf: Add missed allocation hint for bpf_mem_cache_alloc_flags()

John Fastabend (2):
      bpf, sockmap: af_unix stream sockets need to hold ref for pair sock
      bpf, sockmap: Add af_unix test with both sockets in map

Stanislav Fomichev (1):
      netdevsim: Don't accept device bound programs

 drivers/net/netdevsim/bpf.c                        |  4 +-
 drivers/net/netkit.c                               |  6 +++
 include/linux/skmsg.h                              |  1 +
 include/net/af_unix.h                              |  1 +
 kernel/bpf/memalloc.c                              |  2 +
 net/core/skmsg.c                                   |  2 +
 net/unix/af_unix.c                                 |  2 -
 net/unix/unix_bpf.c                                |  5 +++
 .../selftests/bpf/prog_tests/sockmap_listen.c      | 51 +++++++++++++++++-----
 .../selftests/bpf/progs/test_sockmap_listen.c      |  7 +++
 10 files changed, 66 insertions(+), 15 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-29 23:49 pull-request: bpf 2023-11-30 Daniel Borkmann
@ 2023-11-30  3:50 ` patchwork-bot+netdevbpf
  2023-11-30 14:53 ` Eric Dumazet
  1 sibling, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-30  3:50 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: davem, kuba, pabeni, edumazet, ast, andrii, martin.lau, netdev,
	bpf

Hello:

This pull request was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 30 Nov 2023 00:49:16 +0100 you wrote:
> Hi David, hi Jakub, hi Paolo, hi Eric,
> 
> The following pull-request contains BPF updates for your *net* tree.
> 
> We've added 5 non-merge commits during the last 7 day(s) which contain
> a total of 10 files changed, 66 insertions(+), 15 deletions(-).
> 
> [...]

Here is the summary with links:
  - pull-request: bpf 2023-11-30
    https://git.kernel.org/netdev/net/c/0d47fa5cc91b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-29 23:49 pull-request: bpf 2023-11-30 Daniel Borkmann
  2023-11-30  3:50 ` patchwork-bot+netdevbpf
@ 2023-11-30 14:53 ` Eric Dumazet
  2023-11-30 15:04   ` Daniel Borkmann
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2023-11-30 14:53 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: davem, kuba, pabeni, ast, andrii, martin.lau, netdev, bpf

On Thu, Nov 30, 2023 at 12:49 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> Hi David, hi Jakub, hi Paolo, hi Eric,
>
> The following pull-request contains BPF updates for your *net* tree.
>
> We've added 5 non-merge commits during the last 7 day(s) which contain
> a total of 10 files changed, 66 insertions(+), 15 deletions(-).
>
> The main changes are:
>
> 1) Fix AF_UNIX splat from use after free in BPF sockmap, from John Fastabend.


syzbot is not happy with this patch.

Would the following fix make sense?

diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
index 7ea7c3a0d0d06224f49ad5f073bf772b9528a30a..58e89361059fbf9d5942c6dd268dd80ac4b57098
100644
--- a/net/unix/unix_bpf.c
+++ b/net/unix/unix_bpf.c
@@ -168,7 +168,8 @@ int unix_stream_bpf_update_proto(struct sock *sk,
struct sk_psock *psock, bool r
        }

        sk_pair = unix_peer(sk);
-       sock_hold(sk_pair);
+       if (sk_pair)
+               sock_hold(sk_pair);
        psock->sk_pair = sk_pair;
        unix_stream_bpf_check_needs_rebuild(psock->sk_proto);
        sock_replace_proto(sk, &unix_stream_bpf_prot);


>
> 2) Fix a syzkaller splat in netdevsim by properly handling offloaded programs (and
>    not device-bound ones), from Stanislav Fomichev.
>
> 3) Fix bpf_mem_cache_alloc_flags() to initialize the allocation hint, from Hou Tao.
>
> 4) Fix netkit by rejecting IFLA_NETKIT_PEER_INFO in changelink, from Daniel Borkmann.
>
> Please consider pulling these changes from:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git tags/for-netdev
>
> Thanks a lot!
>
> Also thanks to reporters, reviewers and testers of commits in this pull-request:
>
> Jakub Kicinski, Jakub Sitnicki, Nikolay Aleksandrov, Yonghong Song
>
> ----------------------------------------------------------------
>
> The following changes since commit d3fa86b1a7b4cdc4367acacea16b72e0a200b3d7:
>
>   Merge tag 'net-6.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2023-11-23 10:40:13 -0800)
>
> are available in the Git repository at:
>
>   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git tags/for-netdev
>
> for you to fetch changes up to 51354f700d400e55b329361e1386b04695e6e5c1:
>
>   bpf, sockmap: Add af_unix test with both sockets in map (2023-11-30 00:25:25 +0100)
>
> ----------------------------------------------------------------
> bpf-for-netdev
>
> ----------------------------------------------------------------
> Daniel Borkmann (1):
>       netkit: Reject IFLA_NETKIT_PEER_INFO in netkit_change_link
>
> Hou Tao (1):
>       bpf: Add missed allocation hint for bpf_mem_cache_alloc_flags()
>
> John Fastabend (2):
>       bpf, sockmap: af_unix stream sockets need to hold ref for pair sock
>       bpf, sockmap: Add af_unix test with both sockets in map
>
> Stanislav Fomichev (1):
>       netdevsim: Don't accept device bound programs
>
>  drivers/net/netdevsim/bpf.c                        |  4 +-
>  drivers/net/netkit.c                               |  6 +++
>  include/linux/skmsg.h                              |  1 +
>  include/net/af_unix.h                              |  1 +
>  kernel/bpf/memalloc.c                              |  2 +
>  net/core/skmsg.c                                   |  2 +
>  net/unix/af_unix.c                                 |  2 -
>  net/unix/unix_bpf.c                                |  5 +++
>  .../selftests/bpf/prog_tests/sockmap_listen.c      | 51 +++++++++++++++++-----
>  .../selftests/bpf/progs/test_sockmap_listen.c      |  7 +++
>  10 files changed, 66 insertions(+), 15 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-30 14:53 ` Eric Dumazet
@ 2023-11-30 15:04   ` Daniel Borkmann
  2023-11-30 15:54     ` John Fastabend
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Borkmann @ 2023-11-30 15:04 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, ast, andrii, martin.lau, netdev, bpf,
	john.fastabend, jakub

On 11/30/23 3:53 PM, Eric Dumazet wrote:
> On Thu, Nov 30, 2023 at 12:49 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>>
>> Hi David, hi Jakub, hi Paolo, hi Eric,
>>
>> The following pull-request contains BPF updates for your *net* tree.
>>
>> We've added 5 non-merge commits during the last 7 day(s) which contain
>> a total of 10 files changed, 66 insertions(+), 15 deletions(-).
>>
>> The main changes are:
>>
>> 1) Fix AF_UNIX splat from use after free in BPF sockmap, from John Fastabend.
> 
> syzbot is not happy with this patch.
> 
> Would the following fix make sense?
> 
> diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
> index 7ea7c3a0d0d06224f49ad5f073bf772b9528a30a..58e89361059fbf9d5942c6dd268dd80ac4b57098
> 100644
> --- a/net/unix/unix_bpf.c
> +++ b/net/unix/unix_bpf.c
> @@ -168,7 +168,8 @@ int unix_stream_bpf_update_proto(struct sock *sk,
> struct sk_psock *psock, bool r
>          }
> 
>          sk_pair = unix_peer(sk);
> -       sock_hold(sk_pair);
> +       if (sk_pair)
> +               sock_hold(sk_pair);
>          psock->sk_pair = sk_pair;
>          unix_stream_bpf_check_needs_rebuild(psock->sk_proto);
>          sock_replace_proto(sk, &unix_stream_bpf_prot);
> 

Oh well :/ Above looks reasonable to me, thanks, but I'll defer to John & Jakub (both Cc'ed)
for a final look.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-30 15:04   ` Daniel Borkmann
@ 2023-11-30 15:54     ` John Fastabend
  2023-11-30 16:04       ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: John Fastabend @ 2023-11-30 15:54 UTC (permalink / raw)
  To: Daniel Borkmann, Eric Dumazet
  Cc: davem, kuba, pabeni, ast, andrii, martin.lau, netdev, bpf,
	john.fastabend, jakub

Daniel Borkmann wrote:
> On 11/30/23 3:53 PM, Eric Dumazet wrote:
> > On Thu, Nov 30, 2023 at 12:49 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> >>
> >> Hi David, hi Jakub, hi Paolo, hi Eric,
> >>
> >> The following pull-request contains BPF updates for your *net* tree.
> >>
> >> We've added 5 non-merge commits during the last 7 day(s) which contain
> >> a total of 10 files changed, 66 insertions(+), 15 deletions(-).
> >>
> >> The main changes are:
> >>
> >> 1) Fix AF_UNIX splat from use after free in BPF sockmap, from John Fastabend.
> > 
> > syzbot is not happy with this patch.
> > 
> > Would the following fix make sense?
> > 
> > diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
> > index 7ea7c3a0d0d06224f49ad5f073bf772b9528a30a..58e89361059fbf9d5942c6dd268dd80ac4b57098
> > 100644
> > --- a/net/unix/unix_bpf.c
> > +++ b/net/unix/unix_bpf.c
> > @@ -168,7 +168,8 @@ int unix_stream_bpf_update_proto(struct sock *sk,
> > struct sk_psock *psock, bool r
> >          }
> > 
> >          sk_pair = unix_peer(sk);
> > -       sock_hold(sk_pair);
> > +       if (sk_pair)
> > +               sock_hold(sk_pair);
> >          psock->sk_pair = sk_pair;
> >          unix_stream_bpf_check_needs_rebuild(psock->sk_proto);
> >          sock_replace_proto(sk, &unix_stream_bpf_prot);
> > 
> 
> Oh well :/ Above looks reasonable to me, thanks, but I'll defer to John & Jakub (both Cc'ed)
> for a final look.
> 
> Thanks,
> Daniel

Is that sk in LISTEN state by any chance? I can't think why we even allow such a
thing for af_unix sockets.  Another possible fix would be to block adding these
to sockmap at all.

But, above should be fine as well so I would just go with that. Eric or Daniel
would you like to submit a patch or I can if needed.

Thanks,
John

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-30 15:54     ` John Fastabend
@ 2023-11-30 16:04       ` Eric Dumazet
  2023-11-30 16:19         ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2023-11-30 16:04 UTC (permalink / raw)
  To: John Fastabend
  Cc: Daniel Borkmann, davem, kuba, pabeni, ast, andrii, martin.lau,
	netdev, bpf, jakub

On Thu, Nov 30, 2023 at 4:54 PM John Fastabend <john.fastabend@gmail.com> wrote:
>
> Daniel Borkmann wrote:
> > On 11/30/23 3:53 PM, Eric Dumazet wrote:
> > > On Thu, Nov 30, 2023 at 12:49 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> > >>
> > >> Hi David, hi Jakub, hi Paolo, hi Eric,
> > >>
> > >> The following pull-request contains BPF updates for your *net* tree.
> > >>
> > >> We've added 5 non-merge commits during the last 7 day(s) which contain
> > >> a total of 10 files changed, 66 insertions(+), 15 deletions(-).
> > >>
> > >> The main changes are:
> > >>
> > >> 1) Fix AF_UNIX splat from use after free in BPF sockmap, from John Fastabend.
> > >
> > > syzbot is not happy with this patch.
> > >
> > > Would the following fix make sense?
> > >
> > > diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c
> > > index 7ea7c3a0d0d06224f49ad5f073bf772b9528a30a..58e89361059fbf9d5942c6dd268dd80ac4b57098
> > > 100644
> > > --- a/net/unix/unix_bpf.c
> > > +++ b/net/unix/unix_bpf.c
> > > @@ -168,7 +168,8 @@ int unix_stream_bpf_update_proto(struct sock *sk,
> > > struct sk_psock *psock, bool r
> > >          }
> > >
> > >          sk_pair = unix_peer(sk);
> > > -       sock_hold(sk_pair);
> > > +       if (sk_pair)
> > > +               sock_hold(sk_pair);
> > >          psock->sk_pair = sk_pair;
> > >          unix_stream_bpf_check_needs_rebuild(psock->sk_proto);
> > >          sock_replace_proto(sk, &unix_stream_bpf_prot);
> > >
> >
> > Oh well :/ Above looks reasonable to me, thanks, but I'll defer to John & Jakub (both Cc'ed)
> > for a final look.
> >
> > Thanks,
> > Daniel
>
> Is that sk in LISTEN state by any chance? I can't think why we even allow such a
> thing for af_unix sockets.  Another possible fix would be to block adding these
> to sockmap at all.
>
> But, above should be fine as well so I would just go with that. Eric or Daniel
> would you like to submit a patch or I can if needed.

Here is the repro:

# See https://goo.gl/kgGztJ for information about syzkaller reproducers.
#{"procs":1,"slowdown":1,"sandbox":"","sandbox_arg":0,"close_fds":false}
r0 = socket(0x1, 0x1, 0x0)
r1 = bpf$MAP_CREATE(0x0, &(0x7f0000000200)=@base={0xf, 0x4, 0x4, 0x12}, 0x48)
bpf$MAP_UPDATE_ELEM(0x2, &(0x7f0000000140)={r1, &(0x7f0000000000),
&(0x7f0000000100)=@tcp6=r0}, 0x20)

I will release the syzbot report, and send the patch, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-30 16:04       ` Eric Dumazet
@ 2023-11-30 16:19         ` Eric Dumazet
  2023-11-30 23:37           ` John Fastabend
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2023-11-30 16:19 UTC (permalink / raw)
  To: John Fastabend
  Cc: Daniel Borkmann, davem, kuba, pabeni, ast, andrii, martin.lau,
	netdev, bpf, jakub

On Thu, Nov 30, 2023 at 5:04 PM Eric Dumazet <edumazet@google.com> wrote:
>

> Here is the repro:
>
> # See https://goo.gl/kgGztJ for information about syzkaller reproducers.
> #{"procs":1,"slowdown":1,"sandbox":"","sandbox_arg":0,"close_fds":false}
> r0 = socket(0x1, 0x1, 0x0)
> r1 = bpf$MAP_CREATE(0x0, &(0x7f0000000200)=@base={0xf, 0x4, 0x4, 0x12}, 0x48)
> bpf$MAP_UPDATE_ELEM(0x2, &(0x7f0000000140)={r1, &(0x7f0000000000),
> &(0x7f0000000100)=@tcp6=r0}, 0x20)
>
> I will release the syzbot report, and send the patch, thanks.

Actually I will release the syzbot report, and let you work on a fix,
perhaps as you pointed out we could be more restrictive.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: pull-request: bpf 2023-11-30
  2023-11-30 16:19         ` Eric Dumazet
@ 2023-11-30 23:37           ` John Fastabend
  0 siblings, 0 replies; 8+ messages in thread
From: John Fastabend @ 2023-11-30 23:37 UTC (permalink / raw)
  To: Eric Dumazet, John Fastabend
  Cc: Daniel Borkmann, davem, kuba, pabeni, ast, andrii, martin.lau,
	netdev, bpf, jakub

Eric Dumazet wrote:
> On Thu, Nov 30, 2023 at 5:04 PM Eric Dumazet <edumazet@google.com> wrote:
> >
> 
> > Here is the repro:
> >
> > # See https://goo.gl/kgGztJ for information about syzkaller reproducers.
> > #{"procs":1,"slowdown":1,"sandbox":"","sandbox_arg":0,"close_fds":false}
> > r0 = socket(0x1, 0x1, 0x0)
> > r1 = bpf$MAP_CREATE(0x0, &(0x7f0000000200)=@base={0xf, 0x4, 0x4, 0x12}, 0x48)
> > bpf$MAP_UPDATE_ELEM(0x2, &(0x7f0000000140)={r1, &(0x7f0000000000),
> > &(0x7f0000000100)=@tcp6=r0}, 0x20)
> >
> > I will release the syzbot report, and send the patch, thanks.
> 
> Actually I will release the syzbot report, and let you work on a fix,
> perhaps as you pointed out we could be more restrictive.

Thanks, I think just fixing the null ptr deref is probably not enough because
that socket could be connected() after that and then we get back to the original
issue where we don't hold a ref on the peer sock. I'll just block adding non
established af_unix socks to the map and if someone wants to support unconnected
sockets they can add support for it then.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-30 23:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-29 23:49 pull-request: bpf 2023-11-30 Daniel Borkmann
2023-11-30  3:50 ` patchwork-bot+netdevbpf
2023-11-30 14:53 ` Eric Dumazet
2023-11-30 15:04   ` Daniel Borkmann
2023-11-30 15:54     ` John Fastabend
2023-11-30 16:04       ` Eric Dumazet
2023-11-30 16:19         ` Eric Dumazet
2023-11-30 23:37           ` John Fastabend

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).