WSL2-Linux-Kernel/drivers/misc
Dae R. Jeong 770d30b135 vmci_host: fix a race condition in vmci_host_poll() causing GPF
[ Upstream commit ae13381da5 ]

During fuzzing, a general protection fault is observed in
vmci_host_poll().

general protection fault, probably for non-canonical address 0xdffffc0000000019: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x00000000000000c8-0x00000000000000cf]
RIP: 0010:__lock_acquire+0xf3/0x5e00 kernel/locking/lockdep.c:4926
<- omitting registers ->
Call Trace:
 <TASK>
 lock_acquire+0x1a4/0x4a0 kernel/locking/lockdep.c:5672
 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
 _raw_spin_lock_irqsave+0xb3/0x100 kernel/locking/spinlock.c:162
 add_wait_queue+0x3d/0x260 kernel/sched/wait.c:22
 poll_wait include/linux/poll.h:49 [inline]
 vmci_host_poll+0xf8/0x2b0 drivers/misc/vmw_vmci/vmci_host.c:174
 vfs_poll include/linux/poll.h:88 [inline]
 do_pollfd fs/select.c:873 [inline]
 do_poll fs/select.c:921 [inline]
 do_sys_poll+0xc7c/0x1aa0 fs/select.c:1015
 __do_sys_ppoll fs/select.c:1121 [inline]
 __se_sys_ppoll+0x2cc/0x330 fs/select.c:1101
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x4e/0xa0 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x46/0xb0

Example thread interleaving that causes the general protection fault
is as follows:

CPU1 (vmci_host_poll)               CPU2 (vmci_host_do_init_context)
-----                               -----
// Read uninitialized context
context = vmci_host_dev->context;
                                    // Initialize context
                                    vmci_host_dev->context = vmci_ctx_create();
                                    vmci_host_dev->ct_type = VMCIOBJ_CONTEXT;

if (vmci_host_dev->ct_type == VMCIOBJ_CONTEXT) {
    // Dereferencing the wrong pointer
    poll_wait(..., &context->host_context);
}

In this scenario, vmci_host_poll() reads vmci_host_dev->context first,
and then reads vmci_host_dev->ct_type to check that
vmci_host_dev->context is initialized. However, since these two reads
are not atomically executed, there is a chance of a race condition as
described above.

To fix this race condition, read vmci_host_dev->context after checking
the value of vmci_host_dev->ct_type so that vmci_host_poll() always
reads an initialized context.

Reported-by: Dae R. Jeong <threeearcat@gmail.com>
Fixes: 8bf503991f ("VMCI: host side driver implementation.")
Signed-off-by: Dae R. Jeong <threeearcat@gmail.com>
Link: https://lore.kernel.org/r/ZCGFsdBAU4cYww5l@dragonet
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-11 23:00:32 +09:00
..
altera-stapl
bcm-vk
c2port
cardreader misc: rtsx: Fix an error handling path in rtsx_pci_probe() 2022-08-17 14:23:45 +02:00
cb710
cxl cxl: Fix refcount leak in cxl_calc_capp_routing 2022-12-31 13:14:35 +01:00
echo
eeprom eeprom: idt_89hpesx: Fix error handling in idt_init() 2023-03-10 09:39:38 +01:00
genwqe
habanalabs habanalabs/gaudi: mask constant value before cast 2022-08-25 11:40:36 +02:00
ibmasm
lis3lv02d
lkdtm lkdtm/usercopy: Expand size of "out of frame" object 2022-06-14 18:36:20 +02:00
mei mei: bus-fixup:upon error print return values of send and receive 2023-03-11 13:57:34 +01:00
ocxl ocxl: fix pci device refcount leak when calling get_function_0() 2022-12-31 13:14:29 +01:00
pvpanic misc/pvpanic: Convert regular spinlock into trylock on panic path 2022-06-14 18:36:06 +02:00
sgi-gru misc: sgi-gru: fix use-after-free error in gru_set_context_option, gru_fault and gru_handle_user_call_os 2022-12-31 13:14:29 +01:00
sgi-xp
ti-st
uacce uacce: Handle parent device removal or parent driver module rmmod 2022-08-25 11:40:34 +02:00
vmw_vmci vmci_host: fix a race condition in vmci_host_poll() causing GPF 2023-05-11 23:00:32 +09:00
Kconfig
Makefile
ad525x_dpot-i2c.c
ad525x_dpot-spi.c
ad525x_dpot.c
ad525x_dpot.h
apds990x.c
apds9802als.c
atmel-ssc.c misc: atmel-ssc: Fix IRQ check in ssc_probe 2022-06-22 14:22:00 +02:00
bh1770glc.c
cs5535-mfgpt.c
ds1682.c
dummy-irq.c
dw-xdata-pcie.c
enclosure.c
fastrpc.c misc: fastrpc: Fix use-after-free race condition for maps 2023-01-24 07:22:45 +01:00
gehc-achc.c
hi6421v600-irq.c
hisi_hikey_usb.c
hmc6352.c
hpilo.c
hpilo.h
ibmvmc.c
ibmvmc.h
ics932s401.c
isl29003.c
isl29020.c
kgdbts.c
lattice-ecp3-config.c
pch_phub.c
pci_endpoint_test.c misc: pci_endpoint_test: Fix pci_endpoint_test_{copy,write,read}() panic 2022-10-15 07:59:04 +02:00
phantom.c
qcom-coincell.c
sram-exec.c
sram.c
sram.h
tifm_7xx1.c misc: tifm: fix possible memory leak in tifm_7xx1_switch_media() 2022-12-31 13:14:29 +01:00
tifm_core.c
tsl2550.c
vmw_balloon.c misc: vmw_balloon: fix memory leak with using debugfs_lookup() 2023-03-11 13:57:38 +01:00
xilinx_sdfec.c