Ziyang Xuan
aa95efa187
net: qrtr: Fix a refcount bug in qrtr_recvmsg()
...
[ Upstream commit 44d8073200
]
Syzbot reported a bug as following:
refcount_t: addition on 0; use-after-free.
...
RIP: 0010:refcount_warn_saturate+0x17c/0x1f0 lib/refcount.c:25
...
Call Trace:
<TASK>
__refcount_add include/linux/refcount.h:199 [inline]
__refcount_inc include/linux/refcount.h:250 [inline]
refcount_inc include/linux/refcount.h:267 [inline]
kref_get include/linux/kref.h:45 [inline]
qrtr_node_acquire net/qrtr/af_qrtr.c:202 [inline]
qrtr_node_lookup net/qrtr/af_qrtr.c:398 [inline]
qrtr_send_resume_tx net/qrtr/af_qrtr.c:1003 [inline]
qrtr_recvmsg+0x85f/0x990 net/qrtr/af_qrtr.c:1070
sock_recvmsg_nosec net/socket.c:1017 [inline]
sock_recvmsg+0xe2/0x160 net/socket.c:1038
qrtr_ns_worker+0x170/0x1700 net/qrtr/ns.c:688
process_one_work+0x991/0x15c0 kernel/workqueue.c:2390
worker_thread+0x669/0x1090 kernel/workqueue.c:2537
It occurs in the concurrent scenario of qrtr_recvmsg() and
qrtr_endpoint_unregister() as following:
cpu0 cpu1
qrtr_recvmsg qrtr_endpoint_unregister
qrtr_send_resume_tx qrtr_node_release
qrtr_node_lookup mutex_lock(&qrtr_node_lock)
spin_lock_irqsave(&qrtr_nodes_lock, ) refcount_dec_and_test(&node->ref) [node->ref == 0]
radix_tree_lookup [node != NULL] __qrtr_node_release
qrtr_node_acquire spin_lock_irqsave(&qrtr_nodes_lock, )
kref_get(&node->ref) [WARNING] ...
mutex_unlock(&qrtr_node_lock)
Use qrtr_node_lock to protect qrtr_node_lookup() implementation, this
is actually improving the protection of node reference.
Fixes: 0a7e0d0ef0
("net: qrtr: Migrate node lookup tree to spinlock")
Reported-by: syzbot+a7492efaa5d61b51db23@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=a7492efaa5d61b51db23
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com >
Signed-off-by: David S. Miller <davem@davemloft.net >
Signed-off-by: Sasha Levin <sashal@kernel.org >
2023-04-13 16:55:20 +02:00
..
2022-06-09 21:53:28 +02:00
2023-03-22 13:33:54 +01:00
2022-12-31 13:33:02 +01:00
2022-08-25 10:33:21 +02:00
2022-10-15 11:08:36 +01:00
2022-08-22 17:55:50 -07:00
2022-09-22 13:02:10 -07:00
2023-03-30 12:49:22 +02:00
2023-03-17 08:50:32 +01:00
2023-03-11 13:55:24 +01:00
2023-03-17 08:50:24 +01:00
2023-04-06 12:10:52 +02:00
2023-02-09 11:28:04 +01:00
2023-03-17 08:50:24 +01:00
2023-02-22 12:59:52 +01:00
2023-03-30 12:49:09 +02:00
2022-08-25 10:33:21 +02:00
2023-01-24 07:24:31 +01:00
2023-04-06 12:10:58 +02:00
2022-10-07 09:29:17 +02:00
2023-03-30 12:49:09 +02:00
2023-03-30 12:49:09 +02:00
2023-03-22 13:33:50 +01:00
2022-11-15 12:42:26 +01:00
2022-11-22 07:14:55 +01:00
2023-03-10 09:33:07 +01:00
2022-06-09 21:52:55 -07:00
2023-04-13 16:55:19 +02:00
2022-12-05 09:53:08 +01:00
2023-02-06 08:06:34 +01:00
2023-02-22 12:59:53 +01:00
2023-03-30 12:49:00 +02:00
2022-08-29 12:47:15 +01:00
2023-03-22 13:33:42 +01:00
2022-08-29 12:47:15 +01:00
2023-02-01 08:34:45 +01:00
2023-02-09 11:28:06 +01:00
2023-03-17 08:50:17 +01:00
2023-02-22 12:59:52 +01:00
2022-11-29 08:30:18 -08:00
2022-08-29 12:47:15 +01:00
2023-04-13 16:55:20 +02:00
2023-03-10 09:33:02 +01:00
2023-02-22 12:59:42 +01:00
2022-12-31 13:32:55 +01:00
2023-03-30 12:49:20 +02:00
2023-03-11 13:55:26 +01:00
2023-03-22 13:33:47 +01:00
2022-07-08 18:38:44 -07:00
2023-04-06 12:10:44 +02:00
2022-06-09 21:52:55 -07:00
2023-02-22 12:59:53 +01:00
2023-03-17 08:50:26 +01:00
2023-03-17 08:50:28 +01:00
2022-12-31 13:32:26 +01:00
2023-03-22 13:33:43 +01:00
2023-02-09 11:28:13 +01:00
2023-03-30 12:49:02 +02:00
2023-04-06 12:10:37 +02:00
2023-02-09 11:28:04 +01:00
2022-08-22 14:26:30 +01:00
2022-09-20 14:23:56 -07:00
2022-08-22 14:26:30 +01:00
2023-03-10 09:34:34 +01:00