]> git.ipfire.org Git - thirdparty/iptables.git/commit
nft: Fix for zeroing non-existent builtin chains
authorPhil Sutter <phil@nwl.cc>
Tue, 16 Jul 2024 19:07:31 +0000 (21:07 +0200)
committerPhil Sutter <phil@nwl.cc>
Sat, 27 Jul 2024 12:32:39 +0000 (14:32 +0200)
commitf462975fb8049b9b565cb35cc98302331dbd1548
tree93af82044c21470c392addcde58694900af827ca
parent73ac92c769c5f27ac59266ad94031ab6d54af80b
nft: Fix for zeroing non-existent builtin chains

Trying to zero a specific rule in an entirely empty ruleset caused an
error:

| # nft flush ruleset
| # iptables-nft -Z INPUT
| iptables v1.8.10 (nf_tables):  CHAIN_ZERO failed (No such file or directory): chain INPUT

To fix this, start by faking any non-existing builtin chains so verbose
mode prints all the would-be-flushed chains. Later set 'skip' flag if
given chain is a fake one (indicated by missing HANDLE attribute).
Finally cover for concurrent ruleset updates by checking whether the
chain exists.

This bug seems to exist for a long time already, Fixes tag identified
via git-bisect. This patch won't apply to such old trees though, but
calling nft_xt_builtin_init() from nft_chain_zero_counters() should work
there.

Fixes: a6ce0c65d3a39 ("xtables: Optimize nft_chain_zero_counters()")
Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft.c
iptables/tests/shell/testcases/nft-only/0013-zero-non-existent_0 [new file with mode: 0755]