All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Krowiak <akrowiak@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-s390@vger.kernel.org, Vasily Gorbik <gor@linux.ibm.com>,
	kvm@vger.kernel.org, Alexander Gordeev <agordeev@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Halil Pasic <pasic@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>
Subject: Re: [PATCH] s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL
Date: Fri, 7 Aug 2026 18:24:14 -0400	[thread overview]
Message-ID: <3a7b85c4-60d5-40d4-ac86-0fc52a06fe47@linux.ibm.com> (raw)
In-Reply-To: <20260807151809.CEF971F00A3A@smtp.kernel.org>



On 8/7/26 11:18 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Incorrect bitwise operation `bitmap_andnot` used instead of `bitmap_and` for control domains in `vfio_ap_mdev_cfg_remove`, preventing removal of unplugged domains.
> --
>
> --- Patch [1]: [PATCH] s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL ---
> commit 7ae73def648a068715a8cdb4bf574ac5755f8e77
> Author: Anthony Krowiak <akrowiak@linux.ibm.com>
>
> s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL
>
> This commit adds NULL pointer checks for matrix_mdev->kvm prior to taking
> the kvm->lock mutex in the configuration change and scan complete callbacks.
> This prevents a NULL pointer dereference when the matrix mdev has no
> associated KVM instance.
>
> 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..a0b7c37fee281 100644
>> --- a/drivers/s390/crypto/vfio_ap_ops.c
>> +++ b/drivers/s390/crypto/vfio_ap_ops.c
>> @@ -2606,7 +2606,15 @@ static void vfio_ap_mdev_cfg_remove(unsigned long *ap_remove,
>>   	int do_remove = 0;
>>   
>>   	list_for_each_entry(matrix_mdev, &matrix_dev->mdev_list, node) {
>> -		mutex_lock(&matrix_mdev->kvm->lock);
>> +		/*
>> +		 * If the mdev is attached to a KVM guest, we will need to
>> +		 * hold the KVM lock in order to update the guest's AP
>> +		 * configuration if any adapters, domains or control domains
>> +		 * have been removed.
>> +		 */
>> +		if (matrix_mdev->kvm)
>> +			mutex_lock(&matrix_mdev->kvm->lock);
>> +
>>   		mutex_lock(&matrix_dev->mdevs_lock);
>>   
>>   		do_remove |= bitmap_and(aprem, ap_remove,
> [Severity: High]
> This is a pre-existing issue, but I noticed a potential logic flaw just
> below this context in vfio_ap_mdev_cfg_remove() within
> drivers/s390/crypto/vfio_ap_ops.c.
>
> Does the control domain removal incorrectly use bitmap_andnot() instead of
> bitmap_and()?
>
> When a host administrator or hypervisor unplugs a control domain, the code
> evaluates the removed domains using:
>
> 	do_remove |= bitmap_andnot(cdrem, cd_remove,
> 				   matrix_mdev->matrix.adm,
> 				   AP_DOMAINS);
>
> Since this evaluates to cd_remove & ~matrix_mdev->matrix.adm, doesn't this
> mean assigned domains that were removed from the host will resolve to 0?
>
> Could this prevent explicitly unplugged control domains from being removed
> from the KVM guest, allowing it to retain access to hardware it shouldn't
> have?

This looks like a cut and paste error from long ago. bitmap_and should have
been used as it was for the other bitmaps instead of bitmap_andnot.

>
> [ ... ]
>


      reply	other threads:[~2026-08-07 22:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 14:54 [PATCH] s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL Anthony Krowiak
2026-08-07 15:18 ` sashiko-bot
2026-08-07 22:24   ` Anthony Krowiak [this message]

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=3a7b85c4-60d5-40d4-ac86-0fc52a06fe47@linux.ibm.com \
    --to=akrowiak@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pasic@linux.ibm.com \
    --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.