android_kernel_xiaomi_sm7250/net/tipc
Xin Long ce69bdac23 tipc: fix a null-ptr-deref in tipc_topsrv_accept
[ Upstream commit 82cb4e4612c633a9ce320e1773114875604a3cce ]

syzbot found a crash in tipc_topsrv_accept:

  KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
  Workqueue: tipc_rcv tipc_topsrv_accept
  RIP: 0010:kernel_accept+0x22d/0x350 net/socket.c:3487
  Call Trace:
   <TASK>
   tipc_topsrv_accept+0x197/0x280 net/tipc/topsrv.c:460
   process_one_work+0x991/0x1610 kernel/workqueue.c:2289
   worker_thread+0x665/0x1080 kernel/workqueue.c:2436
   kthread+0x2e4/0x3a0 kernel/kthread.c:376
   ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

It was caused by srv->listener that might be set to null by
tipc_topsrv_stop() in net .exit whereas it's still used in
tipc_topsrv_accept() worker.

srv->listener is protected by srv->idr_lock in tipc_topsrv_stop(), so add
a check for srv->listener under srv->idr_lock in tipc_topsrv_accept() to
avoid the null-ptr-deref. To ensure the lsock is not released during the
tipc_topsrv_accept(), move sock_release() after tipc_topsrv_work_stop()
where it's waiting until the tipc_topsrv_accept worker to be done.

Note that sk_callback_lock is used to protect sk->sk_user_data instead of
srv->listener, and it should check srv in tipc_topsrv_listener_data_ready()
instead. This also ensures that no more tipc_topsrv_accept worker will be
started after tipc_conn_close() is called in tipc_topsrv_stop() where it
sets sk->sk_user_data to null.

Fixes: 0ef897be12 ("tipc: separate topology server listener socket from subcsriber sockets")
Reported-by: syzbot+c5ce866a8d30f4be0651@syzkaller.appspotmail.com
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Jon Maloy <jmaloy@redhat.com>
Link: https://lore.kernel.org/r/4eee264380c409c61c6451af1059b7fb271a7e7b.1666120790.git.lucien.xin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-11-03 23:52:30 +09:00
..
addr.c
addr.h
bcast.c tipc: clean up skb list lock handling on send path 2020-07-29 10:16:47 +02:00
bcast.h
bearer.c tipc: check attribute length for bearer name 2022-06-14 16:59:34 +02:00
bearer.h
core.c tipc: fix use-after-free in tipc_bcast_get_mode 2020-11-10 12:35:53 +01:00
core.h
diag.c
discover.c tipc: Fix recognition of trial period 2022-11-03 23:52:25 +09:00
discover.h
eth_media.c
group.c tipc: Fix memory leak in tipc_group_create_member() 2020-09-26 18:01:30 +02:00
group.h
ib_media.c
Kconfig
link.c tipc: improve size validations for received domain records 2022-02-11 08:44:59 +01:00
link.h
Makefile
monitor.c tipc: fix shift wrapping bug in map_get() 2022-09-15 12:17:05 +02:00
monitor.h
msg.c tipc: skb_linearize the head skb when reassembling msgs 2021-06-03 08:38:08 +02:00
msg.h
name_distr.c tipc: rate limit warning for received illegal binding update 2022-02-16 12:51:46 +01:00
name_distr.h
name_table.c tipc: Fix end of loop tests for list_for_each_entry() 2022-03-02 11:38:11 +01:00
name_table.h
net.c
net.h
netlink_compat.c tipc: convert dest node's address to network order 2021-05-22 10:59:39 +02:00
netlink.c
netlink.h
node.c tipc: clean up skb list lock handling on send path 2020-07-29 10:16:47 +02:00
node.h
socket.c net: tipc: fix possible refcount leak in tipc_sk_create() 2022-07-21 21:09:30 +02:00
socket.h
subscr.c
subscr.h
sysctl.c
topsrv.c tipc: fix a null-ptr-deref in tipc_topsrv_accept 2022-11-03 23:52:30 +09:00
topsrv.h
udp_media.c
udp_media.h