Skip to content

Commit 42e344f

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Fix for deleting base chains with payload
When deleting a base chain, iptables-nft simply submits the whole chain to the kernel, including the NFTA_CHAIN_HOOK attribute. The new code added by fixed commit then turned this into a chain update, destroying the hook but not the chain itself. Detect the situation by checking if the chain type is either netdev or inet/ingress. Fixes: 7d937b1 ("netfilter: nf_tables: support for deleting devices in an existing netdev chain") Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 62f9a68 commit 42e344f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,21 +2811,18 @@ static int nf_tables_newchain(struct sk_buff *skb, const struct nfnl_info *info,
28112811
return nf_tables_addchain(&ctx, family, genmask, policy, flags, extack);
28122812
}
28132813

2814-
static int nft_delchain_hook(struct nft_ctx *ctx, struct nft_chain *chain,
2814+
static int nft_delchain_hook(struct nft_ctx *ctx,
2815+
struct nft_base_chain *basechain,
28152816
struct netlink_ext_ack *extack)
28162817
{
2818+
const struct nft_chain *chain = &basechain->chain;
28172819
const struct nlattr * const *nla = ctx->nla;
28182820
struct nft_chain_hook chain_hook = {};
2819-
struct nft_base_chain *basechain;
28202821
struct nft_hook *this, *hook;
28212822
LIST_HEAD(chain_del_list);
28222823
struct nft_trans *trans;
28232824
int err;
28242825

2825-
if (!nft_is_base_chain(chain))
2826-
return -EOPNOTSUPP;
2827-
2828-
basechain = nft_base_chain(chain);
28292826
err = nft_chain_parse_hook(ctx->net, basechain, nla, &chain_hook,
28302827
ctx->family, chain->flags, extack);
28312828
if (err < 0)
@@ -2910,7 +2907,12 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,
29102907
if (chain->flags & NFT_CHAIN_HW_OFFLOAD)
29112908
return -EOPNOTSUPP;
29122909

2913-
return nft_delchain_hook(&ctx, chain, extack);
2910+
if (nft_is_base_chain(chain)) {
2911+
struct nft_base_chain *basechain = nft_base_chain(chain);
2912+
2913+
if (nft_base_chain_netdev(table->family, basechain->ops.hooknum))
2914+
return nft_delchain_hook(&ctx, basechain, extack);
2915+
}
29142916
}
29152917

29162918
if (info->nlh->nlmsg_flags & NLM_F_NONREC &&

0 commit comments

Comments
 (0)