RISC-V: KVM: fix stack overrun when loading vlenb
Subsystems (4)
PATCH 1/1 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 <[email protected]>
Signed-off-by Radim Krčmář <[email protected]>
--- arch/riscv/kvm/vcpu_vector.c | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/kvm/vcpu_vector.c +2 -0
@@ -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 (®_val, uaddr, reg_size))return -EFAULT ;if (reg_val != cntx->vector.vlenb)
Signature · 1 line
2.50.0
Quoted 7 lines · Radim Krčmář
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 <[email protected]>Signed-off-by Radim Krčmář <[email protected]>---
Reviewed-by Daniel Henrique Barboza <[email protected]>
Quoted 16 lines
arch/riscv/kvm/vcpu_vector.c | 2 ++ 1 file changed, 2 insertions(+)arch/riscv/kvm/vcpu_vector.c +2
-0@@ -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 (®_val, uaddr, reg_size))return -EFAULT ;if (reg_val != cntx->vector.vlenb)
Quoted 7 lines · Radim Krčmář
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 <[email protected]>Signed-off-by Radim Krčmář <[email protected]>---
Reviewed-by Nutty Liu <[email protected]>
Thanks,
Nutty
Quoted 16 lines
arch/riscv/kvm/vcpu_vector.c | 2 ++ 1 file changed, 2 insertions(+)arch/riscv/kvm/vcpu_vector.c +2
-0@@ -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 (®_val, uaddr, reg_size))return -EFAULT ;if (reg_val != cntx->vector.vlenb)
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Anup Patel
maintainerQuoted 7 lines · Radim Krčmář
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 <[email protected]>Signed-off-by Radim Krčmář <[email protected]>
Queued this as a fix for Linux-6.17
Thanks,
Anup
Quoted 20 lines
--- arch/riscv/kvm/vcpu_vector.c | 2 ++ 1 file changed, 2 insertions(+)arch/riscv/kvm/vcpu_vector.c +2
-1@@ -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 (®_val, uaddr, reg_size))return -EFAULT ;if (reg_val != cntx->vector.vlenb) --2.50.0