Skip to contentSkip to conversation

net: sched: fix TCF_LAYER_TRANSPORT handling in tcf_get_base_ptr()

PATCH Applied Eric Dumazet 3 participants 3 messages Nov 21, 2025 – Nov 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sched: fix TCF_LAYER_TRANSPORT handling in tcf_get_base_ptr()

syzbot reported that tcf_get_base_ptr() can be called while transport header is not set [1].

Instead of returning a dangling pointer, return NULL.

Fix tcf_get_base_ptr() callers to handle this NULL value.

[1]

 WARNING: CPU: 1 PID: 6019 at ./include/linux/skbuff.h:3071 skb_transport_header include/linux/skbuff.h:3071 [inline]
 WARNING: CPU: 1 PID: 6019 at ./include/linux/skbuff.h:3071 tcf_get_base_ptr include/net/pkt_cls.h:539 [inline]
 WARNING: CPU: 1 PID: 6019 at ./include/linux/skbuff.h:3071 em_nbyte_match+0x2d8/0x3f0 net/sched/em_nbyte.c:43
Modules linked in:
CPU: 1 UID: 0 PID: 6019 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Call Trace:
 <TASK>
  tcf_em_match net/sched/ematch.c:494 [inline]
  __tcf_em_tree_match+0x1ac/0x770 net/sched/ematch.c:520
  tcf_em_tree_match include/net/pkt_cls.h:512 [inline]
  basic_classify+0x115/0x2d0 net/sched/cls_basic.c:50
  tc_classify include/net/tc_wrapper.h:197 [inline]
  __tcf_classify net/sched/cls_api.c:1764 [inline]
  tcf_classify+0x4cf/0x1140 net/sched/cls_api.c:1860
  multiq_classify net/sched/sch_multiq.c:39 [inline]
  multiq_enqueue+0xfd/0x4c0 net/sched/sch_multiq.c:66
  dev_qdisc_enqueue+0x4e/0x260 net/core/dev.c:4118
  __dev_xmit_skb net/core/dev.c:4214 [inline]
  __dev_queue_xmit+0xe83/0x3b50 net/core/dev.c:4729
  packet_snd net/packet/af_packet.c:3076 [inline]
  packet_sendmsg+0x3e33/0x5080 net/packet/af_packet.c:3108
  sock_sendmsg_nosec net/socket.c:727 [inline]
  __sock_sendmsg+0x21c/0x270 net/socket.c:742
  ____sys_sendmsg+0x505/0x830 net/socket.c:2630
---
 include/net/pkt_cls.h |  2 ++
 net/sched/em_cmp.c    |  5 ++++-
 net/sched/em_nbyte.c  |  2 ++
 net/sched/em_text.c   | 11 +++++++++--
 4 files changed, 17 insertions(+), 3 deletions(-)
include/net/pkt_cls.h +2 -0
index c64fd896b1f985c5f6a5b50cbb42ded640d0c9fe..99ac747b7906074c43b3eb8e34cf6c07235cc81d 100644
@@ -536,6 +536,8 @@ static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
 		case TCF_LAYER_NETWORK:
 			return skb_network_header(skb);
 		case TCF_LAYER_TRANSPORT:
+			if (!skb_transport_header_was_set(skb))
+				break;
 			return skb_transport_header(skb);
 	}
 
net/sched/em_cmp.c +4 -1
index 64b637f18bc7d40509bf5c9f7679cfbc2922af1c..48c1bce74f498d0b4ee3d1efde96459b0dac5896 100644
@@ -22,9 +22,12 @@ static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
 			struct tcf_pkt_info *info)
 {
 	struct tcf_em_cmp *cmp = (struct tcf_em_cmp *) em->data;
-	unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer) + cmp->off;
+	unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer);
 	u32 val = 0;
 
+	if (!ptr)
+		return 0;
+	ptr += cmp->off;
 	if (!tcf_valid_offset(skb, ptr, cmp->align))
 		return 0;
 
