]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
RISC-V: KVM: fix stack overrun when loading vlenb
authorRadim Krčmář <rkrcmar@ventanamicro.com>
Tue, 5 Aug 2025 10:44:21 +0000 (12:44 +0200)
committerAnup Patel <anup@brainfault.org>
Mon, 25 Aug 2025 04:56:20 +0000 (10:26 +0530)
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@vger.kernel.org
Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com>
Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Link: https://lore.kernel.org/r/20250805104418.196023-4-rkrcmar@ventanamicro.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vcpu_vector.c

index a5f88cb717f3df3f5911815edf1185ba3d251432..05f3cc2d8e311ac62a56186b3599b5d389bf6f83 100644 (file)
@@ -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(&reg_val, uaddr, reg_size))
                        return -EFAULT;
                if (reg_val != cntx->vector.vlenb)