* [PATCH] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
@ 2026-01-27 7:22 Jiakai Xu
2026-01-28 15:08 ` Anup Patel
2026-02-20 4:11 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Jiakai Xu @ 2026-01-27 7:22 UTC (permalink / raw)
To: linux-kernel, linux-riscv, kvm-riscv, kvm
Cc: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Jiakai Xu, Jiakai Xu
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: 5463091a51cfaa ("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>
---
arch/riscv/kvm/aia_imsic.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c
index e597e86491c3b..bd7081e70036d 100644
--- a/arch/riscv/kvm/aia_imsic.c
+++ b/arch/riscv/kvm/aia_imsic.c
@@ -952,8 +952,10 @@ int kvm_riscv_aia_imsic_rw_attr(struct kvm *kvm, unsigned long type,
if (!vcpu)
return -ENODEV;
- isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
imsic = vcpu->arch.aia_context.imsic_state;
+ if (!imsic)
+ return -ENODEV;
+ isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
read_lock_irqsave(&imsic->vsfile_lock, flags);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
2026-01-27 7:22 [PATCH] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr() Jiakai Xu
@ 2026-01-28 15:08 ` Anup Patel
2026-02-20 4:11 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Anup Patel @ 2026-01-28 15:08 UTC (permalink / raw)
To: Jiakai Xu
Cc: linux-kernel, linux-riscv, kvm-riscv, kvm, Atish Patra,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Jiakai Xu
On Tue, Jan 27, 2026 at 12:52 PM Jiakai Xu <jiakaipeanut@gmail.com> wrote:
>
> 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: 5463091a51cfaa ("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>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Queued this for Linux-6.20
Thanks,
Anup
> ---
> arch/riscv/kvm/aia_imsic.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c
> index e597e86491c3b..bd7081e70036d 100644
> --- a/arch/riscv/kvm/aia_imsic.c
> +++ b/arch/riscv/kvm/aia_imsic.c
> @@ -952,8 +952,10 @@ int kvm_riscv_aia_imsic_rw_attr(struct kvm *kvm, unsigned long type,
> if (!vcpu)
> return -ENODEV;
>
> - isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
> imsic = vcpu->arch.aia_context.imsic_state;
> + if (!imsic)
> + return -ENODEV;
> + isel = KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(type);
>
> read_lock_irqsave(&imsic->vsfile_lock, flags);
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
2026-01-27 7:22 [PATCH] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr() Jiakai Xu
2026-01-28 15:08 ` Anup Patel
@ 2026-02-20 4:11 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2026-02-20 4:11 UTC (permalink / raw)
To: eanut 6
Cc: linux-riscv, linux-kernel, kvm-riscv, kvm, anup, atish.patra,
pjw, palmer, aou, alex, xujiakai2025, jiakaiPeanut
Hello:
This patch was applied to riscv/linux.git (fixes)
by Anup Patel <anup@brainfault.org>:
On Tue, 27 Jan 2026 07:22:19 +0000 you wrote:
> 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]
> ...
>
> [...]
Here is the summary with links:
- RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr()
https://git.kernel.org/riscv/c/aeb1d17d1af5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-20 4:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-27 7:22 [PATCH] RISC-V: KVM: Fix null pointer dereference in kvm_riscv_aia_imsic_rw_attr() Jiakai Xu
2026-01-28 15:08 ` Anup Patel
2026-02-20 4:11 ` patchwork-bot+linux-riscv
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®