Skip to contentSkip to conversation

netfilter: nft_dup: validate family and chains

PATCH Superseded Pablo Neira Ayuso 1 participant 3 messages Aug 21, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)
net/netfilter/nft_dup_netdev.c +12 -0
index 63507402716d..6c8cb7a04264 100644
@@ -44,6 +44,17 @@ 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)
+{
+	if (ctx->family != NFPROTO_NETDEV)
+		return -EOPNOTSUPP;
+
+	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 +90,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 1/1 netfilter: nft_fwd: really validate family

This only supports for the netdev family, report EOPNOTSUPP otherwise.

Fixes 76a109fac206 ("netfilter: nft_fwd_netdev: validate family and chain type")
---
 net/netfilter/nft_fwd_netdev.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nft_fwd_netdev.c +3 -0
index 7c5876dc9ff2..138313123da6 100644
@@ -205,6 +205,9 @@ static int nft_fwd_validate(const struct nft_ctx *ctx,
 			    const struct nft_expr *expr,
 			    const struct nft_data **data)
 {
+	if (ctx->family != NFPROTO_NETDEV)
+		return -EOPNOTSUPP;
+
 	return nft_chain_validate_hooks(ctx->chain, (1 << NF_NETDEV_INGRESS) |
 						    (1 << NF_NETDEV_EGRESS));
 }
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

Re: [PATCH nf] netfilter: nft_fwd: really validate family

Quoted 1 line · Pablo Neira Ayuso

This only supports for the netdev family, report EOPNOTSUPP otherwise.

Scratch this, this is already validated via .family field in expression type.