From: Samuel Moelius <sam.moelius@trailofbits.com>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Samuel Moelius <sam.moelius@trailofbits.com>,
Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org (open list:TC subsystem),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] net/sched: act_csum: skip malformed IPv4 headers
Date: Fri, 5 Jun 2026 15:29:15 +0000 [thread overview]
Message-ID: <20260605152916.2125473-1-sam.moelius@trailofbits.com> (raw)
act_csum trusts the IPv4 IHL field before using it to locate transport
header fields. Packets with an invalid short IHL can make the action
write checksum data into the IPv4 header instead of the intended L4
header.
The action should not repair or modify packets whose IPv4 header length
is invalid. Treat those packets as not eligible for checksum repair and
leave the configured action result unchanged.
Return success without updating checksums when the IPv4 version, IHL, or
total length cannot describe a complete IPv4 header.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
net/sched/act_csum.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index a9e4635d899e..faedf6abd448 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -385,6 +385,8 @@ static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
{
const struct iphdr *iph;
+ unsigned int ihl;
+ unsigned int ipl;
int ntkoff;
ntkoff = skb_network_offset(skb);
@@ -393,41 +395,43 @@ static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
goto fail;
iph = ip_hdr(skb);
+ if (iph->version != 4 || iph->ihl < 5)
+ return 1;
+
+ ihl = iph->ihl * 4;
+ ipl = ntohs(iph->tot_len);
+ if (ipl < ihl)
+ return 1;
switch (iph->frag_off & htons(IP_OFFSET) ? 0 : iph->protocol) {
case IPPROTO_ICMP:
if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
- if (!tcf_csum_ipv4_icmp(skb, iph->ihl * 4,
- ntohs(iph->tot_len)))
+ if (!tcf_csum_ipv4_icmp(skb, ihl, ipl))
goto fail;
break;
case IPPROTO_IGMP:
if (update_flags & TCA_CSUM_UPDATE_FLAG_IGMP)
- if (!tcf_csum_ipv4_igmp(skb, iph->ihl * 4,
- ntohs(iph->tot_len)))
+ if (!tcf_csum_ipv4_igmp(skb, ihl, ipl))
goto fail;
break;
case IPPROTO_TCP:
if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
- if (!tcf_csum_ipv4_tcp(skb, iph->ihl * 4,
- ntohs(iph->tot_len)))
+ if (!tcf_csum_ipv4_tcp(skb, ihl, ipl))
goto fail;
break;
case IPPROTO_UDP:
if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
- if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
- ntohs(iph->tot_len), 0))
+ if (!tcf_csum_ipv4_udp(skb, ihl, ipl, 0))
goto fail;
break;
case IPPROTO_UDPLITE:
if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
- if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
- ntohs(iph->tot_len), 1))
+ if (!tcf_csum_ipv4_udp(skb, ihl, ipl, 1))
goto fail;
break;
case IPPROTO_SCTP:
if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
- !tcf_csum_sctp(skb, iph->ihl * 4, ntohs(iph->tot_len)))
+ !tcf_csum_sctp(skb, ihl, ipl))
goto fail;
break;
}
--
2.43.0
next reply other threads:[~2026-06-05 15:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 15:29 Samuel Moelius [this message]
2026-06-10 15:09 ` [PATCH] net/sched: act_csum: skip malformed IPv4 headers Jakub Kicinski
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=20260605152916.2125473-1-sam.moelius@trailofbits.com \
--to=sam.moelius@trailofbits.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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