All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
	kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v3 01/10] KVM: s390: Fix unlikely NULL gmap dereference
Date: Mon, 27 Jul 2026 15:24:55 +0000	[thread overview]
Message-ID: <20260727152455.DCB331F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727150254.236021-2-imbrenda@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing compiler barrier in vCPU initialization publication allows compiler reordering, potentially defeating the NULL pointer dereference fix.
--

--- Patch [1]: [PATCH v3 01/10] KVM: s390: Fix unlikely NULL gmap dereference ---
commit 5328cd0469f8706fce5babcef6c93d98cfcef985
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>

KVM: s390: Fix unlikely NULL gmap dereference

This commit fixes a potential NULL pointer dereference if a malicious
userspace program guesses a newly created vCPU file descriptor and
starts it before kvm_arch_vcpu_postcreate() finishes. It adds an
initialized flag that is checked before allowing vCPU ioctls to run.

> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index 23c817595e28d..eff0644b8517d 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);

[Severity: High]
Could the compiler reorder the gmap assignment after this WRITE_ONCE()?

Since WRITE_ONCE() only guarantees volatile access but does not provide a
general compiler barrier, it might be possible for the compiler to legally
reorder the preceding non-volatile store (vcpu->arch.gmap = ...) to occur
after the initialized flag is set.

If this happens, a concurrent thread could read initialized as true but
still observe a NULL gmap in __vcpu_run(), triggering the exact crash this
patch intends to fix. 

Would it be safer to use smp_store_release() here to ensure the gmap
initialization is safely published?

>  }
>  
>  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 (!READ_ONCE(vcpu->arch.initialized))
> +		return -EINVAL;

[Severity: High]
If smp_store_release() is used in kvm_arch_vcpu_postcreate(), would it make
sense to use smp_load_acquire() here to properly pair with it and guarantee
we observe the fully initialized vCPU state?

> +
>  	vcpu_load(vcpu);
>  
>  	if (guestdbg_exit_pending(vcpu)) {

[ ... ]

> @@ -5521,6 +5526,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
>  	long r;
>  	u16 rc, rrc;
>  
> +	if (!READ_ONCE(vcpu->arch.initialized))
> +		return -EINVAL;

[Severity: High]
Similarly, should this be smp_load_acquire() to ensure memory visibility
guarantees match across all the vCPU ioctl paths?

> +
>  	vcpu_load(vcpu);
>  
>  	switch (ioctl) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727150254.236021-1-imbrenda@linux.ibm.com?part=1

  reply	other threads:[~2026-07-27 15:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 15:02 [PATCH v3 00/10] KVM: s390: Misc fixes Claudio Imbrenda
2026-07-27 15:02 ` [PATCH v3 01/10] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-07-27 15:24   ` sashiko-bot [this message]
2026-07-27 15:02 ` [PATCH v3 02/10] KVM: s390: Fix leaking of PGM_ADDRESSING to userspace Claudio Imbrenda
2026-07-27 15:33   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 03/10] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
2026-07-27 15:43   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 04/10] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
2026-07-27 16:03   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 05/10] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
2026-07-27 16:14   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 06/10] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-07-27 16:33   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 07/10] KVM: s390: Return -EINTR if a signal was pending while faulting-in Claudio Imbrenda
2026-07-27 16:59   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 08/10] KVM: s390: Free the mmu cache when kvm_arch_vcpu_create() fails Claudio Imbrenda
2026-07-27 17:06   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 09/10] KVM: s390: Fix ordering when adding to SCA Claudio Imbrenda
2026-07-27 17:12   ` sashiko-bot
2026-07-27 15:02 ` [PATCH v3 10/10] KVM: s390: Fix cleanup in kvm_s390_pv_create_cpu() Claudio Imbrenda
2026-07-27 17:18   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260727152455.DCB331F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.