Skip to content

Commit 6d28659

Browse files
radimkrcmargregkh
authored andcommitted
RISC-V: KVM: fix stack overrun when loading vlenb
commit 7997662 upstream. 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: 2fa2903 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f57a4bd commit 6d28659

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

arch/riscv/kvm/vcpu_vector.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ int kvm_riscv_vcpu_set_reg_vector(struct kvm_vcpu *vcpu,
182182
struct kvm_cpu_context *cntx = &vcpu->arch.guest_context;
183183
unsigned long reg_val;
184184

185+
if (reg_size != sizeof(reg_val))
186+
return -EINVAL;
185187
if (copy_from_user(&reg_val, uaddr, reg_size))
186188
return -EFAULT;
187189
if (reg_val != cntx->vector.vlenb)

0 commit comments

Comments
 (0)