Skip to content

Commit aeb1d17

Browse files
6eanutavpatel
authored andcommitted
RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
Add a null pointer check for imsic_state before dereferencing it in kvm_riscv_aia_imsic_rw_attr(). While the function checks that the vcpu exists, it doesn't verify that the vcpu's imsic_state has been initialized, leading to a null pointer dereference when accessed. The crash manifests as: Unable to handle kernel paging request at virtual address dfffffff00000006 ... kvm_riscv_aia_imsic_rw_attr+0x2d8/0x854 arch/riscv/kvm/aia_imsic.c:958 aia_set_attr+0x2ee/0x1726 arch/riscv/kvm/aia_device.c:354 kvm_device_ioctl_attr virt/kvm/kvm_main.c:4744 [inline] kvm_device_ioctl+0x296/0x374 virt/kvm/kvm_main.c:4761 vfs_ioctl fs/ioctl.c:51 [inline] ... The fix adds a check to return -ENODEV if imsic_state is NULL and moves isel assignment after imsic_state NULL check. Fixes: 5463091 ("RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip") Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260127072219.3366607-1-xujiakai2025@iscas.ac.cn Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 11366ea commit aeb1d17

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

arch/riscv/kvm/aia_imsic.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,10 @@ int kvm_riscv_aia_imsic_rw_attr(struct kvm *kvm, unsigned long type,
952952
if (!vcpu)
953953
return -ENODEV;
954954

955-
isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
956955
imsic = vcpu->arch.aia_context.imsic_state;
956+
if (!imsic)
957+
return -ENODEV;
958+
isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
957959

958960
read_lock_irqsave(&imsic->vsfile_lock, flags);
959961

0 commit comments

Comments
 (0)