From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <kuniyu@amazon.com>
Cc: <bpf@vger.kernel.org>, <kernel-team@cloudflare.com>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
<yan@cloudflare.com>
Subject: Re: Unchecked sock pointer causes panic in RAW_TP
Date: Fri, 31 Jan 2025 15:28:51 -0800 [thread overview]
Message-ID: <20250131232851.36345-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20250131223838.31897-1-kuniyu@amazon.com>
From: Kuniyuki Iwashima <kuniyu@amazon.com>
Date: Fri, 31 Jan 2025 14:38:38 -0800
> From: Yan Zhai <yan@cloudflare.com>
> Date: Fri, 31 Jan 2025 12:32:57 -0800
> > Hello,
> >
> > We encountered a panic when tracing kfree_skb with RAW_TP. The problematic
> > argument was introduced in commit ba8de796baf4 ("net: introduce
> > sk_skb_reason_drop function"). It turns out that the verifier still accepted
> > the program despite it didn't test sk == NULL. And this caused kernel panic. I
> > attached a small reproducer and panic trace at the end. It's stably
> > reproducible when packets are dropped without a receiver (e.g. run iperf2 UDP
> > test toward localhost), in both 6.12.11 release and a recent bpf-next master
> > snapshot (I was using commit c03320a6768c).
> >
> > As a contrast, for another tracepoint like tcp_send_reset, if sk is not checked
> > before dereferencing, the verifier will complain and reject the program as
> > expected. So this feels like some annotation is missing? Appreciate if someone
> > could help me figure out.
>
> Maybe __nullable is missing given we annotated skb for tcp_send_reset ?
> https://lore.kernel.org/netdev/20240911033719.91468-4-lulie@linux.alibaba.com/
>
> completely untested:
>
> ---8<---
> diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
> index b877133cd93a..34accc5929d6 100644
> --- a/include/trace/events/skb.h
> +++ b/include/trace/events/skb.h
> @@ -24,14 +24,14 @@ DEFINE_DROP_REASON(FN, FN)
> TRACE_EVENT(kfree_skb,
>
> TP_PROTO(struct sk_buff *skb, void *location,
> - enum skb_drop_reason reason, struct sock *rx_sk),
> + enum skb_drop_reason reason, struct sock *rx_sk__nullable),
>
> - TP_ARGS(skb, location, reason, rx_sk),
> + TP_ARGS(skb, location, reason, rx_sk__nullable),
>
> TP_STRUCT__entry(
> __field(void *, skbaddr)
> __field(void *, location)
> - __field(void *, rx_sk)
> + __field(void *, rx_sk__nullable)
This part is unnecessary.
> __field(unsigned short, protocol)
> __field(enum skb_drop_reason, reason)
> ),
> @@ -39,7 +39,7 @@ TRACE_EVENT(kfree_skb,
> TP_fast_assign(
> __entry->skbaddr = skb;
> __entry->location = location;
> - __entry->rx_sk = rx_sk;
> + __entry->rx_sk = rx_sk__nullable;
> __entry->protocol = ntohs(skb->protocol);
> __entry->reason = reason;
> ),
> ---8<---
>
next prev parent reply other threads:[~2025-01-31 23:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-31 20:32 Unchecked sock pointer causes panic in RAW_TP Yan Zhai
2025-01-31 22:38 ` Kuniyuki Iwashima
2025-01-31 23:28 ` Kuniyuki Iwashima [this message]
2025-02-01 0:24 ` Kuniyuki Iwashima
2025-02-01 0:55 ` Yan Zhai
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=20250131232851.36345-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yan@cloudflare.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