Skip to content

Commit 4a02426

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: tproxy: fix deadlock due to missing BH disable
The xtables packet traverser performs an unconditional local_bh_disable(), but the nf_tables evaluation loop does not. Functions that are called from either xtables or nftables must assume that they can be called in process context. inet_twsk_deschedule_put() assumes that no softirq interrupt can occur. If tproxy is used from nf_tables its possible that we'll deadlock trying to aquire a lock already held in process context. Add a small helper that takes care of this and use it. Link: https://lore.kernel.org/netfilter-devel/[email protected]/ Fixes: 4ed8eb6 ("netfilter: nf_tables: Add native tproxy support") Reported-and-tested-by: Major Dávid <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 9f7dd42 commit 4a02426

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

include/net/netfilter/nf_tproxy.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ static inline bool nf_tproxy_sk_is_transparent(struct sock *sk)
1717
return false;
1818
}
1919

20+
static inline void nf_tproxy_twsk_deschedule_put(struct inet_timewait_sock *tw)
21+
{
22+
local_bh_disable();
23+
inet_twsk_deschedule_put(tw);
24+
local_bh_enable();
25+
}
26+
2027
/* assign a socket to the skb -- consumes sk */
2128
static inline void nf_tproxy_assign_sock(struct sk_buff *skb, struct sock *sk)
2229
{

net/ipv4/netfilter/nf_tproxy_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ nf_tproxy_handle_time_wait4(struct net *net, struct sk_buff *skb,
3838
hp->source, lport ? lport : hp->dest,
3939
skb->dev, NF_TPROXY_LOOKUP_LISTENER);
4040
if (sk2) {
41-
inet_twsk_deschedule_put(inet_twsk(sk));
41+
nf_tproxy_twsk_deschedule_put(inet_twsk(sk));
4242
sk = sk2;
4343
}
4444
}

net/ipv6/netfilter/nf_tproxy_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ nf_tproxy_handle_time_wait6(struct sk_buff *skb, int tproto, int thoff,
6363
lport ? lport : hp->dest,
6464
skb->dev, NF_TPROXY_LOOKUP_LISTENER);
6565
if (sk2) {
66-
inet_twsk_deschedule_put(inet_twsk(sk));
66+
nf_tproxy_twsk_deschedule_put(inet_twsk(sk));
6767
sk = sk2;
6868
}
6969
}

0 commit comments

Comments
 (0)