Skip to contentSkip to conversation

netfilter: nftables: accept all dummy chain when table is dormant

PATCH Superseded Pablo Neira Ayuso 2 participants 6 messages May 18, 2021 – May 19, 2021

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: nftables: accept all dummy chain when table is dormant

The dormant flag need to be updated from the preparation phase, otherwise, two consecutive requests to dorm a table in the same batch might try to remove the same hooks twice, resulting in the following warning:

hook not found, pf 3 num 0

 WARNING: CPU: 0 PID: 334 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
 Modules linked in:
 CPU: 0 PID: 334 Comm: kworker/u4:5 Not tainted 5.12.0-syzkaller #0
 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
 Workqueue: netns cleanup_net
 RIP: 0010:__nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480

This patch is a partial revert of 0ce7cf4127f1 ("netfilter: nftables:
update table flags from the commit phase") to restore the previous behaviour, which updates the dormant flag from the preparation phase to address this issue.

However, there is still another problem: A batch containing a series of dorm-wakeup-dorm table and vice-versa also trigger the warning above since hook unregistration happens from the preparation phase, while hook registration occurs from the commit phase.

To fix this problem, this patch adds a dummy accept-all-rule that is used in case the table enters dormant state. This patch removes nf_tables_table_enable() and nf_tables_table_disable() since chain hooks are always registered, therefore, they are not needed anymore.

The new __NFT_TABLE_F_UPDATE internal flag is used to signal the commit phase that the dormant flag has been updated.

Reported-by [email protected]
Fixes 0ce7cf4127f1 ("netfilter: nftables: update table flags from the commit phase")
Fixes 9ddf63235749 ("netfilter: nf_tables: add support for dormant tables")
---
 include/net/netfilter/nf_tables.h |   3 -
 net/netfilter/nf_tables_api.c     | 147 +++++++++++++++---------------
 2 files changed, 74 insertions(+), 76 deletions(-)
include/net/netfilter/nf_tables.h +0 -3
index 27eeb613bb4e..8ad2839c4dd2 100644
@@ -1507,15 +1507,12 @@ struct nft_trans_chain {
 struct nft_trans_table {
 	bool				update;
 	u8				state;
-	u32				flags;
 };
 
 #define nft_trans_table_update(trans)	\
 	(((struct nft_trans_table *)trans->data)->update)
 #define nft_trans_table_state(trans)	\
 	(((struct nft_trans_table *)trans->data)->state)
-#define nft_trans_table_flags(trans)	\
-	(((struct nft_trans_table *)trans->data)->flags)
 
 struct nft_trans_elem {
 	struct nft_set			*set;
net/netfilter/nf_tables_api.c +74 -73

257 lines not on this page · raw message

Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 5 lines · Pablo Neira Ayuso

The dormant flag need to be updated from the preparation phase, otherwise, two consecutive requests to dorm a table in the same batch might try to remove the same hooks twice, resulting in the following warning:

Quoted 7 lines

hook not found, pf 3 num 0

 WARNING: CPU: 0 PID: 334 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
 Modules linked in:
 CPU: 0 PID: 334 Comm: kworker/u4:5 Not tainted 5.12.0-syzkaller #0
 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
 Workqueue: netns cleanup_net
 RIP: 0010:__nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480

Would it be possible to reject such a batch instead of having to add rely on dummy hooking instead?

I don't think we should try to be clever with nonsensical yes-no-yes-yes-no type commits.

author maintainer
#2 lore raw
Quoted 14 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso

The dormant flag need to be updated from the preparation phase, otherwise, two consecutive requests to dorm a table in the same batch might try to remove the same hooks twice, resulting in the following warning:

Quoted 7 lines

hook not found, pf 3 num 0

 WARNING: CPU: 0 PID: 334 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
 Modules linked in:
 CPU: 0 PID: 334 Comm: kworker/u4:5 Not tainted 5.12.0-syzkaller #0
 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
 Workqueue: netns cleanup_net
 RIP: 0010:__nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
Quoted 2 lines

Would it be possible to reject such a batch instead of having to add rely on dummy hooking instead?

That's a simple way to fix it, yes, ie. hit EBUSY.

Quoted 2 lines

I don't think we should try to be clever with nonsensical yes-no-yes-yes-no type commits.

Note that no such EBUSY limitation exists so far in the transaction semantics that I know [*]. We already discussed that robots might do non-sensical stuff when creating a batches, and reporting EBUSY for this add-del-add case might just break them.

This also removes the conditional hook registration, so hooks are registered once at chain creation. This simplifies interaction with the netfilter core at the cost of adding complexity to nf_tables_commit_chain_prepare() path.

[*] Well, you might still hit EBUSY from a batch, but that happens if the object is really in use, not because of the add-del-add sequence.

maintainer
#3 lore raw
Quoted 20 lines · Pablo Neira Ayuso
Quoted 14 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso

The dormant flag need to be updated from the preparation phase, otherwise, two consecutive requests to dorm a table in the same batch might try to remove the same hooks twice, resulting in the following warning:

Quoted 7 lines

hook not found, pf 3 num 0

 WARNING: CPU: 0 PID: 334 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
 Modules linked in:
 CPU: 0 PID: 334 Comm: kworker/u4:5 Not tainted 5.12.0-syzkaller #0
 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
 Workqueue: netns cleanup_net
 RIP: 0010:__nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
Quoted 2 lines

Would it be possible to reject such a batch instead of having to add rely on dummy hooking instead?

That's a simple way to fix it, yes, ie. hit EBUSY.

Quoted 7 lines
Quoted 2 lines

I don't think we should try to be clever with nonsensical yes-no-yes-yes-no type commits.

Note that no such EBUSY limitation exists so far in the transaction semantics that I know [*]. We already discussed that robots might do non-sensical stuff when creating a batches, and reporting EBUSY for this add-del-add case might just break them.

I don't think this breaks existing users, noone except syzbot reported such WARN splat so far.

Quoted 4 lines

This also removes the conditional hook registration, so hooks are registered once at chain creation. This simplifies interaction with the netfilter core at the cost of adding complexity to nf_tables_commit_chain_prepare() path.

It also adds side effect (hook registration) during preparation phase.

I think its similar to

add table foo
delete table foo
delete table foo

... and that gives -ENOENT.

author maintainer
#4 lore raw
Quoted 32 lines · Florian Westphal
Quoted 20 lines · Pablo Neira Ayuso
Quoted 14 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso

The dormant flag need to be updated from the preparation phase, otherwise, two consecutive requests to dorm a table in the same batch might try to remove the same hooks twice, resulting in the following warning:

Quoted 7 lines

hook not found, pf 3 num 0

 WARNING: CPU: 0 PID: 334 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
 Modules linked in:
 CPU: 0 PID: 334 Comm: kworker/u4:5 Not tainted 5.12.0-syzkaller #0
 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
 Workqueue: netns cleanup_net
 RIP: 0010:__nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
Quoted 2 lines

Would it be possible to reject such a batch instead of having to add rely on dummy hooking instead?

That's a simple way to fix it, yes, ie. hit EBUSY.

Quoted 7 lines
Quoted 2 lines

I don't think we should try to be clever with nonsensical yes-no-yes-yes-no type commits.

Note that no such EBUSY limitation exists so far in the transaction semantics that I know [*]. We already discussed that robots might do non-sensical stuff when creating a batches, and reporting EBUSY for this add-del-add case might just break them.

I don't think this breaks existing users, noone except syzbot reported such WARN splat so far.

Quoted 6 lines
Quoted 4 lines

This also removes the conditional hook registration, so hooks are registered once at chain creation. This simplifies interaction with the netfilter core at the cost of adding complexity to nf_tables_commit_chain_prepare() path.

It also adds side effect (hook registration) during preparation phase.

Chain hook registration always happened from preparation phase before this patch.

Quoted 7 lines

I think its similar to

add table foo
delete table foo
delete table foo

... and that gives -ENOENT.

This is the preparation phase that is rejecting it with -ENOENT.

The sequence that this patch handles is similar to:

add table foo
delete table foo
add table foo

which does _not_ hit EBUSY.

The existing transaction semantics handles similar sequences for the existing objects.

This patch ensures that:

add table x
add chain x y { type filter hook input priority 0; } add table x { flags dormant; }
add table x { ; }

in a batch file works fine.

A robot could generate such sequence above.

author maintainer
#5 lore raw
Quoted 64 lines · Pablo Neira Ayuso
Quoted 32 lines · Florian Westphal
Quoted 20 lines · Pablo Neira Ayuso
Quoted 14 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso

The dormant flag need to be updated from the preparation phase, otherwise, two consecutive requests to dorm a table in the same batch might try to remove the same hooks twice, resulting in the following warning:

Quoted 7 lines

hook not found, pf 3 num 0

 WARNING: CPU: 0 PID: 334 at net/netfilter/core.c:480 __nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
 Modules linked in:
 CPU: 0 PID: 334 Comm: kworker/u4:5 Not tainted 5.12.0-syzkaller #0
 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
 Workqueue: netns cleanup_net
 RIP: 0010:__nf_unregister_net_hook+0x1eb/0x610 net/netfilter/core.c:480
Quoted 2 lines

Would it be possible to reject such a batch instead of having to add rely on dummy hooking instead?

That's a simple way to fix it, yes, ie. hit EBUSY.

Quoted 7 lines
Quoted 2 lines

I don't think we should try to be clever with nonsensical yes-no-yes-yes-no type commits.

Note that no such EBUSY limitation exists so far in the transaction semantics that I know [*]. We already discussed that robots might do non-sensical stuff when creating a batches, and reporting EBUSY for this add-del-add case might just break them.

I don't think this breaks existing users, noone except syzbot reported such WARN splat so far.

Quoted 6 lines
Quoted 4 lines

This also removes the conditional hook registration, so hooks are registered once at chain creation. This simplifies interaction with the netfilter core at the cost of adding complexity to nf_tables_commit_chain_prepare() path.

It also adds side effect (hook registration) during preparation phase.

Chain hook registration always happened from preparation phase before this patch.

Quoted 7 lines

I think its similar to

add table foo
delete table foo
delete table foo

... and that gives -ENOENT.

This is the preparation phase that is rejecting it with -ENOENT.

The sequence that this patch handles is similar to:

add table foo
delete table foo
add table foo

which does _not_ hit EBUSY.

The existing transaction semantics handles similar sequences for the existing objects.

Quoted 8 lines

This patch ensures that:

add table x
add chain x y { type filter hook input priority 0; } add table x { flags dormant; }
add table x { ; }

in a batch file works fine.

Actually, the sequence this handle is:

add table x
add chain x y { type filter hook input priority 0; } add table x { flags dormant; }
add table x { ; }
add table x { flags dormant; }

which is similar to:

add table x
delete table x
add table x

Quoted 1 line

A robot could generate such sequence above.