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_nat: only rewrite IPv4 packets
Date: Wed, 3 Jun 2026 18:04:06 +0000 [thread overview]
Message-ID: <20260603180407.26100-1-sam.moelius@trailofbits.com> (raw)
act_nat can process packets whose protocol is not IPv4 and then
interpret the payload as an IPv4 header. Non-IPv4 packets may be
modified based on unrelated bytes at the network header offset.
The action is documented as IPv4 NAT and should leave other protocols
alone.
Check the packet protocol before parsing and rewriting the IPv4 header.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
net/sched/act_nat.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c
index abb332dee836..34d6ba2d4143 100644
--- a/net/sched/act_nat.c
+++ b/net/sched/act_nat.c
@@ -142,6 +142,9 @@ TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb,
egress = parms->flags & TCA_NAT_FLAG_EGRESS;
noff = skb_network_offset(skb);
+ if (skb_protocol(skb, true) != htons(ETH_P_IP))
+ goto out;
+
if (!pskb_may_pull(skb, sizeof(*iph) + noff))
goto drop;
--
2.43.0
reply other threads:[~2026-06-03 18:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260603180407.26100-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