Skip to contentSkip to conversation

netfilter: ip6_tables: set F_PROTO when proto value is nonzero

PATCH New Florian Westphal 1 participant 1 message Aug 25

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: ip6_tables: set F_PROTO when proto value is nonzero

The ip6tables traverser doesn't search the extension header chain unless userspace did set the IP6T_F_PROTO flag.

This also means that userspace that sets the e->ipv6.proto flag can bypass the protocol check for the rule by not setting this flag.

That in turn means that all ip6_tables modules and targets that want to reject rules without '-p' flag MUST also check for that flag.

Not all do, likely because they got copied from iptables which lacks this flag (no extension headers).

Instead of fixing up all the relevant targets, emulate ip6tables behaviour in the kernel (like nft_compat.c) and set the flag if the protocol is set.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/ipv6/netfilter/ip6_tables.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ipv6/netfilter/ip6_tables.c +5 -0
index f42fb96ef64b..313c4aac377a 100644
@@ -647,6 +647,11 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
 	/* Clear counters and comefrom */
 	e->counters = ((struct xt_counters) { 0, 0 });
 	e->comefrom = 0;
+
+	/* set F_PROTO, else ip6_packet_match won't do the right thing. */
+	if (e->ipv6.proto)
+		e->ipv6.flags |= IP6T_F_PROTO;
+
 	return 0;
 }
 
Signature · 1 line
2.54.0