Skip to contentSkip to conversation

netfilter: ip6t_ah: validate AH header length

PATCH In review Zhixing Chen 2 participants 3 messages Jun 18 – Jun 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ip6t_ah: validate AH header length

ip6t_ah checks that the fixed AH header is present, then uses hdrlen to derive the advertised AH header length for matching.

Return false if the skb does not contain the advertised AH header length. This avoids matching AH headers whose advertised length is not present in the skb.

---

I noticed ip6t_hbh and ip6t_rt already do this advertised-length check for their IPv6 extension headers, so this keeps ip6t_ah in line with those matches.

---
 net/ipv6/netfilter/ip6t_ah.c | 4 ++++
 1 file changed, 4 insertions(+)
net/ipv6/netfilter/ip6t_ah.c +4 -0
index 70da2f2ce064..a40240125a1b 100644
@@ -56,6 +56,10 @@ static bool ah_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 	}
 
 	hdrlen = ipv6_authlen(ah);
+	if (skb->len - ptr < hdrlen) {
+		/* Packet smaller than its length field */
+		return false;
+	}
 
 	pr_debug("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
 	pr_debug("RES %04X ", ah->reserved);
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 7 lines · Zhixing Chen

ip6t_ah checks that the fixed AH header is present, then uses hdrlen to derive the advertised AH header length for matching.

Return false if the skb does not contain the advertised AH header length. This avoids matching AH headers whose advertised length is not present in the skb.

Quoted 6 lines

---

I noticed ip6t_hbh and ip6t_rt already do this advertised-length check for their IPv6 extension headers, so this keeps ip6t_ah in line with those matches.

Could you make a v2 that addresses

https://sashiko.dev/#/patchset/20260618125848.93550-1-running910%40gmail.com
?

We should not return false in matches for malformed packets without also setting ->hotdrop = true.

#2 lore raw
Quoted 2 lines

We should not return false in matches for malformed packets without also setting ->hotdrop = true.

Thanks a lot for taking a careful look, I really appreciate it.

I agree. Returning false makes the packet a rule mismatch, while this condition means the packet is malformed. I will send a v2 that sets ->hotdrop before returning false in ah, and applies the same malformed-header handling to hbh and rt as well.