aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRadim Krčmář <rkrcmar@ventanamicro.com>2025-08-05 12:44:21 +0200
committerAnup Patel <anup@brainfault.org>2025-08-25 10:26:20 +0530
commit799766208f09f95677a9ab111b93872d414fbad7 (patch)
tree8e90fcf0e0d6686d6a5507a865cfcef8178e93c1
parentRISC-V: KVM: Correct kvm_riscv_check_vcpu_requests() comment (diff)
downloadwireguard-linux-799766208f09f95677a9ab111b93872d414fbad7.tar.xz
wireguard-linux-799766208f09f95677a9ab111b93872d414fbad7.zip
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: 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>
-rw-r--r--arch/riscv/kvm/vcpu_vector.c2
1 files changed, 2 insertions, 0 deletions
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(&reg_val, uaddr, reg_size))
return -EFAULT;
if (reg_val != cntx->vector.vlenb)