[PATCH] RISC-V: KVM: fix stack overrun when loading vlenb
Anup Patel
anup at brainfault.org
Fri Aug 22 04:28:52 PDT 2025
On Tue, Aug 5, 2025 at 4:24 PM Radim Krčmář <rkrcmar at ventanamicro.com> wrote:
>
> The userspace load can put up to 2048 bits into an xlen bit stack
> buffer. We want only xlen bits, so check the size beforehand.
>
> Fixes: 2fa290372dfe ("RISC-V: KVM: add 'vlenb' Vector CSR")
> Cc: <stable at vger.kernel.org>
> Signed-off-by: Radim Krčmář <rkrcmar at ventanamicro.com>
Queued this as a fix for Linux-6.17
Thanks,
Anup
> ---
> arch/riscv/kvm/vcpu_vector.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/riscv/kvm/vcpu_vector.c b/arch/riscv/kvm/vcpu_vector.c
> index a5f88cb717f3..05f3cc2d8e31 100644
> --- a/arch/riscv/kvm/vcpu_vector.c
> +++ b/arch/riscv/kvm/vcpu_vector.c
> @@ -182,6 +182,8 @@ int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu,
> struct kvm_cpu_context *cntx = &vcpu->arch.guest_context;
> unsigned long reg_val;
>
> + if (reg_size != sizeof(reg_val))
> + return -EINVAL;
> if (copy_from_user(®_val, uaddr, reg_size))
> return -EFAULT;
> if (reg_val != cntx->vector.vlenb)
> --
> 2.50.0
>
More information about the kvm-riscv
mailing list