Skip to content

Commit fdb69d4

Browse files
6eanutavpatel
authored andcommitted
RISC-V: KVM: Fix NULL pointer dereference in SBI v0.1 SEND_IPI handler
The SBI v0.1 SEND_IPI handler iterates over the hart mask and calls kvm_get_vcpu_by_id() to find the target vcpu for each set bit. When a guest provides a hart mask containing bits for non-existent vcpu_ids, kvm_get_vcpu_by_id() returns NULL, which is then unconditionally dereferenced by kvm_riscv_vcpu_set_interrupt(), causing a kernel crash. Fix this by adding a NULL check before dereferencing the return value. If the target vcpu is not found, skip it and continue processing the remaining valid harts. Fixes: a046c2d ("RISC-V: KVM: Reorganize SBI code by moving SBI v0.1 to its own file") Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Assisted-by: OpenClaw:DeepSeek-V3.2 Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260517124414.420919-1-xujiakai2025@iscas.ac.cn Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 0e9d0e7 commit fdb69d4

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/riscv/kvm/vcpu_sbi_v01.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
5555

5656
for_each_set_bit(i, &hmask, BITS_PER_LONG) {
5757
rvcpu = kvm_get_vcpu_by_id(vcpu->kvm, i);
58+
if (!rvcpu)
59+
continue;
5860
ret = kvm_riscv_vcpu_set_interrupt(rvcpu, IRQ_VS_SOFT);
5961
if (ret < 0)
6062
break;

0 commit comments

Comments
 (0)