netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Returning negative values repeatedly from a SOCK_FILTER ebpf prog stalls kernel thread
@ 2024-06-22 12:15 Zac Ecob
  0 siblings, 0 replies; 3+ messages in thread
From: Zac Ecob @ 2024-06-22 12:15 UTC (permalink / raw)
  To: bpf@vger.kernel.org, netdev@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

Problem is title. Attached is files for repro. Working on v6.10-rc4. 

After doing some investigation, the `sk_wmem_alloc` member of `struct sk` seems to only be increasing, presumably missing some refcnt_dec somewhere.

At a certain point, in `sock_alloc_send_pskb`, we fail the check:

`
if (sk_wmem_alloc_get(sk) < READ_ONCE(sk->sk_sndbuf))
`

Upon which we enter `sock_wait_for_wmem` and schedule a massive timeout (at least that's what happened in my tests)


Please let me know if I need to add anything.

Thanks
Not sure where the missing refcnt subs are, must admit unfamiliarity with the network code.


[-- Attachment #2: repro.tar.xz --]
[-- Type: application/x-xz, Size: 2172 bytes --]

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

* Returning negative values repeatedly from a SOCK_FILTER ebpf prog stalls kernel thread
@ 2024-06-22 12:20 Zac Ecob
  2024-06-23  4:51 ` Kuniyuki Iwashima
  0 siblings, 1 reply; 3+ messages in thread
From: Zac Ecob @ 2024-06-22 12:20 UTC (permalink / raw)
  To: bpf@vger.kernel.org, netdev@vger.kernel.org

Problem is title. 

To trigger, I attached an EBPF prof that just returned -1, and send ~1000 packets through it.

After doing some investigation, the `sk_wmem_alloc` member of `struct sk` seems to only be increasing, presumably missing some refcnt_dec somewhere. 

At a certain point, in `sock_alloc_send_pskb`, we fail the check: 

`
if (sk_wmem_alloc_get(sk) < READ_ONCE(sk->sk_sndbuf))
` 

Upon which we enter `sock_wait_for_wmem` and schedule a massive timeout (at least that's what happened in my tests).

Not sure where the missing refcnt subs are, must admit unfamiliarity with the network code.

Please let me know if I need to add anything. 

Thanks

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

* Re: Returning negative values repeatedly from a SOCK_FILTER ebpf prog stalls kernel thread
  2024-06-22 12:20 Returning negative values repeatedly from a SOCK_FILTER ebpf prog stalls kernel thread Zac Ecob
@ 2024-06-23  4:51 ` Kuniyuki Iwashima
  0 siblings, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2024-06-23  4:51 UTC (permalink / raw)
  To: zacecob; +Cc: bpf, netdev, kuniyu

From: Zac Ecob <zacecob@protonmail.com>
Date: Sat, 22 Jun 2024 12:20:05 +0000
> Problem is title.
> 
> To trigger, I attached an EBPF prof that just returned -1, and send ~1000
> packets through it.

If you want to drop the packet, the prog must return 0.

You can see sk_filter_trim_cap() where the returned value from bpf prog
is cast to unsigned int.  Then, pskb_trim() does nothing because skb->len
is smaller than (unsigned int)-1, and 0 is set to err.

  unsigned int pkt_len;

  pkt_len = bpf_prog_run_save_cb(filter->prog, skb);
  err = pkt_len ? pskb_trim(skb, max(cap, pkt_len)) : -EPERM;

After calling sk_filter() from unix_dgram_sendmsg(), the skb is just queued
to the peer.


> 
> After doing some investigation, the `sk_wmem_alloc` member of `struct sk`
> seems to only be increasing, presumably missing some refcnt_dec somewhere.

So, no refcnt is leaked.
What is missing is recv() on the peer side.


> 
> At a certain point, in `sock_alloc_send_pskb`, we fail the check: 
> 
> `
> if (sk_wmem_alloc_get(sk) < READ_ONCE(sk->sk_sndbuf))
> ` 
> 
> Upon which we enter `sock_wait_for_wmem` and schedule a massive timeout
> (at least that's what happened in my tests).
> 
> Not sure where the missing refcnt subs are, must admit unfamiliarity with
> the network code.

The paired sub is sock_wfree() in unix_destruct_scm(), which is set
to skb->destructor() in unix_scm_to_skb() and called from kfree_skb().


> 
> Please let me know if I need to add anything. 
> 
> Thanks

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

end of thread, other threads:[~2024-06-23  4:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-22 12:20 Returning negative values repeatedly from a SOCK_FILTER ebpf prog stalls kernel thread Zac Ecob
2024-06-23  4:51 ` Kuniyuki Iwashima
  -- strict thread matches above, loose matches on Subject: below --
2024-06-22 12:15 Zac Ecob

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).