Skip to content

Commit f9bcdce

Browse files
committed
Merge tag 'nf-23-04-21' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net 1) Set on IPS_CONFIRMED before change_status() otherwise EBUSY is bogusly hit. This bug was introduced in the 6.3 release cycle. 2) Fix nfnetlink_queue conntrack support: Set/dump timeout accordingly for unconfirmed conntrack entries. Make sure this is done after IPS_CONFIRMED is set on. This is an old bug, it happens since the introduction of this feature. * tag 'nf-23-04-21' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf: netfilter: conntrack: fix wrong ct->timeout value netfilter: conntrack: restore IPS_CONFIRMED out of nf_conntrack_hash_check_insert() ==================== Link: https://lore.kernel.org/r/20230421105700.325438-1-pablo@netfilter.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents e375b50 + 73db1b8 commit f9bcdce

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

include/net/netfilter/nf_conntrack_core.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ static inline void __nf_ct_set_timeout(struct nf_conn *ct, u64 timeout)
8989
{
9090
if (timeout > INT_MAX)
9191
timeout = INT_MAX;
92-
WRITE_ONCE(ct->timeout, nfct_time_stamp + (u32)timeout);
92+
93+
if (nf_ct_is_confirmed(ct))
94+
WRITE_ONCE(ct->timeout, nfct_time_stamp + (u32)timeout);
95+
else
96+
ct->timeout = (u32)timeout;
9397
}
9498

9599
int __nf_ct_change_timeout(struct nf_conn *ct, u64 cta_timeout);

net/netfilter/nf_conntrack_bpf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ __bpf_kfunc struct nf_conn *bpf_ct_insert_entry(struct nf_conn___init *nfct_i)
381381
struct nf_conn *nfct = (struct nf_conn *)nfct_i;
382382
int err;
383383

384+
nfct->status |= IPS_CONFIRMED;
384385
err = nf_conntrack_hash_check_insert(nfct);
385386
if (err < 0) {
386387
nf_conntrack_free(nfct);

net/netfilter/nf_conntrack_core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,6 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
932932
goto out;
933933
}
934934

935-
ct->status |= IPS_CONFIRMED;
936935
smp_wmb();
937936
/* The caller holds a reference to this object */
938937
refcount_set(&ct->ct_general.use, 2);

net/netfilter/nf_conntrack_netlink.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ static int ctnetlink_dump_status(struct sk_buff *skb, const struct nf_conn *ct)
176176
static int ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct,
177177
bool skip_zero)
178178
{
179-
long timeout = nf_ct_expires(ct) / HZ;
179+
long timeout;
180+
181+
if (nf_ct_is_confirmed(ct))
182+
timeout = nf_ct_expires(ct) / HZ;
183+
else
184+
timeout = ct->timeout / HZ;
180185

181186
if (skip_zero && timeout == 0)
182187
return 0;
@@ -2253,9 +2258,6 @@ ctnetlink_create_conntrack(struct net *net,
22532258
if (!cda[CTA_TIMEOUT])
22542259
goto err1;
22552260

2256-
timeout = (u64)ntohl(nla_get_be32(cda[CTA_TIMEOUT])) * HZ;
2257-
__nf_ct_set_timeout(ct, timeout);
2258-
22592261
rcu_read_lock();
22602262
if (cda[CTA_HELP]) {
22612263
char *helpname = NULL;
@@ -2316,6 +2318,12 @@ ctnetlink_create_conntrack(struct net *net,
23162318
nfct_seqadj_ext_add(ct);
23172319
nfct_synproxy_ext_add(ct);
23182320

2321+
/* we must add conntrack extensions before confirmation. */
2322+
ct->status |= IPS_CONFIRMED;
2323+
2324+
timeout = (u64)ntohl(nla_get_be32(cda[CTA_TIMEOUT])) * HZ;
2325+
__nf_ct_set_timeout(ct, timeout);
2326+
23192327
if (cda[CTA_STATUS]) {
23202328
err = ctnetlink_change_status(ct, cda);
23212329
if (err < 0)

0 commit comments

Comments
 (0)