[PATCH] RISC-V: KVM: Validate SBI STA shmem alignment in kvm_sbi_ext_sta_set_reg
eanut 6
jiakaipeanut at gmail.com
Fri Jan 30 16:15:44 PST 2026
Thanks for the review.
I’ll send a v2 shortly with these changes.
Thanks,
Jiakai
On Sat, Jan 31, 2026 at 4:48 AM Andrew Jones
<andrew.jones at oss.qualcomm.com> wrote:
>
> On Sat, Jan 24, 2026 at 02:20:42AM +0000, Jiakai Xu wrote:
> ...
> > diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c
> > index afa0545c3bcfc..7dfe671c42eaa 100644
> > --- a/arch/riscv/kvm/vcpu_sbi_sta.c
> > +++ b/arch/riscv/kvm/vcpu_sbi_sta.c
> > @@ -186,23 +186,25 @@ static int kvm_sbi_ext_sta_set_reg(struct kvm_vcpu *vcpu, unsigned long reg_num,
> > return -EINVAL;
> > value = *(const unsigned long *)reg_val;
> >
> > + gpa_t new_shmem = vcpu->arch.sta.shmem;
>
> Please declare new_shmem at the top of the function and there's no
> need to initialize it to vcpu->arch.sta.shmem. Actually it appears you
> meant to initialize it to NULL, based on the 'if (new_shmem ...)' check
> below.
>
> > +
> > switch (reg_num) {
> > case KVM_REG_RISCV_SBI_STA_REG(shmem_lo):
> > if (IS_ENABLED(CONFIG_32BIT)) {
> > gpa_t hi = upper_32_bits(vcpu->arch.sta.shmem);
> >
> > - vcpu->arch.sta.shmem = value;
> > - vcpu->arch.sta.shmem |= hi << 32;
> > + new_shmem = value;
> > + new_shmem |= hi << 32;
> > } else {
> > - vcpu->arch.sta.shmem = value;
> > + new_shmem = value;
> > }
> > break;
> > case KVM_REG_RISCV_SBI_STA_REG(shmem_hi):
> > if (IS_ENABLED(CONFIG_32BIT)) {
> > gpa_t lo = lower_32_bits(vcpu->arch.sta.shmem);
> >
> > - vcpu->arch.sta.shmem = ((gpa_t)value << 32);
> > - vcpu->arch.sta.shmem |= lo;
> > + new_shmem = ((gpa_t)value << 32);
> > + new_shmem |= lo;
> > } else if (value != 0) {
> > return -EINVAL;
> > }
> > @@ -210,7 +212,10 @@ static int kvm_sbi_ext_sta_set_reg(struct kvm_vcpu *vcpu, unsigned long reg_num,
> > default:
> > return -ENOENT;
> > }
>
> Please add a blank line here.
>
> > + if (new_shmem && !IS_ALIGNED(new_shmem, 64))
> > + return -EINVAL;
> >
> > + vcpu->arch.sta.shmem = new_shmem;
>
> And another blank line here.
>
> > return 0;
> > }
> >
> > --
> > 2.34.1
> >
>
> Thanks,
> drew
More information about the kvm-riscv
mailing list