From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <zacecob@protonmail.com>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <kuniyu@amazon.com>
Subject: Re: Returning negative values repeatedly from a SOCK_FILTER ebpf prog stalls kernel thread
Date: Sat, 22 Jun 2024 21:51:41 -0700 [thread overview]
Message-ID: <20240623045141.78101-1-kuniyu@amazon.com> (raw)
In-Reply-To: <CJrradVmkT-HM6goIYbivHNdWglG0h11_0Ky2ObV_ZCOunJaksIj9alG1UTHCkSDX_Jhm6uB5P5vS8C75QfrjWrqeHisUIDn2023xfv7jp0=@protonmail.com>
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
next prev parent reply other threads:[~2024-06-23 4:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-06-22 12:15 Zac Ecob
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240623045141.78101-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=bpf@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=zacecob@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox