Skip to contentSkip to conversation

net: validate skb->napi_id in RX tracepoints

PATCH Applied Kohei Enju 4 participants 6 messages Apr 20 – Apr 23

Subsystems (3)
lore
Share & tools
lore

Kohei Enju

author
#0 lore raw

PATCH 1/1 net: validate skb->napi_id in RX tracepoints

Since commit 2bd82484bb4c ("xps: fix xps for stacked devices"), skb->napi_id shares storage with sender_cpu. RX tracepoints using net_dev_rx_verbose_template read skb->napi_id directly and can therefore report sender_cpu values as if they were NAPI IDs.

For example, on the loopback path this can report 1 as napi_id, where 1 comes from raw_smp_processor_id() + 1 in the XPS path:

  # bpftrace -e 'tracepoint:net:netif_rx_entry{ print(args->napi_id); }'
  # taskset -c 0 ping -c 1 ::1

Report only valid NAPI IDs in these tracepoints and use 0 otherwise.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")
---
 include/trace/events/net.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/trace/events/net.h +3 -1
index fdd9ad474ce3..dbc2c5598e35 100644
@@ -10,6 +10,7 @@
 #include <linux/if_vlan.h>
 #include <linux/ip.h>
 #include <linux/tracepoint.h>
+#include <net/busy_poll.h>
 
 TRACE_EVENT(net_dev_start_xmit,
 
@@ -208,7 +209,8 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,
 	TP_fast_assign(
 		__assign_str(name);
 #ifdef CONFIG_NET_RX_BUSY_POLL
-		__entry->napi_id = skb->napi_id;
+		__entry->napi_id = napi_id_valid(skb->napi_id) ?
+				   skb->napi_id : 0;
 #else
 		__entry->napi_id = 0;
 #endif
Signature · 1 line
2.51.0
#1 lore raw
Quoted 6 lines · Kohei Enju

Since commit 2bd82484bb4c ("xps: fix xps for stacked devices"), skb->napi_id shares storage with sender_cpu. RX tracepoints using net_dev_rx_verbose_template read skb->napi_id directly and can therefore report sender_cpu values as if they were NAPI IDs.

For example, on the loopback path this can report 1 as napi_id, where 1

So I think veth_forward_skb->__netif_rx could be affected as well?

Quoted 35 lines

comes from raw_smp_processor_id() + 1 in the XPS path:

   # bpftrace -e 'tracepoint:net:netif_rx_entry{ print(args->napi_id); }'
   # taskset -c 0 ping -c 1 ::1

Report only valid NAPI IDs in these tracepoints and use 0 otherwise.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")
---
  include/trace/events/net.h | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
include/trace/events/net.h +3 -1
index fdd9ad474ce3..dbc2c5598e35 100644
@@ -10,6 +10,7 @@
  #include <linux/if_vlan.h>
  #include <linux/ip.h>
  #include <linux/tracepoint.h>
+#include <net/busy_poll.h>
 
  TRACE_EVENT(net_dev_start_xmit,
 
@@ -208,7 +209,8 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,
  	TP_fast_assign(
  		__assign_str(name);
  #ifdef CONFIG_NET_RX_BUSY_POLL
-		__entry->napi_id = skb->napi_id;
+		__entry->napi_id = napi_id_valid(skb->napi_id) ?
+				   skb->napi_id : 0;
  #else
  		__entry->napi_id = 0;
  #endif
author
#2 lore raw
Quoted 9 lines · Jiayuan Chen
Quoted 6 lines · Kohei Enju

Since commit 2bd82484bb4c ("xps: fix xps for stacked devices"), skb->napi_id shares storage with sender_cpu. RX tracepoints using net_dev_rx_verbose_template read skb->napi_id directly and can therefore report sender_cpu values as if they were NAPI IDs.

For example, on the loopback path this can report 1 as napi_id, where 1

So I think veth_forward_skb->__netif_rx could be affected as well?

Yes. Just in case, I've confirmed the same behavior in the veth path. The mentioned loopback path is just a single example of possibly affected paths.

Thanks,
Kohei

Quoted 33 lines
Quoted 33 lines

comes from raw_smp_processor_id() + 1 in the XPS path:

   # bpftrace -e 'tracepoint:net:netif_rx_entry{ print(args->napi_id); }'
   # taskset -c 0 ping -c 1 ::1

Report only valid NAPI IDs in these tracepoints and use 0 otherwise.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")
---
  include/trace/events/net.h | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
include/trace/events/net.h +3 -1
index fdd9ad474ce3..dbc2c5598e35 100644
@@ -10,6 +10,7 @@
  #include <linux/if_vlan.h>
  #include <linux/ip.h>
  #include <linux/tracepoint.h>
+#include <net/busy_poll.h>
  TRACE_EVENT(net_dev_start_xmit,
@@ -208,7 +209,8 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,
  	TP_fast_assign(
  		__assign_str(name);
  #ifdef CONFIG_NET_RX_BUSY_POLL
-		__entry->napi_id = skb->napi_id;
+		__entry->napi_id = napi_id_valid(skb->napi_id) ?
+				   skb->napi_id : 0;
  #else
  		__entry->napi_id = 0;
  #endif
Reviewed-by
#3 lore raw
Quoted 7 lines · Kohei Enju
Quoted 6 lines · Jiayuan Chen
Quoted 5 lines · Kohei Enju

Since commit 2bd82484bb4c ("xps: fix xps for stacked devices"), skb->napi_id shares storage with sender_cpu. RX tracepoints using net_dev_rx_verbose_template read skb->napi_id directly and can therefore report sender_cpu values as if they were NAPI IDs.

Quoted 9 lines
Quoted 2 lines
Quoted 1 line

For example, on the loopback path this can report 1 as napi_id, where 1

So I think veth_forward_skb->__netif_rx could be affected as well?

Yes. Just in case, I've confirmed the same behavior in the veth path. The mentioned loopback path is just a single example of possibly affected paths.

Thanks,
Kohei

reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to Kohei Enju
Quoted 8 lines · Kohei Enju

Since commit 2bd82484bb4c ("xps: fix xps for stacked devices"), skb->napi_id shares storage with sender_cpu. RX tracepoints using net_dev_rx_verbose_template read skb->napi_id directly and can therefore report sender_cpu values as if they were NAPI IDs.

For example, on the loopback path this can report 1 as napi_id, where 1 comes from raw_smp_processor_id() + 1 in the XPS path:

Quoted 7 lines
  # bpftrace -e 'tracepoint:net:netif_rx_entry{ print(args->napi_id); }'
  # taskset -c 0 ping -c 1 ::1

Report only valid NAPI IDs in these tracepoints and use 0 otherwise.

Fixes 2bd82484bb4c ("xps: fix xps for stacked devices")
Quoted 17 lines
---
 include/trace/events/net.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/trace/events/net.h +1 -0
index fdd9ad474ce3..dbc2c5598e35 100644
@@ -10,6 +10,7 @@
 #include <linux/if_vlan.h>
 #include <linux/ip.h>
 #include <linux/tracepoint.h>
+#include <net/busy_poll.h>
 
 TRACE_EVENT(net_dev_start_xmit,
 

include/trace/events/net.h DECLARE_EVENT_CLASS(net_dev_rx_verbose_template, · line 213

Quoted 6 lines
include/trace/events/net.h +2 -1
@@ -208,7 +209,8 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,
 	TP_fast_assign(
 		__assign_str(name);
 #ifdef CONFIG_NET_RX_BUSY_POLL
-		__entry->napi_id = skb->napi_id;
+		__entry->napi_id = napi_id_valid(skb->napi_id) ?
+				   skb->napi_id : 0;

Note to self: they key is that if the storage at napi_id is being used as a sender_cpu then napi_id_valid because the valid values for a sender_cpu are disjoint from those of a valid napi_id. This can be seen clearly in the implementation of napi_id_valid() and the comment above it.

Quoted 6 lines
include/trace/events/net.h +0 -0
 #else
 		__entry->napi_id = 0;
 #endif
Signature · 1 line
2.51.0
#5 lore raw
In reply to Kohei Enju
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 20 Apr 2026 10:54:23 +0000 you wrote:

Since commit 2bd82484bb4c ("xps: fix xps for stacked devices"), skb->napi_id shares storage with sender_cpu. RX tracepoints using net_dev_rx_verbose_template read skb->napi_id directly and can therefore report sender_cpu values as if they were NAPI IDs.

For example, on the loopback path this can report 1 as napi_id, where 1 comes from raw_smp_processor_id() + 1 in the XPS path:

[...]

Here is the summary with links:
- [net,v1] net: validate skb->napi_id in RX tracepoints

    https://git.kernel.org/netdev/net/c/3bfcf396081a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html