Skip to content

Commit 4f3dbdf

Browse files
Wanpeng Libonzini
Wanpeng Li
authored andcommitted
KVM: eventfd: fix NULL deref irqbypass consumer
Reported syzkaller: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 IP: irq_bypass_unregister_consumer+0x9d/0xb70 [irqbypass] PGD 0 Oops: 0002 [#1] SMP CPU: 1 PID: 125 Comm: kworker/1:1 Not tainted 4.9.0+ #1 Workqueue: kvm-irqfd-cleanup irqfd_shutdown [kvm] task: ffff9bbe0dfbb900 task.stack: ffffb61802014000 RIP: 0010:irq_bypass_unregister_consumer+0x9d/0xb70 [irqbypass] Call Trace: irqfd_shutdown+0x66/0xa0 [kvm] process_one_work+0x16b/0x480 worker_thread+0x4b/0x500 kthread+0x101/0x140 ? process_one_work+0x480/0x480 ? kthread_create_on_node+0x60/0x60 ret_from_fork+0x25/0x30 RIP: irq_bypass_unregister_consumer+0x9d/0xb70 [irqbypass] RSP: ffffb61802017e20 CR2: 0000000000000008 The syzkaller folks reported a NULL pointer dereference that due to unregister an consumer which fails registration before. The syzkaller creates two VMs w/ an equal eventfd occasionally. So the second VM fails to register an irqbypass consumer. It will make irqfd as inactive and queue an workqueue work to shutdown irqfd and unregister the irqbypass consumer when eventfd is closed. However, the second consumer has been initialized though it fails registration. So the token(same as the first VM's) is taken to unregister the consumer through the workqueue, the consumer of the first VM is found and unregistered, then NULL deref incurred in the path of deleting consumer from the consumers list. This patch fixes it by making irq_bypass_register/unregister_consumer() looks for the consumer entry based on consumer pointer itself instead of token matching. Reported-by: Dmitry Vyukov <[email protected]> Suggested-by: Alex Williamson <[email protected]> Cc: [email protected] Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Alex Williamson <[email protected]> Signed-off-by: Wanpeng Li <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 129a72a commit 4f3dbdf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

virt/lib/irqbypass.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
195195
mutex_lock(&lock);
196196

197197
list_for_each_entry(tmp, &consumers, node) {
198-
if (tmp->token == consumer->token) {
198+
if (tmp->token == consumer->token || tmp == consumer) {
199199
mutex_unlock(&lock);
200200
module_put(THIS_MODULE);
201201
return -EBUSY;
@@ -245,7 +245,7 @@ void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
245245
mutex_lock(&lock);
246246

247247
list_for_each_entry(tmp, &consumers, node) {
248-
if (tmp->token != consumer->token)
248+
if (tmp != consumer)
249249
continue;
250250

251251
list_for_each_entry(producer, &producers, node) {

0 commit comments

Comments
 (0)