Skip to content

Commit 7997662

Browse files
radimkrcmaravpatel
authored andcommitted
RISC-V: KVM: fix stack overrun when loading vlenb
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: [email protected] Signed-off-by: Radim Krčmář <[email protected]> Reviewed-by: Nutty Liu <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent e61a12a commit 7997662

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)