net/sched/em_nbyte.c +2 -0
index 4f9f21a05d5e40aadfdc4c339b8178ad43dc2c8b..c65ffa5fff946edbc30a65ad99087bf664665e32 100644
@@ -42,6 +42,8 @@ static int em_nbyte_match(struct sk_buff *skb, struct tcf_ematch *em,
 	struct nbyte_data *nbyte = (struct nbyte_data *) em->data;
 	unsigned char *ptr = tcf_get_base_ptr(skb, nbyte->hdr.layer);
 
+	if (!ptr)
+		return 0;
 	ptr += nbyte->hdr.off;
 
 	if (!tcf_valid_offset(skb, ptr, nbyte->hdr.len))
net/sched/em_text.c +9 -2
index 6b3d0af72c39c7fb1e3290e24bf94f5bf9e0b358..692e2be1793e9961bcd4516baf54a05341f6ac5d 100644
@@ -29,12 +29,19 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
 			 struct tcf_pkt_info *info)
 {
 	struct text_match *tm = EM_TEXT_PRIV(m);
+	unsigned char *ptr;
 	int from, to;
 
-	from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
+	ptr = tcf_get_base_ptr(skb, tm->from_layer);
+	if (!ptr)
+		return 0;
+	from = ptr - skb->data;
 	from += tm->from_offset;
 
-	to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
+	ptr = tcf_get_base_ptr(skb, tm->to_layer);
+	if (!ptr)
+		return 0;
+	to = ptr - skb->data;
 	to += tm->to_offset;
 
 	return skb_find_text(skb, from, to, tm->config) != UINT_MAX;
Signature · 1 line
2.52.0.460.gd25c4c69ec-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Eric Dumazet

syzbot reported that tcf_get_base_ptr() can be called while transport header is not set [1].

Instead of returning a dangling pointer, return NULL.

Fix tcf_get_base_ptr() callers to handle this NULL value.

[1]

 WARNING: CPU: 1 PID: 6019 at ./include/linux/skbuff.h:3071 skb_transport_header include/linux/skbuff.h:3071 [inline]
 WARNING: CPU: 1 PID: 6019 at ./include/linux/skbuff.h:3071 tcf_get_base_ptr include/net/pkt_cls.h:539 [inline]
 WARNING: CPU: 1 PID: 6019 at ./include/linux/skbuff.h:3071 em_nbyte_match+0x2d8/0x3f0 net/sched/em_nbyte.c:43
Modules linked in:
CPU: 1 UID: 0 PID: 6019 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Call Trace:
 <TASK>
  tcf_em_match net/sched/ematch.c:494 [inline]
  __tcf_em_tree_match+0x1ac/0x770 net/sched/ematch.c:520
  tcf_em_tree_match include/net/pkt_cls.h:512 [inline]
  basic_classify+0x115/0x2d0 net/sched/cls_basic.c:50
  tc_classify include/net/tc_wrapper.h:197 [inline]
  __tcf_classify net/sched/cls_api.c:1764 [inline]
  tcf_classify+0x4cf/0x1140 net/sched/cls_api.c:1860
  multiq_classify net/sched/sch_multiq.c:39 [inline]
  multiq_enqueue+0xfd/0x4c0 net/sched/sch_multiq.c:66
  dev_qdisc_enqueue+0x4e/0x260 net/core/dev.c:4118
  __dev_xmit_skb net/core/dev.c:4214 [inline]
  __dev_queue_xmit+0xe83/0x3b50 net/core/dev.c:4729
  packet_snd net/packet/af_packet.c:3076 [inline]
  packet_sendmsg+0x3e33/0x5080 net/packet/af_packet.c:3108
  sock_sendmsg_nosec net/socket.c:727 [inline]
  __sock_sendmsg+0x21c/0x270 net/socket.c:742
  ____sys_sendmsg+0x505/0x830 net/socket.c:2630
Quoted 4 lines

cheers,
jamal

Quoted 80 lines
---
 include/net/pkt_cls.h |  2 ++
 net/sched/em_cmp.c    |  5 ++++-
 net/sched/em_nbyte.c  |  2 ++
 net/sched/em_text.c   | 11 +++++++++--
 4 files changed, 17 insertions(+), 3 deletions(-)
include/net/pkt_cls.h +2 -0
index c64fd896b1f985c5f6a5b50cbb42ded640d0c9fe..99ac747b7906074c43b3eb8e34cf6c07235cc81d 100644
@@ -536,6 +536,8 @@ static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer)
                case TCF_LAYER_NETWORK:
                        return skb_network_header(skb);
                case TCF_LAYER_TRANSPORT:
+                       if (!skb_transport_header_was_set(skb))
+                               break;
                        return skb_transport_header(skb);
        }
 
net/sched/em_cmp.c +4 -1
index 64b637f18bc7d40509bf5c9f7679cfbc2922af1c..48c1bce74f498d0b4ee3d1efde96459b0dac5896 100644
@@ -22,9 +22,12 @@ static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
                        struct tcf_pkt_info *info)
 {
        struct tcf_em_cmp *cmp = (struct tcf_em_cmp *) em->data;
-       unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer) + cmp->off;
+       unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer);
        u32 val = 0;
 
+       if (!ptr)
+               return 0;
+       ptr += cmp->off;
        if (!tcf_valid_offset(skb, ptr, cmp->align))
                return 0;
 
net/sched/em_nbyte.c +2 -0
index 4f9f21a05d5e40aadfdc4c339b8178ad43dc2c8b..c65ffa5fff946edbc30a65ad99087bf664665e32 100644
@@ -42,6 +42,8 @@ static int em_nbyte_match(struct sk_buff *skb, struct tcf_ematch *em,
        struct nbyte_data *nbyte = (struct nbyte_data *) em->data;
        unsigned char *ptr = tcf_get_base_ptr(skb, nbyte->hdr.layer);
 
+       if (!ptr)
+               return 0;
        ptr += nbyte->hdr.off;
 
        if (!tcf_valid_offset(skb, ptr, nbyte->hdr.len))
net/sched/em_text.c +9 -3
index 6b3d0af72c39c7fb1e3290e24bf94f5bf9e0b358..692e2be1793e9961bcd4516baf54a05341f6ac5d 100644
@@ -29,12 +29,19 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
                         struct tcf_pkt_info *info)
 {
        struct text_match *tm = EM_TEXT_PRIV(m);
+       unsigned char *ptr;
        int from, to;
 
-       from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
+       ptr = tcf_get_base_ptr(skb, tm->from_layer);
+       if (!ptr)
+               return 0;
+       from = ptr - skb->data;
        from += tm->from_offset;
 
-       to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
+       ptr = tcf_get_base_ptr(skb, tm->to_layer);
+       if (!ptr)
+               return 0;
+       to = ptr - skb->data;
        to += tm->to_offset;
 
        return skb_find_text(skb, from, to, tm->config) != UINT_MAX;
--

2.52.0.460.gd25c4c69ec-goog

#2 lore raw
In reply to Eric Dumazet
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 8 lines · On Fri, 21 Nov 2025 15:41:00 +0000 you wrote:

syzbot reported that tcf_get_base_ptr() can be called while transport header is not set [1].

Instead of returning a dangling pointer, return NULL.

Fix tcf_get_base_ptr() callers to handle this NULL value.

[...]

Here is the summary with links:
- [net-next] net: sched: fix TCF_LAYER_TRANSPORT handling in tcf_get_base_ptr()

    https://git.kernel.org/netdev/net/c/4fe5a00ec707

You are awesome, thank you!

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