KVM: s390: Even more fixes. And then... even more fixes
Christian Borntraeger
maintainercover KVM: s390: Even more fixes. And then... even more fixes
More AI reported fixes all over the place.
Christian Borntraeger (4):
KVM: s390: keyop: use mmu_lock to read gmap->asce
KVM: s390: vsie: zero stale crypto bits
KVM: s390: pv: Fix rc/rrc offset for PVM_DUMP
KVM: s390: Restore sigset on error path
arch/s390/kvm/kvm-s390.c | 11 +++++++---- arch/s390/kvm/vsie.c | 1 + 2 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.53.0
Christian Borntraeger
maintainerPATCH 1/4 KVM: s390: keyop: use mmu_lock to read gmap->asce
Every other dat_* consumer in this file (kvm_s390_get_skeys, set_skeys, get_cmma_bits, set_cmma_bits, MEM_CLR_CMMA, kvm_s390_fixup_prefix, kvm_test_age_gfn, kvm_age_gfn) reads kvm->arch.gmap->asce *inside* the mmu_lock read-side. keyop is the only outlier.
gmap->asce is mutated under write_lock(mmu_lock) by gmap_set_limit() and keyop might use a stale asce value for walking as KVM_S390_KEYOP and KVM_S390_VM_MEM_LIMIT_SIZE can run concurrently. This can result in memory corruption.
--- arch/s390/kvm/kvm-s390.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +2 -1
@@ -561,11 +561,12 @@ static void __kvm_s390_exit(void)static int kvm_s390_keyop (struct kvm_s390_mmu_cache *mc,struct kvm *kvm,int op,unsigned long addr,union skey skey) { -union asce asce = kvm->arch.gmap->asce;gfn_t gfn =gpa_to_gfn (addr); +union asce asce;int r;guard (read_lock)(&kvm->mmu_lock); + asce = kvm->arch.gmap->asce;switch (op) {case KVM_S390_KEYOP_SSKE :
Signature · 1 line
2.53.0
Christian Borntraeger
maintainerPATCH 2/4 KVM: s390: vsie: zero stale crypto bits
In reply to Christian BorntraegerWhen shadowing crypto access bits from a format0 apcb (crycb 0 or 1), the bits 64..255 are unchanged from whatever is in the vsie page in the crycb and thus in the apcb. This gives a nested guest potential access to a device no longer available. Zero out the remaining bits.
--- arch/s390/kvm/vsie.c | 1 + 1 file changed, 1 insertion(+)
arch/s390/kvm/vsie.c +1 -0
@@ -172,6 +172,7 @@ static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s, sizeof(struct kvm_s390_apcb0)))return -EFAULT ; +memset (apcb_s,0 ,sizeof (*apcb_s)); apcb_s->apm[0 ] = apcb_h->apm[0 ] & tmp.apm[0 ]; apcb_s->aqm[0 ] = apcb_h->aqm[0 ] & tmp.aqm[0 ] &0xffff000000000000UL ; apcb_s->adm[0 ] = apcb_h->adm[0 ] & tmp.adm[0 ] &0xffff000000000000UL ;
Signature · 1 line
2.53.0
Re: [PATCH 2/4] KVM: s390: vsie: zero stale crypto bits
Quoted 8 lines · On Tue, 11 Aug 2026 17:37:36 +0200 Christian Borntraeger…
When shadowing crypto access bits from a format0 apcb (crycb 0 or 1), the bits 64..255 are unchanged from whatever is in the vsie page in the crycb and thus in the apcb. This gives a nested guest potential access to a device no longer available. Zero out the remaining bits.
Fixes 6b79de4b056e ("KVM: s390: vsie: allow guest FORMAT-1 CRYCB on host FORMAT-2")Signed-off-by Christian Borntraeger <[email protected]>
Quoted 16 lines
--- arch/s390/kvm/vsie.c | 1 + 1 file changed, 1 insertion(+)arch/s390/kvm/vsie.c +1
-0@@ -172,6 +172,7 @@ static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s, sizeof(struct kvm_s390_apcb0)))return -EFAULT ; +memset (apcb_s,0 ,sizeof (*apcb_s)); apcb_s->apm[0 ] = apcb_h->apm[0 ] & tmp.apm[0 ]; apcb_s->aqm[0 ] = apcb_h->aqm[0 ] & tmp.aqm[0 ] &0xffff000000000000UL ; apcb_s->adm[0 ] = apcb_h->adm[0 ] & tmp.adm[0 ] &0xffff000000000000UL ;
Christian Borntraeger
maintainerPATCH 3/4 KVM: s390: pv: Fix rc/rrc offset for PVM_DUMP
In reply to Christian BorntraegerThe rc/rrc value is copied to the cmd location of the cmd in the kvm_pv_cmd structure. Fix the offset.
--- arch/s390/kvm/kvm-s390.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +1 -1
@@ -5734,7 +5734,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r =kvm_s390_handle_pv_vcpu_dump (vcpu, &cmd);/* Always copy over UV rc / rrc data */ -if (copy_to_user ((__u8 __user *)argp, &cmd.rc, +if (copy_to_user (argp + offsetof(struct kvm_pv_cmd , rc), &cmd.rc,sizeof (cmd.rc) +sizeof (cmd.rrc))) r = -EFAULT ;break ;
Signature · 1 line
2.53.0
Re: [PATCH 3/4] KVM: s390: pv: Fix rc/rrc offset for PVM_DUMP
Quoted 6 lines · On Tue, 11 Aug 2026 17:37:37 +0200 Christian Borntraeger…
The rc/rrc value is copied to the cmd location of the cmd in the
kvm_pv_cmdstructure. Fix the offset.Fixes 8aba09588d2a ("KVM: s390: Add CPU dump functionality")Signed-off-by Christian Borntraeger <[email protected]>
the documentation for KVM_S390_PV_CPU_COMMAND looks wrong, we should fix that at some point.
Quoted 17 lines
--- arch/s390/kvm/kvm-s390.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/s390/kvm/kvm-s390.c +1
-1@@ -5734,7 +5734,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r =kvm_s390_handle_pv_vcpu_dump (vcpu, &cmd);/* Always copy over UV rc / rrc data */ -if (copy_to_user ((__u8 __user *)argp, &cmd.rc, +if (copy_to_user (argp + offsetof(struct kvm_pv_cmd , rc), &cmd.rc,sizeof (cmd.rc) +sizeof (cmd.rrc))) r = -EFAULT ;break ;
Christian Borntraeger
maintainerPATCH 4/4 KVM: s390: Restore sigset on error path
In reply to Christian Borntraegerkvm_sigset_activate() installs vcpu->sigset via sigprocmask() and stashes the caller's mask in current->real_blocked; only kvm_sigset_deactivate() restores it.
For KVM_RUN on a STOPPED vcpu the error path will not restore the userspace mask. Re-arrange the error handling to also restore the signal mask.
--- arch/s390/kvm/kvm-s390.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +4 -2
@@ -5071,7 +5071,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)pr_err_ratelimited ("can't run stopped vcpu %d\n" , vcpu->vcpu_id); rc = -EINVAL ; - goto out; + goto out_sigset; }kernel_fpu_begin (&fpu,KERNEL_FPC |KERNEL_VXR );
@@ -5101,9 +5101,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)store_regs (vcpu);kernel_fpu_end (&fpu,KERNEL_FPC |KERNEL_VXR ); + vcpu->stat.exit_userspace++; + +out_sigset:kvm_sigset_deactivate (vcpu); - vcpu->stat.exit_userspace++; out:vcpu_put (vcpu);return rc;
Signature · 1 line
2.53.0
Re: [PATCH 4/4] KVM: s390: Restore sigset on error path
Quoted 11 lines · On Tue, 11 Aug 2026 17:37:38 +0200 Christian Borntraeger…
kvm_sigset_activate()installsvcpu->sigsetviasigprocmask()and stashes the caller's mask incurrent->real_blocked; onlykvm_sigset_deactivate()restores it.For
KVM_RUNon a STOPPED vcpu the error path will not restore the userspace mask. Re-arrange the error handling to also restore the signal mask.Fixes 6352e4d2dd9a3 ("KVM: s390: implement KVM_(S|G)ET_MP_STATE for user space state control")Signed-off-by Christian Borntraeger <[email protected]>
Quoted 30 lines
--- arch/s390/kvm/kvm-s390.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)arch/s390/kvm/kvm-s390.c +4
-2@@ -5071,7 +5071,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)pr_err_ratelimited ("can't run stopped vcpu %d\n" , vcpu->vcpu_id); rc = -EINVAL ; - goto out; + goto out_sigset; }kernel_fpu_begin (&fpu,KERNEL_FPC |KERNEL_VXR );@@ -5101,9 +5101,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)store_regs (vcpu);kernel_fpu_end (&fpu,KERNEL_FPC |KERNEL_VXR ); + vcpu->stat.exit_userspace++; + +out_sigset:kvm_sigset_deactivate (vcpu); - vcpu->stat.exit_userspace++; out:vcpu_put (vcpu);return rc;