Skip to content

Commit cf77d84

Browse files
committed
netfilter: nf_ct_ftp: fix deadlock when nat rewrite is needed
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2139501 commit d250889 Author: Florian Westphal <fw@strlen.de> Date: Tue Sep 20 18:31:30 2022 +0200 netfilter: nf_ct_ftp: fix deadlock when nat rewrite is needed We can't use ct->lock, this is already used by the seqadj internals. When using ftp helper + nat, seqadj will attempt to acquire ct->lock again. Revert back to a global lock for now. Fixes: c783a29 ("netfilter: nf_ct_ftp: prefer skb_linearize") Reported-by: Bruno de Paula Larini <bruno.larini@riosoft.com.br> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent cf7af8e commit cf77d84

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/netfilter/nf_conntrack_ftp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>");
3333
MODULE_DESCRIPTION("ftp connection tracking helper");
3434
MODULE_ALIAS("ip_conntrack_ftp");
3535
MODULE_ALIAS_NFCT_HELPER(HELPER_NAME);
36+
static DEFINE_SPINLOCK(nf_ftp_lock);
3637

3738
#define MAX_PORTS 8
3839
static u_int16_t ports[MAX_PORTS];
@@ -409,7 +410,8 @@ static int help(struct sk_buff *skb,
409410
}
410411
datalen = skb->len - dataoff;
411412

412-
spin_lock_bh(&ct->lock);
413+
/* seqadj (nat) uses ct->lock internally, nf_nat_ftp would cause deadlock */
414+
spin_lock_bh(&nf_ftp_lock);
413415
fb_ptr = skb->data + dataoff;
414416

415417
ends_in_nl = (fb_ptr[datalen - 1] == '\n');
@@ -538,7 +540,7 @@ static int help(struct sk_buff *skb,
538540
if (ends_in_nl)
539541
update_nl_seq(ct, seq, ct_ftp_info, dir, skb);
540542
out:
541-
spin_unlock_bh(&ct->lock);
543+
spin_unlock_bh(&nf_ftp_lock);
542544
return ret;
543545
}
544546

0 commit comments

Comments
 (0)