From: Jesper Dangaard Brouer <hawk@kernel.org>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
"Eric Dumazet" <eric.dumazet@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
"Paolo Abeni" <pabeni@redhat.com>,
"Toke Høiland-Jørgensen" <toke@toke.dk>,
kernel-team@cloudflare.com, mfleming@cloudflare.com
Subject: Re: [PATCH net-next V1] net: track pfmemalloc drops via SKB_DROP_REASON_PFMEMALLOC
Date: Fri, 9 May 2025 15:48:04 +0200 [thread overview]
Message-ID: <665a622b-cb6b-4647-a287-b1b03d78e02f@kernel.org> (raw)
In-Reply-To: <20250502161733.17fd0d60@kernel.org>
On 03/05/2025 01.17, Jakub Kicinski wrote:
> On Fri, 02 May 2025 17:16:38 +0200 Jesper Dangaard Brouer wrote:
>> @@ -142,15 +144,20 @@ int sk_filter_trim_cap(struct sock *sk, struct sk_buff *skb, unsigned int cap)
>> */
>> if (skb_pfmemalloc(skb) && !sock_flag(sk, SOCK_MEMALLOC)) {
>> NET_INC_STATS(sock_net(sk), LINUX_MIB_PFMEMALLOCDROP);
>> + *reason = SKB_DROP_REASON_PFMEMALLOC;
>> return -ENOMEM;
>> }
>> err = BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb);
>> - if (err)
>> + if (err) {
>> + *reason = SKB_DROP_REASON_SOCKET_FILTER;
>> return err;
>> + }
>>
>> err = security_sock_rcv_skb(sk, skb);
>> - if (err)
>> + if (err) {
>> + *reason = SKB_DROP_REASON_SECURITY_HOOK;
>> return err;
>> + }
>>
>> rcu_read_lock();
>> filter = rcu_dereference(sk->sk_filter);
>
> there is:
>
> err = pkt_len ? pskb_trim(skb, max(cap, pkt_len)) : -EPERM;
>
> later on, which I think may return error without touching drop reason.
> If caller didn't init it the reason will be undefined.
Good review, thanks for catching this.
In this (-EPERM) case should clearly set SKB_DROP_REASON_SOCKET_FILTER.
It is the original "main" reason for socket filter drop decision.
Thanks for catching my mistake.
The BPF-prog return value for type BPF_PROG_TYPE_SOCKET_FILTER is
different than more modern BPF-prog types (that usually returns an
action). This confused me a bit when reading the code, so let link the
documentation here[1] to help reviewers and seed Google + AIs.
It states: "The return value from indicates how many bytes of the
message should be kept. Returning a value less then the side of the
packet will truncate it and returning 0 will discard the packet."
Will send a V2.
--Jesper
[1] https://docs.ebpf.io/linux/program-type/BPF_PROG_TYPE_SOCKET_FILTER/
prev parent reply other threads:[~2025-05-09 13:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 15:16 [PATCH net-next V1] net: track pfmemalloc drops via SKB_DROP_REASON_PFMEMALLOC Jesper Dangaard Brouer
2025-05-02 23:17 ` Jakub Kicinski
2025-05-09 13:48 ` Jesper Dangaard Brouer [this message]
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=665a622b-cb6b-4647-a287-b1b03d78e02f@kernel.org \
--to=hawk@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=kuba@kernel.org \
--cc=mfleming@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=toke@toke.dk \
/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;
as well as URLs for NNTP newsgroup(s).