* [PATCH v2] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_has_attr
@ 2026-01-25 8:51 Jiakai Xu
2026-01-25 11:30 ` Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Jiakai Xu @ 2026-01-25 8:51 UTC (permalink / raw)
To: linux-kernel, linux-riscv, kvm-riscv, kvm
Cc: Alexandre Ghiti, Albert Ou, Palmer Dabbelt, Paul Walmsley,
Atish Patra, Anup Patel, Jiakai Xu
Add a null pointer check for imsic_state before dereferencing it in
kvm_riscv_aia_imsic_has_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.
This issue was discovered during fuzzing of RISC-V KVM code. The
crash occurs when userspace calls KVM_HAS_DEVICE_ATTR ioctl on an
AIA IMSIC device before the IMSIC state has been fully initialized
for a vcpu.
The crash manifests as:
Unable to handle kernel paging request at virtual address
dfffffff00000001
...
epc : kvm_riscv_aia_imsic_has_attr+0x464/0x50e
arch/riscv/kvm/aia_imsic.c:998
...
kvm_riscv_aia_imsic_has_attr+0x464/0x50e arch/riscv/kvm/aia_imsic.c:998
aia_has_attr+0x128/0x2bc arch/riscv/kvm/aia_device.c:471
kvm_device_ioctl_attr virt/kvm/kvm_main.c:4722 [inline]
kvm_device_ioctl+0x296/0x374 virt/kvm/kvm_main.c:4739
...
The fix adds a check to return -ENODEV if imsic_state is NULL, which
is consistent with other error handling in the function and prevents
the null pointer dereference.
v2: add Fixes tag and drop external link as suggested.
Fixes: 5463091a51cf ("RISC-V: KVM: Expose IMSIC registers as attributes of AIA irqchip")
Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn>
---
arch/riscv/kvm/aia_imsic.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c
index e597e86491c3b..9c58a66068447 100644
--- a/arch/riscv/kvm/aia_imsic.c
+++ b/arch/riscv/kvm/aia_imsic.c
@@ -995,6 +995,9 @@ int kvm_riscv_aia_imsic_has_attr(struct kvm *kvm, unsigned long type)
isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
imsic = vcpu->arch.aia_context.imsic_state;
+ if (!imsic)
+ return -ENODEV;
+
return imsic_mrif_isel_check(imsic->nr_eix, isel);
}
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_has_attr
2026-01-25 8:51 [PATCH v2] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_has_attr Jiakai Xu
@ 2026-01-25 11:30 ` Markus Elfring
2026-01-25 11:46 ` eanut 6
0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2026-01-25 11:30 UTC (permalink / raw)
To: Jiakai Xu, kvm, kvm-riscv, linux-riscv
Cc: Jiakai Xu, LKML, Albert Ou, Alexandre Ghiti, Anup Patel,
Atish Patra, Palmer Dabbelt, Paul Walmsley
…
> The fix adds a check to return -ENODEV if imsic_state is NULL, which
> is consistent with other error handling in the function and prevents
> the null pointer dereference.
How do you think about to move the assignment for the local variable “isel”
behind this check by another update step?
https://elixir.bootlin.com/linux/v6.19-rc5/source/arch/riscv/kvm/aia_imsic.c#L982-L999
> v2: add Fixes tag and drop external link as suggested.
Please move a patch version description behind the marker line.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc6#n785
Would it be helpful to append parentheses to a function name also in the summary phrase?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_has_attr
2026-01-25 11:30 ` Markus Elfring
@ 2026-01-25 11:46 ` eanut 6
0 siblings, 0 replies; 3+ messages in thread
From: eanut 6 @ 2026-01-25 11:46 UTC (permalink / raw)
To: Markus Elfring
Cc: Jiakai Xu, kvm, kvm-riscv, linux-riscv, LKML, Albert Ou,
Alexandre Ghiti, Anup Patel, Atish Patra, Palmer Dabbelt,
Paul Walmsley
Thanks, will address in v3.
Best regards,
Jiakai
Markus Elfring <Markus.Elfring@web.de> 于2026年1月25日周日 19:30写道:
>
> …
> > The fix adds a check to return -ENODEV if imsic_state is NULL, which
> > is consistent with other error handling in the function and prevents
> > the null pointer dereference.
>
> How do you think about to move the assignment for the local variable “isel”
> behind this check by another update step?
> https://elixir.bootlin.com/linux/v6.19-rc5/source/arch/riscv/kvm/aia_imsic.c#L982-L999
>
>
> > v2: add Fixes tag and drop external link as suggested.
>
> Please move a patch version description behind the marker line.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc6#n785
>
>
> Would it be helpful to append parentheses to a function name also in the summary phrase?
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-25 11:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-25 8:51 [PATCH v2] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_has_attr Jiakai Xu
2026-01-25 11:30 ` Markus Elfring
2026-01-25 11:46 ` eanut 6
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®