Skip to contentSkip to conversation

net: check qdisc_pkt_len_segs_init() return value on ingress

PATCH Superseded David Carlier 2 participants 2 messages Apr 8 – Apr 12

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: check qdisc_pkt_len_segs_init() return value on ingress

Commit 7fb4c1967011 ("net: pull headers in qdisc_pkt_len_segs_init()") changed qdisc_pkt_len_segs_init() to return an skb drop reason when it detects malicious GSO packets. The egress path in __dev_queue_xmit() checks this return value and drops bad packets, but the ingress path in sch_handle_ingress() ignores it.

This means malformed GSO packets entering via TC ingress are not dropped and could be redirected to another interface or cause incorrect qdisc accounting.

Check the return value and drop the packet when a bad GSO is detected.

Fixes 7fb4c1967011 ("net: pull headers in qdisc_pkt_len_segs_init()")
---
 net/core/dev.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/core/dev.c +10 -2
index 5a31f9d2128c..2b5f508fc479 100644
@@ -4459,7 +4459,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
 		   struct net_device *orig_dev, bool *another)
 {
 	struct bpf_mprog_entry *entry = rcu_dereference_bh(skb->dev->tcx_ingress);
-	enum skb_drop_reason drop_reason = SKB_DROP_REASON_TC_INGRESS;
+	enum skb_drop_reason drop_reason;
 	struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
 	int sch_ret;
 
@@ -4472,7 +4472,15 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
 		*pt_prev = NULL;
 	}
 
-	qdisc_pkt_len_segs_init(skb);
+	drop_reason = qdisc_pkt_len_segs_init(skb);
+	if (unlikely(drop_reason)) {
+		kfree_skb_reason(skb, drop_reason);
+		*ret = NET_RX_DROP;
+		bpf_net_ctx_clear(bpf_net_ctx);
+		return NULL;
+	}
+
+	drop_reason = SKB_DROP_REASON_TC_INGRESS;
 	tcx_set_ingress(skb, true);
 
 	if (static_branch_unlikely(&tcx_needed_key)) {
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 6 lines · On Wed, 8 Apr 2026 18:23:07 +0100 David Carlier wrote:

Commit 7fb4c1967011 ("net: pull headers in qdisc_pkt_len_segs_init()") changed qdisc_pkt_len_segs_init() to return an skb drop reason when it detects malicious GSO packets. The egress path in __dev_queue_xmit() checks this return value and drops bad packets, but the ingress path in sch_handle_ingress() ignores it.

Quoted 8 lines

This means malformed GSO packets entering via TC ingress are not dropped and could be redirected to another interface or cause incorrect qdisc accounting.

Check the return value and drop the packet when a bad GSO is detected.

Fixes 7fb4c1967011 ("net: pull headers in qdisc_pkt_len_segs_init()")

Not sure this can happen today, but okay.
Hopefully we won't get a patch for every Sashiko report we knowingly ignored :|

net/core/dev.c sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, · line 4462

Quoted 10 lines
net/core/dev.c +1 -1
index 5a31f9d2128c..2b5f508fc479 100644
@@ -4459,7 +4459,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
 		   struct net_device *orig_dev, bool *another)
 {
 	struct bpf_mprog_entry *entry = rcu_dereference_bh(skb->dev->tcx_ingress);
-	enum skb_drop_reason drop_reason = SKB_DROP_REASON_TC_INGRESS;
+	enum skb_drop_reason drop_reason;

this needs to move one line down now to keep the variable ordering.

Quoted 20 lines
net/core/dev.c +9 -1
 	struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
 	int sch_ret;
 
@@ -4472,7 +4472,15 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
 		*pt_prev = NULL;
 	}
 
-	qdisc_pkt_len_segs_init(skb);
+	drop_reason = qdisc_pkt_len_segs_init(skb);
+	if (unlikely(drop_reason)) {
+		kfree_skb_reason(skb, drop_reason);
+		*ret = NET_RX_DROP;
+		bpf_net_ctx_clear(bpf_net_ctx);
+		return NULL;
+	}
+
+	drop_reason = SKB_DROP_REASON_TC_INGRESS;
 	tcx_set_ingress(skb, true);
 
 	if (static_branch_unlikely(&tcx_needed_key)) {
Signature · 1 line
pw-bot: cr