Skip to contentSkip to conversation

netfilter: xt_policy: fix strict mode inbound policy matching

PATCH In review Ren Wei 2 participants 2 messages Apr 17 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

PATCH 1/1 netfilter: xt_policy: fix strict mode inbound policy matching

From: Jiexun Wang <[email protected]>

match_policy_in() walks sec_path entries from the last transform to the first one, but strict policy matching needs to consume info->pol[] in the same forward order as the rule layout.

Derive the strict-match policy position from the number of transforms already consumed so that multi-element inbound rules are matched consistently.

Fixes df008c91f835 ("net: Allow userns root to control llc, netfilter, netlink, packet, and xfrm")
---
 net/netfilter/xt_policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_policy.c +1 -1
index cb6e8279010a..b5fa65558318 100644
@@ -63,7 +63,7 @@ match_policy_in(const struct sk_buff *skb, const struct xt_policy_info *info,
 		return 0;
 
 	for (i = sp->len - 1; i >= 0; i--) {
-		pos = strict ? i - sp->len + 1 : 0;
+		pos = strict ? sp->len - i - 1 : 0;
 		if (pos >= info->len)
 			return 0;
 		e = &info->pol[pos];
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#2 lore raw
Quoted 9 lines · Ren Wei

From: Jiexun Wang <[email protected]>

match_policy_in() walks sec_path entries from the last transform to the first one, but strict policy matching needs to consume info->pol[] in the same forward order as the rule layout.

Derive the strict-match policy position from the number of transforms already consumed so that multi-element inbound rules are matched consistently.

That hints that secpaths with len > 1 do not exist, or at least have never been used. This has always been broken.

For the patch