[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251119224140.8616-8-david.laight.linux@gmail.com>
Date: Wed, 19 Nov 2025 22:41:03 +0000
From: david.laight.linux@...il.com
To: linux-kernel@...r.kernel.org,
netdev@...r.kernel.org
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
David Laight <david.laight.linux@...il.com>
Subject: [PATCH 07/44] net/core/flow_dissector: Fix cap of __skb_flow_dissect() return value.
From: David Laight <david.laight.linux@...il.com>
There are some dodgy clamp_t(u16, ...) and min_t(u16, ...).
__skb_flow_dissect() tries to cap its return value with:
key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
however this casts skb->len to u16 before the comparison.
While both nboff and hlen are 'small', skb->len could be 0x10001 which
gets converted to 1 by the cast.
This gives an invalid (small) value for thoff for valid packets.
bpf_flow_dissect() used clamp_t(u16, ...) to set both flow_keys->nhoff
and flow_keys->thoff.
While I think these can't lose significant bits the casts are unnecessary
plain clamp(...) works fine.
Fixes: d0c081b49137c ("flow_dissector: properly cap thoff field")
Signed-off-by: David Laight <david.laight.linux@...il.com>
---
net/core/flow_dissector.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 1b61bb25ba0e..e362160bb73d 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -1023,9 +1023,8 @@ u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
result = bpf_prog_run_pin_on_cpu(prog, ctx);
- flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen);
- flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
- flow_keys->nhoff, hlen);
+ flow_keys->nhoff = clamp(flow_keys->nhoff, nhoff, hlen);
+ flow_keys->thoff = clamp(flow_keys->thoff, flow_keys->nhoff, hlen);
return result;
}
@@ -1687,7 +1686,7 @@ bool __skb_flow_dissect(const struct net *net,
ret = true;
out:
- key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
+ key_control->thoff = umin(nhoff, skb ? skb->len : hlen);
key_basic->n_proto = proto;
key_basic->ip_proto = ip_proto;
--
2.39.5
Powered by blists - more mailing lists