Skip to contentSkip to conversation

netfilter: nft_dup: validate family and chains

PATCH In review Pablo Neira Ayuso 1 participant 4 messages Aug 21, 2022

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/3 netfilter: nft_dup: validate family and chains

This only supports for netdev family and ingress and egress hooks.

Fixes 502061f81d3e ("netfilter: nf_tables: add packet duplication to the netdev family")
---
 net/netfilter/nft_dup_netdev.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/netfilter/nft_dup_netdev.c +9 -0
index 63507402716d..1d5bbe8d2660 100644
@@ -44,6 +44,14 @@ static int nft_dup_netdev_init(const struct nft_ctx *ctx,
 				       sizeof(int));
 }
 
+static int nft_dup_netdev_validate(const struct nft_ctx *ctx,
+				   const struct nft_expr *expr,
+				   const struct nft_data **data)
+{
+	return nft_chain_validate_hooks(ctx->chain, (1 << NF_NETDEV_INGRESS) |
+						    (1 << NF_NETDEV_EGRESS));
+}
+
 static int nft_dup_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)
 {
 	struct nft_dup_netdev *priv = nft_expr_priv(expr);
@@ -79,6 +87,7 @@ static const struct nft_expr_ops nft_dup_netdev_ops = {
 	.eval		= nft_dup_netdev_eval,
 	.init		= nft_dup_netdev_init,
 	.dump		= nft_dup_netdev_dump,
+	.validate	= nft_dup_netdev_validate,
 	.reduce		= NFT_REDUCE_READONLY,
 	.offload	= nft_dup_netdev_offload,
 	.offload_action	= nft_dup_netdev_offload_action,
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/3 netfilter: nft_osf: restrict osf to ipv4, ipv6 and inet families

As it was originally intended, restrict extension to supported families.

Fixes b96af92d6eaf ("netfilter: nf_tables: implement Passive OS fingerprint module in nft_osf")
---
 net/netfilter/nft_osf.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
net/netfilter/nft_osf.c +15 -3
index 0053a697c931..89342ccccdcc 100644
@@ -115,9 +115,21 @@ static int nft_osf_validate(const struct nft_ctx *ctx,
 			    const struct nft_expr *expr,
 			    const struct nft_data **data)
 {
-	return nft_chain_validate_hooks(ctx->chain, (1 << NF_INET_LOCAL_IN) |
-						    (1 << NF_INET_PRE_ROUTING) |
-						    (1 << NF_INET_FORWARD));
+	unsigned int hooks;
+
+	switch (ctx->family) {
+	case NFPROTO_IPV4:
+	case NFPROTO_IPV6:
+	case NFPROTO_INET:
+		hooks = (1 << NF_INET_LOCAL_IN) |
+			(1 << NF_INET_PRE_ROUTING) |
+			(1 << NF_INET_FORWARD);
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return nft_chain_validate_hooks(ctx->chain, hooks);
 }
 
 static bool nft_osf_reduce(struct nft_regs_track *track,
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH 3/3 netfilter: nft_tunnel: restrict it to netdev family

In reply to Pablo Neira Ayuso

Only allow to use this expression from NFPROTO_NETDEV family.

Fixes af308b94a2a4 ("netfilter: nf_tables: add tunnel support")
---
 net/netfilter/nft_tunnel.c | 1 +
 1 file changed, 1 insertion(+)
net/netfilter/nft_tunnel.c +1 -0
index 5edaaded706d..983ade4be3b3 100644
@@ -161,6 +161,7 @@ static const struct nft_expr_ops nft_tunnel_get_ops = {
 
 static struct nft_expr_type nft_tunnel_type __read_mostly = {
 	.name		= "tunnel",
+	.family		= NFPROTO_NETDEV,
 	.ops		= &nft_tunnel_get_ops,
 	.policy		= nft_tunnel_policy,
 	.maxattr	= NFTA_TUNNEL_MAX,
Signature · 1 line
2.30.2
author maintainer
#3 lore raw
In reply to Pablo Neira Ayuso
Quoted 1 line · Pablo Neira Ayuso

This only supports for netdev family and ingress and egress hooks.

Not really required since this is already restricted to NFPROTO_NETDEV, withdraw.