Skip to contentSkip to conversation

netfilter: xt_connmark: reject invalid shift parameters

PATCH In review Ren Wei 2 participants 2 messages Jul 3 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Ren Wei

author
#1 lore raw

PATCH 1/1 netfilter: xt_connmark: reject invalid shift parameters

In reply to a message not in the archive

From: Wyatt Feng <[email protected]>

Revision 2 of the CONNMARK target accepts user-controlled shift parameters and applies them to 32-bit mark values in connmark_tg_shift().

A shift_bits value of 32 or more triggers an undefined-shift bug when the rule is evaluated. Invalid shift_dir values are also accepted and silently fall back to the left-shift path.

Reject invalid revision-2 shift parameters in connmark_tg_check() so malformed rules fail at installation time, before they can reach the packet path.

Fixes 472a73e00757 ("netfilter: xt_conntrack: Support bit-shifting for CONNMARK & MARK targets.")
Assisted-by Codex:GPT-5.4
---
 net/netfilter/xt_connmark.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/netfilter/xt_connmark.c +6 -0
index 4277084de2e7..b7fdc3e9d423 100644
@@ -103,8 +103,14 @@ connmark_tg_v2(struct sk_buff *skb, const struct xt_action_param *par)
 
 static int connmark_tg_check(const struct xt_tgchk_param *par)
 {
+	const struct xt_connmark_tginfo2 *info = par->targinfo;
 	int ret;
 
+	if (par->target->revision == 2) {
+		if (info->shift_dir > D_SHIFT_RIGHT || info->shift_bits >= 32)
+			return -EINVAL;
+	}
+
 	ret = nf_ct_netns_get(par->net, par->family);
 	if (ret < 0)
 		pr_info_ratelimited("cannot load conntrack support for proto=%u\n",
Signature · 1 line
2.47.3
reviewer Reviewed-by on v1 1/1
#2 lore raw
Quoted 14 lines · Ren Wei

From: Wyatt Feng <[email protected]>

Revision 2 of the CONNMARK target accepts user-controlled shift parameters and applies them to 32-bit mark values in connmark_tg_shift().

A shift_bits value of 32 or more triggers an undefined-shift bug when the rule is evaluated. Invalid shift_dir values are also accepted and silently fall back to the left-shift path.

Reject invalid revision-2 shift parameters in connmark_tg_check() so malformed rules fail at installation time, before they can reach the packet path.

Quoted 8 lines
Fixes 472a73e00757 ("netfilter: xt_conntrack: Support bit-shifting for CONNMARK & MARK targets.")
Assisted-by Codex:GPT-5.4