Skip to content

Commit 6a4194d

Browse files
radimkrcmardongert
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> (cherry picked from commit c76bf8359188a11f8fd790e5bbd6077894a245cc)
1 parent e2e45e6 commit 6a4194d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/riscv/kvm/vcpu_vector.c

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

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

0 commit comments

Comments
 (0)