Skip to contentSkip to conversation

netfilter: nf_tables: don't fail when updating base chain policy

PATCH Applied Florian Westphal 2 participants 2 messages Jul 13, 2019 – Jul 16, 2019

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: don't fail when updating base chain policy

The following nftables test case fails on nf-next:

tests/shell/run-tests.sh tests/shell/testcases/transactions/0011chain_0

The test case contains:
add chain x y { type filter hook input priority 0; } add chain x y { policy drop; }"

The new test
if (chain->flags ^ flags)

	return -EOPNOTSUPP;

triggers here, because chain->flags has NFT_BASE_CHAIN set, but flags is 0 because no flag attribute was present in the policy update.

Just fetch the current flag settings of a pre-existing chain in case userspace did not provide any.

Fixes c9626a2cbdb20 ("netfilter: nf_tables: add hardware offload support")
---
 net/netfilter/nf_tables_api.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_tables_api.c +2 -0
index add64bd227a8..5746a7c948fe 100644
@@ -1914,6 +1914,8 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
 
 	if (nla[NFTA_CHAIN_FLAGS])
 		flags = ntohl(nla_get_be32(nla[NFTA_CHAIN_FLAGS]));
+	else if (chain)
+		flags = chain->flags;
 
 	nft_ctx_init(&ctx, net, skb, nlh, family, table, chain, nla);
 
Signature · 1 line
2.21.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Florian Westphal

The following nftables test case fails on nf-next:

tests/shell/run-tests.sh tests/shell/testcases/transactions/0011chain_0

The test case contains:
add chain x y { type filter hook input priority 0; } add chain x y { policy drop; }"

The new test
if (chain->flags ^ flags)

Quoted 7 lines
	return -EOPNOTSUPP;

triggers here, because chain->flags has NFT_BASE_CHAIN set, but flags is 0 because no flag attribute was present in the policy update.

Just fetch the current flag settings of a pre-existing chain in case userspace did not provide any.

Applied, thanks for fixing up this, this is my fault.