Commit 2cdaa3ee authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: conntrack: restore IPS_CONFIRMED out of nf_conntrack_hash_check_insert()

e6d57e9f ("netfilter: conntrack: fix rmmod double-free race")
consolidates IPS_CONFIRMED bit set in nf_conntrack_hash_check_insert().
However, this breaks ctnetlink:

 # conntrack -I -p tcp --timeout 123 --src 1.2.3.4 --dst 5.6.7.8 --state ESTABLISHED --sport 1 --dport 4 -u SEEN_REPLY
 conntrack v1.4.6 (conntrack-tools): Operation failed: Device or resource busy

This is a partial revert of the aforementioned commit to restore
IPS_CONFIRMED.

Fixes: e6d57e9f ("netfilter: conntrack: fix rmmod double-free race")
Reported-by: default avatarStéphane Graber <stgraber@stgraber.org>
Tested-by: default avatarStéphane Graber <stgraber@stgraber.org>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 92e8c732
...@@ -381,6 +381,7 @@ __bpf_kfunc struct nf_conn *bpf_ct_insert_entry(struct nf_conn___init *nfct_i) ...@@ -381,6 +381,7 @@ __bpf_kfunc struct nf_conn *bpf_ct_insert_entry(struct nf_conn___init *nfct_i)
struct nf_conn *nfct = (struct nf_conn *)nfct_i; struct nf_conn *nfct = (struct nf_conn *)nfct_i;
int err; int err;
nfct->status |= IPS_CONFIRMED;
err = nf_conntrack_hash_check_insert(nfct); err = nf_conntrack_hash_check_insert(nfct);
if (err < 0) { if (err < 0) {
nf_conntrack_free(nfct); nf_conntrack_free(nfct);
......
...@@ -932,7 +932,6 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct) ...@@ -932,7 +932,6 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
goto out; goto out;
} }
ct->status |= IPS_CONFIRMED;
smp_wmb(); smp_wmb();
/* The caller holds a reference to this object */ /* The caller holds a reference to this object */
refcount_set(&ct->ct_general.use, 2); refcount_set(&ct->ct_general.use, 2);
......
...@@ -2316,6 +2316,9 @@ ctnetlink_create_conntrack(struct net *net, ...@@ -2316,6 +2316,9 @@ ctnetlink_create_conntrack(struct net *net,
nfct_seqadj_ext_add(ct); nfct_seqadj_ext_add(ct);
nfct_synproxy_ext_add(ct); nfct_synproxy_ext_add(ct);
/* we must add conntrack extensions before confirmation. */
ct->status |= IPS_CONFIRMED;
if (cda[CTA_STATUS]) { if (cda[CTA_STATUS]) {
err = ctnetlink_change_status(ct, cda); err = ctnetlink_change_status(ct, cda);
if (err < 0) if (err < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment