* [PATCH v2 0/7] KVM: s390: Misc fixes
@ 2026-07-13 15:08 Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
` (6 more replies)
0 siblings, 7 replies; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
Fix a bunch of small issues that came up during the previous round of fixes.
They are mostly extremely unlikely races, but they should be fixed
nonetheless.
v1->v2
* Drop some patches that have been picked upstream in the meantime.
* Drop patch 3, as it was trying to fix a bug that does not exist
* Avoid the NULL gmap dereference by using a flag
* Fix the return value of kvm_s390_[gp]et_skeys too
* Use kvm->slots_arch_lock instead of kvm->slots_lock for CMMA and ESSA
handling, to avoid potential deadlocks with the RCU.
* Three new patches to fix other issues that came out while fixing the
other issues
Claudio Imbrenda (7):
KVM: s390: Fix unlikely NULL gmap dereference
KVM: s390: Return -EFAULT instead of PGM_ADDRESSING
KVM: s390: Fix race in __do_essa()
KVM: s390: cmma: Fix dirty tracking when removing memslot
KVM: s390: ucontrol: Add missing locking around gmap_remove_child()
KVM: s390: Fix overclearing ESCA in case of error
KVM: s390: Return -EINTR if a signal was pending while faulting-in
arch/s390/include/asm/kvm_host.h | 1 +
arch/s390/kvm/dat.c | 7 +++++-
arch/s390/kvm/faultin.c | 2 +-
arch/s390/kvm/kvm-s390.c | 39 ++++++++++++++++++++++++--------
arch/s390/kvm/priv.c | 5 ++--
5 files changed, 40 insertions(+), 14 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
2026-07-14 8:32 ` Steffen Eiden
2026-07-14 13:23 ` Janosch Frank
2026-07-13 15:08 ` [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING Claudio Imbrenda
` (5 subsequent siblings)
6 siblings, 2 replies; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
When creating a new vCPU, kvm_vm_ioctl_create_vcpu() will call
kvm_arch_vcpu_postcreate() after the file descriptor for the new vCPU
has been created. The new file descriptor has not been returned yet,
but a malicious userspace program could try to guess it.
If a malicious userspace program manages to start the newly created vCPU
before kvm_arch_vcpu_postcreate() is called, __vcpu_run() will try to
dereference vcpu->arch.gmap and trigger a NULL pointer dereference.
Fix this by moving the initialization of vcpu->arch.gmap into
kvm_arch_vcpu_create(), which is called before the file descriptor for
the vCPU is created.
Fixes: dafd032a15f8 ("KVM: s390: move vcpu specific initalization to a later point")
Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/include/asm/kvm_host.h | 1 +
arch/s390/kvm/kvm-s390.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index eaa34c5bd3c1..edf75b6ad20c 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -440,6 +440,7 @@ struct kvm_vcpu_arch {
bool skey_enabled;
/* Indicator if the access registers have been loaded from guest */
bool acrs_loaded;
+ bool initialized;
struct kvm_s390_pv_vcpu pv;
union diag318_info diag318_info;
struct kvm_s390_mmu_cache *mc;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 23c817595e28..374dae6dae81 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -3611,6 +3611,8 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
if (test_kvm_facility(vcpu->kvm, 74) || vcpu->kvm->arch.user_instr0 ||
vcpu->kvm->arch.user_operexec)
vcpu->arch.sie_block->ictl |= ICTL_OPEREXC;
+
+ WRITE_ONCE(vcpu->arch.initialized, true);
}
static bool kvm_has_pckmo_subfunc(struct kvm *kvm, unsigned long nr)
@@ -5037,6 +5039,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
kvm_run->kvm_dirty_regs & ~KVM_SYNC_S390_VALID_FIELDS)
return -EINVAL;
+ if (!vcpu->arch.initialized)
+ return -EINVAL;
+
vcpu_load(vcpu);
if (guestdbg_exit_pending(vcpu)) {
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
2026-07-14 8:44 ` Steffen Eiden
2026-07-13 15:08 ` [PATCH v2 3/7] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
` (4 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
If kvm_s390_set_cmma_bits() is asked to set CMMA values outside of a
memslot, PGM_ADDRESSING (5) is returned, instead of a negative error
value. Same issue with kvm_s390_{g,s}et_skeys().
Fix by returning -EFAULT whenever the return value would be > 0, which
is consistent with the behaviour before the gmap rewrite.
Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 374dae6dae81..53691aaf6534 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -2212,7 +2212,7 @@ static int kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
}
kvfree(keys);
- return r;
+ return r <= 0 ? r : -EFAULT;
}
static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
@@ -2274,7 +2274,7 @@ static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
kvm_s390_free_mmu_cache(mc);
out:
kvfree(keys);
- return r;
+ return r <= 0 ? r : -EFAULT;
}
/*
@@ -2384,7 +2384,7 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags);
- return r;
+ return r <= 0 ? r : -EFAULT;
}
/**
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 3/7] KVM: s390: Fix race in __do_essa()
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 4/7] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
` (3 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
An unlikely race between __do_essa() and kvm_s390_vm_start_migration(),
kvm_s390_vm_stop_migration(), or dat_get_cmma() was possible.
Fix by locking kvm->slots_lock. Since this is not a hot path, the
overhead of an additional mutex is negligible.
Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 9 ++++-----
arch/s390/kvm/priv.c | 5 +++--
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 53691aaf6534..9e3b8b5c6aa6 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1298,7 +1298,8 @@ static int kvm_s390_vm_set_migration(struct kvm *kvm,
{
int res = -ENXIO;
- mutex_lock(&kvm->slots_lock);
+ guard(mutex)(&kvm->slots_arch_lock);
+
switch (attr->attr) {
case KVM_S390_VM_MIGRATION_START:
res = kvm_s390_vm_start_migration(kvm);
@@ -1309,7 +1310,6 @@ static int kvm_s390_vm_set_migration(struct kvm *kvm,
default:
break;
}
- mutex_unlock(&kvm->slots_lock);
return res;
}
@@ -2996,9 +2996,8 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
r = -EFAULT;
if (copy_from_user(&args, argp, sizeof(args)))
break;
- mutex_lock(&kvm->slots_lock);
- r = kvm_s390_get_cmma_bits(kvm, &args);
- mutex_unlock(&kvm->slots_lock);
+ scoped_guard(mutex, &kvm->slots_arch_lock)
+ r = kvm_s390_get_cmma_bits(kvm, &args);
if (!r) {
r = copy_to_user(argp, &args, sizeof(args));
if (r)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index ad0ddc433a73..d4c91e416167 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -1260,8 +1260,9 @@ static int handle_essa(struct kvm_vcpu *vcpu)
/* Retry the ESSA instruction */
kvm_s390_retry_instr(vcpu);
} else {
- scoped_guard(read_lock, &vcpu->kvm->mmu_lock)
- i = __do_essa(vcpu, orc);
+ scoped_guard(mutex, &vcpu->kvm->slots_arch_lock)
+ scoped_guard(read_lock, &vcpu->kvm->mmu_lock)
+ i = __do_essa(vcpu, orc);
if (i < 0)
return i;
/* Account for the possible extra cbrl entry */
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 4/7] KVM: s390: cmma: Fix dirty tracking when removing memslot
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
` (2 preceding siblings ...)
2026-07-13 15:08 ` [PATCH v2 3/7] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
` (2 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
When a memslot is removed, all ptes that mapped the slot are cleared or
even deallocated. If this happens while the system is in migration
mode, and if cmma-dirty pages are removed, the cmma-dirty counter will
not reflect reality.
Fix by appropriately decrementing the cmma-dirty counter when removing
a memslot.
Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/dat.c | 7 ++++++-
arch/s390/kvm/kvm-s390.c | 14 ++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kvm/dat.c b/arch/s390/kvm/dat.c
index 5f1960ec982d..cc0b8b1330c2 100644
--- a/arch/s390/kvm/dat.c
+++ b/arch/s390/kvm/dat.c
@@ -844,6 +844,7 @@ static long _dat_slot_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_wal
struct slot_priv *p = walk->priv;
union crste dummy = { .val = p->token };
union pte new_pte, pte = READ_ONCE(*ptep);
+ union pgste pgste;
new_pte = _PTE_TOK(dummy.tok.type, dummy.tok.par);
@@ -851,7 +852,11 @@ static long _dat_slot_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_wal
if (pte.val == new_pte.val)
return 0;
- dat_ptep_xchg(ptep, new_pte, gfn, walk->asce, false);
+ pgste = pgste_get_lock(ptep);
+ pgste = __dat_ptep_xchg(ptep, pgste, new_pte, gfn, walk->asce, false);
+ pgste.cmma_d = 0;
+ pgste_set_unlock(ptep, pgste);
+
return 0;
}
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 9e3b8b5c6aa6..5c2408fc5a8c 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -5796,11 +5796,19 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
return 0;
}
+static long cmma_d_count_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
+{
+ if (pgste_of(ptep)->cmma_d)
+ atomic64_dec(walk->priv);
+ return 0;
+}
+
void kvm_arch_commit_memory_region(struct kvm *kvm,
struct kvm_memory_slot *old,
const struct kvm_memory_slot *new,
enum kvm_mr_change change)
{
+ const struct dat_walk_ops ops = { .pte_entry = cmma_d_count_pte, };
struct kvm_s390_mmu_cache *mc = NULL;
int rc = 0;
@@ -5814,6 +5822,12 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
}
scoped_guard(write_lock, &kvm->mmu_lock) {
+ if (kvm->arch.migration_mode && kvm->arch.use_cmma) {
+ _dat_walk_gfn_range(old->base_gfn, old->base_gfn + old->npages,
+ kvm->arch.gmap->asce, &ops, DAT_WALK_IGN_HOLES,
+ &kvm->arch.cmma_dirty_pages);
+ }
+
switch (change) {
case KVM_MR_DELETE:
rc = dat_delete_slot(mc, kvm->arch.gmap->asce, old->base_gfn, old->npages);
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child()
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
` (3 preceding siblings ...)
2026-07-13 15:08 ` [PATCH v2 4/7] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
2026-07-17 12:59 ` Steffen Eiden
2026-07-13 15:08 ` [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 7/7] KVM: s390: Return -EINTR if a signal was pending while faulting-in Claudio Imbrenda
6 siblings, 1 reply; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
gmap_remove_child() needs to be called while holding the children_lock
of the parent gmap. This was not the case in the error handling path of
kvm_arch_vcpu_create() for UCONTROL guests.
Fix by adding the missing lock.
Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 5c2408fc5a8c..fc0a884d7f54 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -3866,7 +3866,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
out_ucontrol_uninit:
if (kvm_is_ucontrol(vcpu->kvm)) {
- gmap_remove_child(vcpu->arch.gmap);
+ scoped_guard(spinlock, &vcpu->kvm->arch.gmap->children_lock)
+ gmap_remove_child(vcpu->arch.gmap);
vcpu->arch.gmap = gmap_put(vcpu->arch.gmap);
}
out_free_sie_block:
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
` (4 preceding siblings ...)
2026-07-13 15:08 ` [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
2026-07-14 12:48 ` Janosch Frank
2026-07-14 12:51 ` Christian Borntraeger
2026-07-13 15:08 ` [PATCH v2 7/7] KVM: s390: Return -EINTR if a signal was pending while faulting-in Claudio Imbrenda
6 siblings, 2 replies; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
If an attempt is made to create a vCPU with an already existing ID,
the duplicated vCPU will be destroyed. When destroying a vCPU, its
ESCA entry will be cleared. In the above scenario, the spurious
duplicate vCPU is destroyed, but the ESCA entry corresponding to the
original vCPU is cleared.
Fix by skipping clearing the ESCA entry if the vCPU creation was not
successful, i.e. if the pointer to the ESCA in the state description is
not set.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index fc0a884d7f54..6339a327a7be 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -3458,7 +3458,7 @@ static void sca_del_vcpu(struct kvm_vcpu *vcpu)
{
struct esca_block *sca = vcpu->kvm->arch.sca;
- if (!kvm_s390_use_sca_entries())
+ if (!kvm_s390_use_sca_entries() || !vcpu->arch.sie_block->scaol)
return;
clear_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 7/7] KVM: s390: Return -EINTR if a signal was pending while faulting-in
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
` (5 preceding siblings ...)
2026-07-13 15:08 ` [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
@ 2026-07-13 15:08 ` Claudio Imbrenda
6 siblings, 0 replies; 14+ messages in thread
From: Claudio Imbrenda @ 2026-07-13 15:08 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
If a signal is pending while trying to fault-in a page, return -EINTR
instead of -EAGAIN.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Fixes: e907ae530133 ("KVM: s390: Add helper functions for fault handling")
---
arch/s390/kvm/faultin.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kvm/faultin.c b/arch/s390/kvm/faultin.c
index fee80047bd94..235b9c66ce54 100644
--- a/arch/s390/kvm/faultin.c
+++ b/arch/s390/kvm/faultin.c
@@ -93,7 +93,7 @@ int kvm_s390_faultin_gfn(struct kvm_vcpu *vcpu, struct kvm *kvm, struct guest_fa
return PGM_ADDRESSING;
/* Signal pending: try again. */
if (f->pfn == KVM_PFN_ERR_SIGPENDING)
- return -EAGAIN;
+ return -EINTR;
/* Check if it's read-only memory; don't try to actually handle that case. */
if (f->pfn == KVM_PFN_ERR_RO_FAULT)
return -EOPNOTSUPP;
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
@ 2026-07-14 8:32 ` Steffen Eiden
2026-07-14 13:23 ` Janosch Frank
1 sibling, 0 replies; 14+ messages in thread
From: Steffen Eiden @ 2026-07-14 8:32 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, borntraeger, frankja, david, nrb,
schlameuss, gra
On Mon, Jul 13, 2026 at 05:08:51PM +0200, Claudio Imbrenda wrote:
> When creating a new vCPU, kvm_vm_ioctl_create_vcpu() will call
> kvm_arch_vcpu_postcreate() after the file descriptor for the new vCPU
> has been created. The new file descriptor has not been returned yet,
> but a malicious userspace program could try to guess it.
>
> If a malicious userspace program manages to start the newly created vCPU
> before kvm_arch_vcpu_postcreate() is called, __vcpu_run() will try to
> dereference vcpu->arch.gmap and trigger a NULL pointer dereference.
>
> Fix this by moving the initialization of vcpu->arch.gmap into
> kvm_arch_vcpu_create(), which is called before the file descriptor for
> the vCPU is created.
>
> Fixes: dafd032a15f8 ("KVM: s390: move vcpu specific initalization to a later point")
> Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING
2026-07-13 15:08 ` [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING Claudio Imbrenda
@ 2026-07-14 8:44 ` Steffen Eiden
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Eiden @ 2026-07-14 8:44 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, borntraeger, frankja, david, nrb,
schlameuss, gra
On Mon, Jul 13, 2026 at 05:08:52PM +0200, Claudio Imbrenda wrote:
> If kvm_s390_set_cmma_bits() is asked to set CMMA values outside of a
> memslot, PGM_ADDRESSING (5) is returned, instead of a negative error
> value. Same issue with kvm_s390_{g,s}et_skeys().
>
> Fix by returning -EFAULT whenever the return value would be > 0, which
> is consistent with the behaviour before the gmap rewrite.
>
> Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
> arch/s390/kvm/kvm-s390.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index 374dae6dae81..53691aaf6534 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -2212,7 +2212,7 @@ static int kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
> }
>
> kvfree(keys);
> - return r;
> + return r <= 0 ? r : -EFAULT;
> }
>
> static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
> @@ -2274,7 +2274,7 @@ static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
> kvm_s390_free_mmu_cache(mc);
> out:
> kvfree(keys);
> - return r;
> + return r <= 0 ? r : -EFAULT;
> }
>
> /*
> @@ -2384,7 +2384,7 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
>
> set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags);
>
> - return r;
> + return r <= 0 ? r : -EFAULT;
> }
Wouldnt it make more sense to let dat_set_cmma_bits return -EFAULT?
(there the PGM_ADDRESSING might come from)
at least change the documentation of this function that it might return
PGM_ADDRESSING in case of an error.
Similary, dat_{g,s}et_storage_keys may return -EFAULT or at least have
this behaviour documented.
Steffen
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error
2026-07-13 15:08 ` [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
@ 2026-07-14 12:48 ` Janosch Frank
2026-07-14 12:51 ` Christian Borntraeger
1 sibling, 0 replies; 14+ messages in thread
From: Janosch Frank @ 2026-07-14 12:48 UTC (permalink / raw)
To: Claudio Imbrenda, linux-kernel
Cc: kvm, linux-s390, borntraeger, david, seiden, nrb, schlameuss, gra
On 7/13/26 17:08, Claudio Imbrenda wrote:
> If an attempt is made to create a vCPU with an already existing ID,
> the duplicated vCPU will be destroyed. When destroying a vCPU, its
> ESCA entry will be cleared. In the above scenario, the spurious
> duplicate vCPU is destroyed, but the ESCA entry corresponding to the
> original vCPU is cleared.
>
> Fix by skipping clearing the ESCA entry if the vCPU creation was not
> successful, i.e. if the pointer to the ESCA in the state description is
> not set.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
> arch/s390/kvm/kvm-s390.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index fc0a884d7f54..6339a327a7be 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -3458,7 +3458,7 @@ static void sca_del_vcpu(struct kvm_vcpu *vcpu)
> {
> struct esca_block *sca = vcpu->kvm->arch.sca;
>
> - if (!kvm_s390_use_sca_entries())
> + if (!kvm_s390_use_sca_entries() || !vcpu->arch.sie_block->scaol)
> return;
>
> clear_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);
Oh boy.
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error
2026-07-13 15:08 ` [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-07-14 12:48 ` Janosch Frank
@ 2026-07-14 12:51 ` Christian Borntraeger
1 sibling, 0 replies; 14+ messages in thread
From: Christian Borntraeger @ 2026-07-14 12:51 UTC (permalink / raw)
To: Claudio Imbrenda, linux-kernel
Cc: kvm, linux-s390, frankja, david, seiden, nrb, schlameuss, gra
Am 13.07.26 um 17:08 schrieb Claudio Imbrenda:
> If an attempt is made to create a vCPU with an already existing ID,
> the duplicated vCPU will be destroyed. When destroying a vCPU, its
> ESCA entry will be cleared. In the above scenario, the spurious
> duplicate vCPU is destroyed, but the ESCA entry corresponding to the
> original vCPU is cleared.
>
> Fix by skipping clearing the ESCA entry if the vCPU creation was not
> successful, i.e. if the pointer to the ESCA in the state description is
> not set.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
> arch/s390/kvm/kvm-s390.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index fc0a884d7f54..6339a327a7be 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -3458,7 +3458,7 @@ static void sca_del_vcpu(struct kvm_vcpu *vcpu)
> {
> struct esca_block *sca = vcpu->kvm->arch.sca;
>
> - if (!kvm_s390_use_sca_entries())
> + if (!kvm_s390_use_sca_entries() || !vcpu->arch.sie_block->scaol)
> return;
I think sashiko is right and we need to consider scaol and scaoh together.>
> clear_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-07-14 8:32 ` Steffen Eiden
@ 2026-07-14 13:23 ` Janosch Frank
1 sibling, 0 replies; 14+ messages in thread
From: Janosch Frank @ 2026-07-14 13:23 UTC (permalink / raw)
To: Claudio Imbrenda, linux-kernel
Cc: kvm, linux-s390, borntraeger, david, seiden, nrb, schlameuss, gra
On 7/13/26 17:08, Claudio Imbrenda wrote:
> When creating a new vCPU, kvm_vm_ioctl_create_vcpu() will call
> kvm_arch_vcpu_postcreate() after the file descriptor for the new vCPU
> has been created. The new file descriptor has not been returned yet,
> but a malicious userspace program could try to guess it.
>
> If a malicious userspace program manages to start the newly created vCPU
> before kvm_arch_vcpu_postcreate() is called, __vcpu_run() will try to
> dereference vcpu->arch.gmap and trigger a NULL pointer dereference.
>
> Fix this by moving the initialization of vcpu->arch.gmap into
> kvm_arch_vcpu_create(), which is called before the file descriptor for
> the vCPU is created.
>
> Fixes: dafd032a15f8 ("KVM: s390: move vcpu specific initalization to a later point")
> Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Yep, that explains why other architecture have initialization tracking :)
FWIW: We could also hide the sca fix in #6 behind this flag but having
them separate is also ok
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child()
2026-07-13 15:08 ` [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
@ 2026-07-17 12:59 ` Steffen Eiden
0 siblings, 0 replies; 14+ messages in thread
From: Steffen Eiden @ 2026-07-17 12:59 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, borntraeger, frankja, david, nrb,
schlameuss, gra
On Mon, Jul 13, 2026 at 05:08:55PM +0200, Claudio Imbrenda wrote:
> gmap_remove_child() needs to be called while holding the children_lock
> of the parent gmap. This was not the case in the error handling path of
> kvm_arch_vcpu_create() for UCONTROL guests.
>
> Fix by adding the missing lock.
>
> Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-07-17 12:59 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-07-14 8:32 ` Steffen Eiden
2026-07-14 13:23 ` Janosch Frank
2026-07-13 15:08 ` [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING Claudio Imbrenda
2026-07-14 8:44 ` Steffen Eiden
2026-07-13 15:08 ` [PATCH v2 3/7] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 4/7] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
2026-07-17 12:59 ` Steffen Eiden
2026-07-13 15:08 ` [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-07-14 12:48 ` Janosch Frank
2026-07-14 12:51 ` Christian Borntraeger
2026-07-13 15:08 ` [PATCH v2 7/7] KVM: s390: Return -EINTR if a signal was pending while faulting-in Claudio Imbrenda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox