linux-s390.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>
Cc: kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.vom>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH v3 7/9] KVM: s390: vsie: Fix unshadowing while shadowing
Date: Thu, 13 Aug 2026 22:43:34 +0000	[thread overview]
Message-ID: <20260813224338.9EC941F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260324174301.232921-8-imbrenda@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Missing unshadowing check in `_do_shadow_pte` and `_do_shadow_crste` leads to orphaned shadow mappings and use-after-free of host memory.
--

--- Patch [7]: [PATCH v3 7/9] KVM: s390: vsie: Fix unshadowing while shadowing ---
commit d5030d28123280edd38c0f9ad86e8a0833ab9f12
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>

KVM: s390: vsie: Fix unshadowing while shadowing

If shadowing causes the shadow gmap to get unshadowed, exit early to
prevent an attempt to dereference the parent pointer, which at this
point is NULL.

> diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
> index 70703bf866dbe..0ac2d775d4c05 100644
> --- a/arch/s390/kvm/gaccess.c
> +++ b/arch/s390/kvm/gaccess.c
> @@ -1472,6 +1472,9 @@ static int _do_shadow_crste(struct gmap *sg, gpa_t raddr, union crste *host, uni
>  		return rc;
>  
>  	do {
> +		/* _gmap_crstep_xchg_atomic() could have unshadowed this shadow gmap */
> +		if (!sg->parent)
> +			return -EAGAIN;
>  		oldcrste = READ_ONCE(*host);
>  		newcrste = _crste_fc1(f->pfn, oldcrste.h.tt, f->writable, !p);

[Severity: Critical]
This is a pre-existing issue, but since we are checking for unshadowing here,
could _gmap_crstep_xchg_atomic() unshadow the shadow gmap on the exact 
iteration where it succeeds?

If _gmap_crstep_xchg_atomic() succeeds but unshadows sg, the loop exits and
bypasses this check on the next iteration. It would then unconditionally install
the shadow entry just below the loop:

_do_shadow_crste() {
    ...
	} while (!_gmap_crstep_xchg_atomic(sg->parent, host, oldcrste, newcrste, f->gfn, false));

	newcrste = _crste_fc1(f->pfn, oldcrste.h.tt, 0, !p);
	gfn = gpa_to_gfn(raddr);
	while (!dat_crstep_xchg_atomic(table, READ_ONCE(*table), newcrste, gfn, sg->asce))
		;
    ...
}

Could this leave the guest with orphaned shadow mappings? If the host later
unmaps the page, it iterates over parent->children to invalidate shadow page
tables. Since sg was removed during unshadowing, it would fail to find and 
invalidate it, which seems like it might allow a use-after-free of host memory.

Would we need a similar check after the loop exits here, and similarly in
_do_shadow_pte() after _gmap_ptep_xchg() returns?

[ ... ]

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

  reply	other threads:[~2026-08-13 22:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 17:42 [PATCH v3 0/9] KVM: s390: More memory management fixes Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 1/9] KVM: s390: vsie: Fix dat_split_ste() Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 2/9] KVM: s390: Remove non-atomic dat_crstep_xchg() Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 3/9] KVM: s390: vsie: Fix check for pre-existing shadow mapping Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 4/9] KVM: s390: vsie: Fix nested guest memory shadowing Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 5/9] KVM: s390: Fix gmap_link() Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 6/9] KVM: s390: vsie: Fix refcount overflow for shadow gmaps Claudio Imbrenda
2026-03-24 17:42 ` [PATCH v3 7/9] KVM: s390: vsie: Fix unshadowing while shadowing Claudio Imbrenda
2026-08-13 22:43   ` sashiko-bot [this message]
2026-03-24 17:43 ` [PATCH v3 8/9] KVM: s390: vsie: Fix guest page tables protection Claudio Imbrenda
2026-03-25 12:30   ` kernel test robot
2026-08-13 23:01   ` sashiko-bot
2026-03-24 17:43 ` [PATCH v3 9/9] KVM: s390: Fix KVM_S390_VCPU_FAULT ioctl Claudio Imbrenda
2026-08-13 23:08   ` 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=20260813224338.9EC941F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.vom \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).