]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netfilter: tproxy: fix deadlock due to missing BH disable
authorFlorian Westphal <fw@strlen.de>
Fri, 3 Mar 2023 09:58:56 +0000 (10:58 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Mar 2023 07:32:51 +0000 (08:32 +0100)
[ Upstream commit 4a02426787bf024dafdb79b362285ee325de3f5e ]

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/401bd6ed-314a-a196-1cdc-e13c720cc8f2@balasys.hu/
Fixes: 5e25179efc53 ("netfilter: nf_tables: Add native tproxy support")
Reported-and-tested-by: Major Dávid <major.david@balasys.hu>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/netfilter/nf_tproxy.h
net/ipv4/netfilter/nf_tproxy_ipv4.c
net/ipv6/netfilter/nf_tproxy_ipv6.c

index 82d0e41b76f224f02a5b8fb3fec6d4c64721066a..faa108b1ba675ba89724b16ba3c16df2776aeb6b 100644 (file)
@@ -17,6 +17,13 @@ static inline bool nf_tproxy_sk_is_transparent(struct sock *sk)
        return false;
 }
 
+static inline void nf_tproxy_twsk_deschedule_put(struct inet_timewait_sock *tw)
+{
+       local_bh_disable();
+       inet_twsk_deschedule_put(tw);
+       local_bh_enable();
+}
+
 /* assign a socket to the skb -- consumes sk */
 static inline void nf_tproxy_assign_sock(struct sk_buff *skb, struct sock *sk)
 {
index b2bae0b0e42a1e983210b37b32b50186de1b0eff..61cb2341f50fe007c6208a091d214ba6c37e905d 100644 (file)
@@ -38,7 +38,7 @@ nf_tproxy_handle_time_wait4(struct net *net, struct sk_buff *skb,
                                            hp->source, lport ? lport : hp->dest,
                                            skb->dev, NF_TPROXY_LOOKUP_LISTENER);
                if (sk2) {
-                       inet_twsk_deschedule_put(inet_twsk(sk));
+                       nf_tproxy_twsk_deschedule_put(inet_twsk(sk));
                        sk = sk2;
                }
        }
index 34d51cd426b0ccaf1e2ffbc3875bfb3804f6cf33..00761924f2766a02cbad320712df5a2a4e9d716f 100644 (file)
@@ -63,7 +63,7 @@ nf_tproxy_handle_time_wait6(struct sk_buff *skb, int tproto, int thoff,
                                            lport ? lport : hp->dest,
                                            skb->dev, NF_TPROXY_LOOKUP_LISTENER);
                if (sk2) {
-                       inet_twsk_deschedule_put(inet_twsk(sk));
+                       nf_tproxy_twsk_deschedule_put(inet_twsk(sk));
                        sk = sk2;
                }
        }