Hello,
These are netfilter fixes for the *net* tree.
First patch resolves a false-positive lockdep splat:
rcu_dereference is used outside of rcu read lock. Let lockdep
validate that the transaction mutex is locked.
Second patch fixes a kdoc warning added in previous PR.
Third patch fixes a memory leak:
The catchall element isn't disabled correctly, this allows
userspace to deactivate the element again. This results in refcount
underflow which in turn prevents memory release. This was always
broken since the feature was added in 5.13.
Patch 4 fixes an incorrect change in the previous pull request:
Adding a duplicate key to a set should work if the duplicate key
has expired, restore this behaviour. All from myself.
Patch #5 resolves an old historic artifact in sctp conntrack:
a 300ms timeout for shutdown_ack. Increase this to 3s. From Xin Long.
Patch #6 fixes a sysctl data race in ipvs, two threads can clobber the
sysctl value, from Sishuai Gong. This is a day-0 bug that predates git
history.
Patches 7, 8 and 9, from Pablo Neira Ayuso, are also followups
for the previous GC rework in nf_tables: The netlink notifier and the
netns exit path must both increment the gc worker seqcount, else worker
may encounter stale (free'd) pointers.
The following changes since commit e4dd0d3a2f64b8bd8029ec70f52bdbebd0644408:
net: fix the RTO timer retransmitting skb every 1ms if linear option is enabled (2023-08-15 20:24:04 +0100)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-23-08-16
for you to fetch changes up to 23185c6aed1ffb8fc44087880ba2767aba493779:
netfilter: nft_dynset: disallow object maps (2023-08-16 00:05:15 +0200)
----------------------------------------------------------------
nf pull request 2023-08-16
----------------------------------------------------------------
Florian Westphal (4):
netfilter: nf_tables: fix false-positive lockdep splat
netfilter: nf_tables: fix kdoc warnings after gc rework
netfilter: nf_tables: deactivate catchall elements in next generation
netfilter: nf_tables: don't fail inserts if duplicate has expired
Pablo Neira Ayuso (3):
netfilter: nf_tables: fix GC transaction races with netns and netlink event exit path
netfilter: nf_tables: GC transaction race with netns dismantle
netfilter: nft_dynset: disallow object maps
Sishuai Gong (1):
ipvs: fix racy memcpy in proc_do_sync_threshold
Xin Long (1):
netfilter: set default timeout to 3 secs for sctp shutdown send and recv state
Documentation/networking/nf_conntrack-sysctl.rst | 4 +--
include/net/netfilter/nf_tables.h | 1 +
net/netfilter/ipvs/ip_vs_ctl.c | 4 +++
net/netfilter/nf_conntrack_proto_sctp.c | 6 ++--
net/netfilter/nf_tables_api.c | 44 +++++++++++++++++++++---
net/netfilter/nft_dynset.c | 3 ++
net/netfilter/nft_set_pipapo.c | 38 +++++++++-----------
7 files changed, 69 insertions(+), 31 deletions(-)
Jakub Kicinski says:
We've got some new kdoc warnings here:
net/netfilter/nft_set_pipapo.c:1557: warning: Function parameter or member '_set' not described in 'pipapo_gc'
net/netfilter/nft_set_pipapo.c:1557: warning: Excess function parameter 'set' description in 'pipapo_gc'
include/net/netfilter/nf_tables.h:577: warning: Function parameter or member 'dead' not described in 'nft_set'
Fixes: 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
Fixes: f6c383b8c31a ("netfilter: nf_tables: adapt set backend to use GC transaction API")
Reported-by: Jakub Kicinski <kuba@kernel.org>
Closes: https://lore.kernel.org/netdev/20230810104638.746e46f1@kernel.org/
Signed-off-by: Florian Westphal <fw@strlen.de>
---
include/net/netfilter/nf_tables.h | 1 +
net/netfilter/nft_set_pipapo.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
When flushing, individual set elements are disabled in the next
generation via the ->flush callback.
Catchall elements are not disabled. This is incorrect and may lead to
double-deactivations of catchall elements which then results in memory
leaks:
WARNING: CPU: 1 PID: 3300 at include/net/netfilter/nf_tables.h:1172 nft_map_deactivate+0x549/0x730
CPU: 1 PID: 3300 Comm: nft Not tainted 6.5.0-rc5+ #60
RIP: 0010:nft_map_deactivate+0x549/0x730
[..]
? nft_map_deactivate+0x549/0x730
nf_tables_delset+0xb66/0xeb0
(the warn is due to nft_use_dec() detecting underflow).
Fixes: aaa31047a6d2 ("netfilter: nftables: add catch-all set element support")
Reported-by: lonial con <redacted>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 1 +
1 file changed, 1 insertion(+)
nftables selftests fail:
run-tests.sh testcases/sets/0044interval_overlap_0
Expected: 0-2 . 0-3, got:
W: [FAILED] ./testcases/sets/0044interval_overlap_0: got 1
Insertion must ignore duplicate but expired entries.
Moreover, there is a strange asymmetry in nft_pipapo_activate:
It refetches the current element, whereas the other ->activate callbacks
(bitmap, hash, rhash, rbtree) use elem->priv.
Same for .remove: other set implementations take elem->priv,
nft_pipapo_remove fetches elem->priv, then does a relookup,
remove this.
I suspect this was the reason for the change that prompted the
removal of the expired check in pipapo_get() in the first place,
but skipping exired elements there makes no sense to me, this helper
is used for normal get requests, insertions (duplicate check)
and deactivate callback.
In first two cases expired elements must be skipped.
For ->deactivate(), this gets called for DELSETELEM, so it
seems to me that expired elements should be skipped as well, i.e.
delete request should fail with -ENOENT error.
Fixes: 24138933b97b ("netfilter: nf_tables: don't skip expired elements during walk")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nft_set_pipapo.c | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)
From: Xin Long <lucien.xin@gmail.com>
In SCTP protocol, it is using the same timer (T2 timer) for SHUTDOWN and
SHUTDOWN_ACK retransmission. However in sctp conntrack the default timeout
value for SCTP_CONNTRACK_SHUTDOWN_ACK_SENT state is 3 secs while it's 300
msecs for SCTP_CONNTRACK_SHUTDOWN_SEND/RECV state.
As Paolo Valerio noticed, this might cause unwanted expiration of the ct
entry. In my test, with 1s tc netem delay set on the NAT path, after the
SHUTDOWN is sent, the sctp ct entry enters SCTP_CONNTRACK_SHUTDOWN_SEND
state. However, due to 300ms (too short) delay, when the SHUTDOWN_ACK is
sent back from the peer, the sctp ct entry has expired and been deleted,
and then the SHUTDOWN_ACK has to be dropped.
Also, it is confusing these two sysctl options always show 0 due to all
timeout values using sec as unit:
net.netfilter.nf_conntrack_sctp_timeout_shutdown_recd = 0
net.netfilter.nf_conntrack_sctp_timeout_shutdown_sent = 0
This patch fixes it by also using 3 secs for sctp shutdown send and recv
state in sctp conntrack, which is also RTO.initial value in SCTP protocol.
Note that the very short time value for SCTP_CONNTRACK_SHUTDOWN_SEND/RECV
was probably used for a rare scenario where SHUTDOWN is sent on 1st path
but SHUTDOWN_ACK is replied on 2nd path, then a new connection started
immediately on 1st path. So this patch also moves from SHUTDOWN_SEND/RECV
to CLOSE when receiving INIT in the ORIGINAL direction.
Fixes: 9fb9cbb1082d ("[NETFILTER]: Add nf_conntrack subsystem.")
Reported-by: Paolo Valerio <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
Documentation/networking/nf_conntrack-sysctl.rst | 4 ++--
net/netfilter/nf_conntrack_proto_sctp.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
From: Sishuai Gong <redacted>
When two threads run proc_do_sync_threshold() in parallel,
data races could happen between the two memcpy():
Thread-1 Thread-2
memcpy(val, valp, sizeof(val));
memcpy(valp, val, sizeof(val));
This race might mess up the (struct ctl_table *) table->data,
so we add a mutex lock to serialize them.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://lore.kernel.org/netdev/B6988E90-0A1E-4B85-BF26-2DAF6D482433@gmail.com/
Signed-off-by: Sishuai Gong <redacted>
Acked-by: Simon Horman <horms@kernel.org>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/ipvs/ip_vs_ctl.c | 4 ++++
1 file changed, 4 insertions(+)
From: Pablo Neira Ayuso <pablo@netfilter.org>
Netlink event path is missing a synchronization point with GC
transactions. Add GC sequence number update to netns release path and
netlink event path, any GC transaction losing race will be discarded.
Fixes: 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_tables_api.c | 36 +++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
@@ -9739,6 +9739,22 @@ static void nft_set_commit_update(struct list_head *set_update_list)}}+staticunsignedintnft_gc_seq_begin(structnftables_pernet*nft_net)+{+unsignedintgc_seq;++/* Bump gc counter, it becomes odd, this is the busy mark. */+gc_seq=READ_ONCE(nft_net->gc_seq);+WRITE_ONCE(nft_net->gc_seq,++gc_seq);++returngc_seq;+}++staticvoidnft_gc_seq_end(structnftables_pernet*nft_net,unsignedintgc_seq)+{+WRITE_ONCE(nft_net->gc_seq,++gc_seq);+}+staticintnf_tables_commit(structnet*net,structsk_buff*skb){structnftables_pernet*nft_net=nft_pernet(net);
@@ -9824,9 +9840,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)WRITE_ONCE(nft_net->base_seq,base_seq);-/* Bump gc counter, it becomes odd, this is the busy mark. */-gc_seq=READ_ONCE(nft_net->gc_seq);-WRITE_ONCE(nft_net->gc_seq,++gc_seq);+gc_seq=nft_gc_seq_begin(nft_net);/* step 3. Start new generation, rules_gen_X now in use. */net->nft.gencursor=nft_gencursor_next(net);
@@ -10039,7 +10053,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nf_tables_gen_notify(net,skb,NFT_MSG_NEWGEN);nf_tables_commit_audit_log(&adl,nft_net->base_seq);-WRITE_ONCE(nft_net->gc_seq,++gc_seq);+nft_gc_seq_end(nft_net,gc_seq);nf_tables_commit_release(net);return0;
@@ -11040,6 +11054,7 @@ static int nft_rcv_nl_event(struct notifier_block *this, unsigned long event,structnet*net=n->net;unsignedintdeleted;boolrestart=false;+unsignedintgc_seq;if(event!=NETLINK_URELEASE||n->protocol!=NETLINK_NETFILTER)returnNOTIFY_DONE;
@@ -11047,6 +11062,9 @@ static int nft_rcv_nl_event(struct notifier_block *this, unsigned long event,nft_net=nft_pernet(net);deleted=0;mutex_lock(&nft_net->commit_mutex);++gc_seq=nft_gc_seq_begin(nft_net);+if(!list_empty(&nf_tables_destroy_list))rcu_barrier();again:
@@ -11069,6 +11087,8 @@ static int nft_rcv_nl_event(struct notifier_block *this, unsigned long event,if(restart)gotoagain;}+nft_gc_seq_end(nft_net,gc_seq);+mutex_unlock(&nft_net->commit_mutex);returnNOTIFY_DONE;
@@ -11106,12 +11126,20 @@ static void __net_exit nf_tables_pre_exit_net(struct net *net)staticvoid__net_exitnf_tables_exit_net(structnet*net){structnftables_pernet*nft_net=nft_pernet(net);+unsignedintgc_seq;mutex_lock(&nft_net->commit_mutex);++gc_seq=nft_gc_seq_begin(nft_net);+if(!list_empty(&nft_net->commit_list)||!list_empty(&nft_net->module_list))__nf_tables_abort(net,NFNL_ABORT_NONE);+__nft_release_tables(net);++nft_gc_seq_end(nft_net,gc_seq);+mutex_unlock(&nft_net->commit_mutex);WARN_ON_ONCE(!list_empty(&nft_net->tables));WARN_ON_ONCE(!list_empty(&nft_net->module_list));
From: Pablo Neira Ayuso <pablo@netfilter.org>
Do not allow to insert elements from datapath to objects maps.
Fixes: 8aeff920dcc9 ("netfilter: nf_tables: add stateful object reference to set elements")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nft_dynset.c | 3 +++
1 file changed, 3 insertions(+)