net/sched: act_pedit: require matching IPv4 L4 protocol
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 1/2 net/sched: act_pedit: require matching IPv4 L4 protocol
The extended IPv4 L4 header mode in act_pedit can select TCP or UDP header fields without confirming that the IPv4 protocol field matches the selected transport header.
That lets a rule written for TCP or UDP modify unrelated payload bytes in a packet carrying a different protocol.
Verify that the IPv4 header is long enough, that the protocol matches the selected TCP or UDP header, and that the packet is not a non-initial fragment before applying TCP or UDP extended header edits.
---
Changes in v2:
- Add check of iph->frag_off & htons(IP_OFFSET)
net/sched/act_pedit.c | 4 ++++ 1 file changed, 4 insertions(+)
net/sched/act_pedit.c +4 -0
@@ -18,6 +18,7 @@#include <linux/slab.h> #include <linux/overflow.h> #include <linux/unaligned.h> +#include <net/ip.h> #include <net/ipv6.h> #include <net/netlink.h> #include <net/pkt_sched.h>
@@ -331,6 +332,9 @@ static int pedit_l4_skb_offset(struct sk_buff *skb, int *hoffset, const int headif (!iph) goto out; +if (iph->ihl <5 || iph->protocol != header_type || + (iph->frag_off &htons (IP_OFFSET ))) + goto out; *hoffset = noff + iph->ihl *4 ; ret =0 ;break ;
Signature · 1 line
2.43.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Tue, 9 Jun 2026 18:56:34 +0000 you wrote:
The extended IPv4 L4 header mode in
act_peditcan select TCP or UDP header fields without confirming that the IPv4 protocol field matches the selected transport header.That lets a rule written for TCP or UDP modify unrelated payload bytes in a packet carrying a different protocol.
[...]
Here is the summary with links:
- [net,v3,1/2] net/sched: act_pedit: require matching IPv4 L4 protocol
https://git.kernel.org/netdev/net-next/c/d504a9785722 - [net,v3,2/2] net/sched: act_pedit: require matching IPv4 L4 protocol https://git.kernel.org/netdev/net-next/c/f7d109f176f2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
PATCH v3 2/2 net/sched: act_pedit: require matching IPv4 L4 protocol
In reply to a message not in the archiveFrom: Victor Nogueira <[email protected]>
Add a tdc test that checks the act_pedit extended L4 header mode does not edit a packet whose IPv4 protocol does not match the selected transport header.
The test installs an ingress pedit rule that sets the UDP destination port, then injects a TCP packet with dport 2222. The UDP and TCP destination ports sit at the same L4 offset, so a buggy kernel rewrites the TCP dport. A second flower filter matches TCP dport 2222 and drops the packet through an indexed gact action; the test then verifies via JSON that this action saw exactly one packet, i.e. the dport was left untouched and still matched 2222.
---
Changes in v3:
- Add test
.../tc-testing/tc-tests/actions/pedit.json | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/actions/pedit.json +49 -0
@@ -1920,5 +1920,54 @@ "teardown": [ "$TC actions flush action pedit" ] + }, + { + "id": "1a4f", + "name": "Pedit udp dport should not mangle TCP packet dport", + "category": [ + "actions", + "pedit" + ], + "plugins": { + "requires": [ + "nsPlugin", + "scapyPlugin" + ] + }, + "setup": [ + "$TC qdisc add dev $DEV1 clsact", + "$TC filter add dev $DEV1 ingress protocol ip pref 1 matchall action pedit ex munge udp dport set 18053 continue" + ], + "cmdUnderTest": "$TC filter add dev $DEV1 ingress protocol ip pref 2 flower ip_proto tcp dst_port 2222 action drop index 1", + "scapy": { + "iface": "$DEV0", + "count": 1, + "packet": "Ether()/IP(dst='10.10.10.1')/TCP(dport=2222)" + }, + "expExitCode": "0", + "verifyCmd": "$TC -j -s actions get action gact index 1", + "matchJSON": [ + { + "total acts": 0 + }, + { + "actions": [ + { + "order": 1, + "kind": "gact", + "control_action": { + "type": "drop" + }, + "index": 1, + "stats": { + "packets": 1 + } + } + ] + } + ], + "teardown": [ + "$TC qdisc del dev $DEV1 clsact" + ] } ]
Signature · 1 line
2.54.0