net/sched: act_nat: only rewrite IPv4 packets
Subsystems (3)
PATCH 1/1 net/sched: act_nat: only rewrite IPv4 packets
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.
--- net/sched/act_nat.c | 3 +++ 1 file changed, 3 insertions(+)
net/sched/act_nat.c +3 -0
@@ -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;
Signature · 1 line
2.43.0
Simon Horman
reviewerFrom: 'Simon Horman' <[email protected]>
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
net/sched: act_nat: only rewrite IPv4 packets
This commit modifies act_nat to check the packet protocol before parsing and rewriting the IPv4 header. This prevents the action from modifying non-IPv4 packets based on unrelated bytes at the network header offset.
net/sched/act_nat.c TC_INDIRECT_SCOPE int tcf_nat_act(struct sk_buff *skb, · line 147
Quoted 11 lines
net/sched/act_nat.c +3
-0@@ -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; +
[Severity: High]
Does this code parse inline VLAN headers as IPv4 headers?
By explicitly passing true for skip_vlan to skb_protocol(), the check looks past inline VLAN tags to evaluate the encapsulated inner protocol. If the inner protocol is IPv4, the check passes, but noff and skb_network_header(skb) are not advanced past the VLAN tags.
When the action later proceeds to call iph = ip_hdr(skb) at line 151 and rewrites the IP addresses, won't it silently corrupt the VLAN tag and adjacent packet bytes instead of the actual IPv4 header?
Quoted 3 lines
net/sched/act_nat.c +0
-0if (!pskb_may_pull (skb,sizeof (*iph) + noff)) goto drop;