From: sashiko-bot@kernel.org
To: "Anthony Krowiak" <akrowiak@linux.ibm.com>
Cc: kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
linux-s390@vger.kernel.org
Subject: Re: [PATCH] s390/vfio-ap: fix stale pqap_hook pointer on error in vfio_ap_mdev_set_kvm()
Date: Wed, 22 Jul 2026 14:23:34 +0000 [thread overview]
Message-ID: <20260722142334.5BC8B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722140927.892342-1-akrowiak@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Restoring `kvm->arch.crypto.pqap_hook` to `&m->pqap_hook` after releasing update locks creates a TOCTOU race condition leading to an exploitable Use-After-Free.
--
--- Patch [1]: [PATCH] s390/vfio-ap: fix stale pqap_hook pointer on error in vfio_ap_mdev_set_kvm() ---
commit 3eedf7c518752f33e7b7b7758dc2098b54d797b9
Author: Anthony Krowiak <akrowiak@linux.ibm.com>
s390/vfio-ap: fix stale pqap_hook pointer on error in vfio_ap_mdev_set_kvm()
This commit addresses an issue where the pqap_hook pointer is left pointing
at a failing matrix_mdev when a conflicting assignment is detected. It fixes
this by restoring the hook to the legitimately attached mdev discovered
during the error path.
Cc: stable@vger.kernel.org
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 44b3a1dcc1b36..e18540fd6dc75 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
[ ... ]
> @@ -1833,6 +1839,10 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
> list_for_each_entry(m, &matrix_dev->mdev_list, node) {
> if (m != matrix_mdev && m->kvm == kvm) {
> release_update_locks_for_kvm(kvm);
> + /* Undo the hook installation since we're failing */
> + down_write(&kvm->arch.crypto.pqap_hook_rwsem);
> + kvm->arch.crypto.pqap_hook = &m->pqap_hook;
[Severity: Critical]
Is there a race condition introduced here since the update locks are released
right before restoring the hook pointer?
Looking at vfio_ap_mdev_set_kvm() in drivers/s390/crypto/vfio_ap_ops.c,
release_update_locks_for_kvm() drops the mutexes that protect the mdev
list. Once those locks are dropped, could another thread concurrently remove
and free the existing mdev (m)?
If m is freed while we are waiting to acquire the pqap_hook_rwsem, this code
would then assign a dangling pointer to kvm->arch.crypto.pqap_hook. Later,
when the guest executes a PQAP instruction, it might dereference this freed
memory, resulting in a use-after-free.
Would it be safer to restore the hook pointer before calling
release_update_locks_for_kvm() to ensure m remains valid?
> + up_write(&kvm->arch.crypto.pqap_hook_rwsem);
> return -EPERM;
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260722140927.892342-1-akrowiak@linux.ibm.com?part=1
next prev parent reply other threads:[~2026-07-22 14:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 14:09 [PATCH] s390/vfio-ap: fix stale pqap_hook pointer on error in vfio_ap_mdev_set_kvm() Anthony Krowiak
2026-07-22 14:23 ` sashiko-bot [this message]
2026-07-28 16:10 ` Anthony Krowiak
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=20260722142334.5BC8B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akrowiak@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@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