linux-stable/net
Xin Long d962d42d63 tipc: call tipc_lxc_xmit without holding node_read_lock
[ Upstream commit 88956177db ]

When sending packets between nodes in netns, it calls tipc_lxc_xmit() for
peer node to receive the packets where tipc_sk_mcast_rcv()/tipc_sk_rcv()
might be called, and it's pretty much like in tipc_rcv().

Currently the local 'node rw lock' is held during calling tipc_lxc_xmit()
to protect the peer_net not being freed by another thread. However, when
receiving these packets, tipc_node_add_conn() might be called where the
peer 'node rw lock' is acquired. Then a dead lock warning is triggered by
lockdep detector, although it is not a real dead lock:

    WARNING: possible recursive locking detected
    --------------------------------------------
    conn_server/1086 is trying to acquire lock:
    ffff8880065cb020 (&n->lock#2){++--}-{2:2}, \
                     at: tipc_node_add_conn.cold.76+0xaa/0x211 [tipc]

    but task is already holding lock:
    ffff8880065cd020 (&n->lock#2){++--}-{2:2}, \
                     at: tipc_node_xmit+0x285/0xb30 [tipc]

    other info that might help us debug this:
     Possible unsafe locking scenario:

           CPU0
           ----
      lock(&n->lock#2);
      lock(&n->lock#2);

     *** DEADLOCK ***

     May be due to missing lock nesting notation

    4 locks held by conn_server/1086:
     #0: ffff8880036d1e40 (sk_lock-AF_TIPC){+.+.}-{0:0}, \
                          at: tipc_accept+0x9c0/0x10b0 [tipc]
     #1: ffff8880036d5f80 (sk_lock-AF_TIPC/1){+.+.}-{0:0}, \
                          at: tipc_accept+0x363/0x10b0 [tipc]
     #2: ffff8880065cd020 (&n->lock#2){++--}-{2:2}, \
                          at: tipc_node_xmit+0x285/0xb30 [tipc]
     #3: ffff888012e13370 (slock-AF_TIPC){+...}-{2:2}, \
                          at: tipc_sk_rcv+0x2da/0x1b40 [tipc]

    Call Trace:
     <TASK>
     dump_stack_lvl+0x44/0x5b
     __lock_acquire.cold.77+0x1f2/0x3d7
     lock_acquire+0x1d2/0x610
     _raw_write_lock_bh+0x38/0x80
     tipc_node_add_conn.cold.76+0xaa/0x211 [tipc]
     tipc_sk_finish_conn+0x21e/0x640 [tipc]
     tipc_sk_filter_rcv+0x147b/0x3030 [tipc]
     tipc_sk_rcv+0xbb4/0x1b40 [tipc]
     tipc_lxc_xmit+0x225/0x26b [tipc]
     tipc_node_xmit.cold.82+0x4a/0x102 [tipc]
     __tipc_sendstream+0x879/0xff0 [tipc]
     tipc_accept+0x966/0x10b0 [tipc]
     do_accept+0x37d/0x590

This patch avoids this warning by not holding the 'node rw lock' before
calling tipc_lxc_xmit(). As to protect the 'peer_net', rcu_read_lock()
should be enough, as in cleanup_net() when freeing the netns, it calls
synchronize_rcu() before the free is continued.

Also since tipc_lxc_xmit() is like the RX path in tipc_rcv(), it makes
sense to call it under rcu_read_lock(). Note that the right lock order
must be:

   rcu_read_lock();
   tipc_node_read_lock(n);
   tipc_node_read_unlock(n);
   tipc_lxc_xmit();
   rcu_read_unlock();

instead of:

   tipc_node_read_lock(n);
   rcu_read_lock();
   tipc_node_read_unlock(n);
   tipc_lxc_xmit();
   rcu_read_unlock();

and we have to call tipc_node_read_lock/unlock() twice in
tipc_node_xmit().

Fixes: f73b12812a ("tipc: improve throughput between nodes in netns")
Reported-by: Shuang Li <shuali@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Link: https://lore.kernel.org/r/5bdd1f8fee9db695cfff4528a48c9b9d0523fb00.1670110641.git.lucien.xin@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-14 11:37:29 +01:00
..
6lowpan
9p 9p/xen: check logical size for buffer size 2022-12-14 11:37:17 +01:00
802
8021q net: use eth_hw_addr_set() instead of ether_addr_copy() 2022-08-31 17:16:37 +02:00
appletalk
atm net/atm: fix proc_mpc_write incorrect return value 2022-10-29 10:12:55 +02:00
ax25 net: ax25: Fix deadlock caused by skb_recv_datagram in ax25_recvmsg 2022-06-22 14:22:01 +02:00
batman-adv batman-adv: Use netif_rx_any_context() any. 2022-07-29 17:25:07 +02:00
bluetooth Bluetooth: Fix not cleanup led when bt_init fails 2022-12-14 11:37:24 +01:00
bpf bpf, test_run: Fix alignment problem in bpf_prog_test_run_skb() 2022-11-26 09:24:35 +01:00
bpfilter
bridge bridge: switchdev: Fix memory leaks when changing VLAN protocol 2022-11-26 09:24:40 +01:00
caif net: caif: fix double disconnect client in chnl_net_open() 2022-11-26 09:24:39 +01:00
can can: af_can: fix NULL pointer dereference in can_rcv_filter 2022-12-14 11:37:22 +01:00
ceph libceph: fix potential use-after-free on linger ping and resends 2022-05-25 09:57:28 +02:00
core netfilter: conntrack: Fix data-races around ct mark 2022-12-02 17:41:04 +01:00
dcb
dccp dccp/tcp: Reset saddr on failure after inet6?_hash_connect(). 2022-12-02 17:41:07 +01:00
decnet net: Fix data-races around sysctl_[rw]mem(_offset)?. 2022-08-03 12:03:51 +02:00
dns_resolver
dsa net: dsa: sja1105: Check return value 2022-12-14 11:37:25 +01:00
ethernet
ethtool ethtool: eeprom: fix null-deref on genl_info in dump 2022-11-03 23:59:14 +09:00
hsr net: hsr: Fix potential use-after-free 2022-12-08 11:28:41 +01:00
ieee802154 net: ieee802154: fix error return code in dgram_bind() 2022-11-03 23:59:14 +09:00
ife
ipv4 ipv4: Fix incorrect route flushing when table ID 0 is used 2022-12-14 11:37:28 +01:00
ipv6 dccp/tcp: Reset saddr on failure after inet6?_hash_connect(). 2022-12-02 17:41:07 +01:00
iucv
kcm kcm: close race conditions on sk_receive_queue 2022-11-26 09:24:50 +01:00
key xfrm: Fix oops in __xfrm_state_delete() 2022-12-02 17:41:06 +01:00
l2tp ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg 2022-06-22 14:21:58 +02:00
l3mdev
lapb
llc
mac80211 wifi: mac8021: fix possible oob access in ieee80211_get_rate_duration 2022-12-08 11:28:40 +01:00
mac802154 mac802154: fix missing INIT_LIST_HEAD in ieee802154_if_add() 2022-12-14 11:37:25 +01:00
mctp mctp: Fix an error handling path in mctp_init() 2022-11-16 09:58:22 +01:00
mpls net: Use u64_stats_fetch_begin_irq() for stats fetch. 2022-09-08 12:28:07 +02:00
mptcp mptcp: Fix crash due to tcp_tsorted_anchor was initialized before release skb 2022-08-31 17:16:50 +02:00
ncsi
netfilter netfilter: ctnetlink: fix compilation warning after data race fixes in ct mark 2022-12-14 11:37:23 +01:00
netlabel
netlink net: genl: fix error path memory leak in policy dumping 2022-08-25 11:40:25 +02:00
netrom
nfc NFC: nci: Bounds check struct nfc_target arrays 2022-12-14 11:37:27 +01:00
nsh
openvswitch netfilter: conntrack: Fix data-races around ct mark 2022-12-02 17:41:04 +01:00
packet packet: do not set TP_STATUS_CSUM_VALID on CHECKSUM_COMPLETE 2022-12-08 11:28:41 +01:00
phonet
psample
qrtr net: qrtr: start MHI channel after endpoit creation 2022-08-25 11:40:29 +02:00
rds net: rds: don't hold sock lock when cancelling work from rds_tcp_reset_callbacks() 2022-10-26 12:34:49 +02:00
rfkill
rose rose: Fix NULL pointer dereference in rose_send_frame() 2022-11-10 18:15:29 +01:00
rxrpc rxrpc: Fix race between conn bundle lookup and bundle removal [ZDI-CAN-15975] 2022-12-02 17:41:04 +01:00
sched net: sched: allow act_ct to be built without NF_NAT 2022-12-02 17:41:06 +01:00
sctp sctp: fix memory leak in sctp_stream_outq_migrate() 2022-12-08 11:28:41 +01:00
smc net/smc: Fix possible leaked pernet namespace in smc_init() 2022-11-10 18:15:31 +01:00
strparser
sunrpc SUNRPC: Fix null-ptr-deref when xps sysfs alloc failed 2022-11-10 18:15:26 +01:00
switchdev
tipc tipc: call tipc_lxc_xmit without holding node_read_lock 2022-12-14 11:37:29 +01:00
tls net/tls: Remove the context from the list in tls_device_down 2022-08-03 12:03:47 +02:00
unix af_unix: Get user_ns from in_skb in unix_diag_get_exact(). 2022-12-14 11:37:24 +01:00
vmw_vsock vsock: fix possible infinite sleep in vsock_connectible_wait_data() 2022-11-10 18:15:31 +01:00
wireless wifi: cfg80211: don't allow multi-BSSID in S1G 2022-12-08 11:28:40 +01:00
x25 net/x25: Fix skb leak in x25_lapb_receive_frame() 2022-11-26 09:24:41 +01:00
xdp xsk: Fix backpressure mechanism on Tx 2022-10-26 12:34:40 +02:00
xfrm xfrm: replay: Fix ESN wrap around for GSO 2022-12-02 17:41:02 +01:00
compat.c
devres.c
Kconfig
Makefile
socket.c net: Fix a data-race around sysctl_somaxconn. 2022-08-31 17:16:45 +02:00
sysctl_net.c