Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karl Mehltretter" <kmehltretter@gmail.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	dmitry.torokhov@gmail.com,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-input@vger.kernel.org,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3 1/6] virtio_ccw: fix synchronize_cbs() after interrupt fallback
Date: Tue, 08 Sep 2026 05:50:11 +0000	[thread overview]
Message-ID: <20260908055011.87FB01F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260908053817.26065-2-kmehltretter@gmail.com>

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

Pre-existing issues:
- [Critical] virtio_ccw_reset() silently fails to reset the device if ccw allocation fails, risking use-after-free and DMA corruption.
- [High] virtio_ccw_del_vqs silently aborts on memory allocation failure, permanently leaking all virtqueues and their DMA memory.
- [High] Silent allocation failure in virtio_ccw_drop_indicator leaves stale virtqueue pointers in global routing tables, leading to UAF when adapter interrupts fire.
--

commit bd43fb4d1f3ef8003538155a318dcf69a27e4625
Author: Karl Mehltretter <kmehltretter@gmail.com>

virtio_ccw: fix synchronize_cbs() after interrupt fallback

virtio_ccw_synchronize_cbs() assumes the device uses adapter interrupts
when vcdev->airq_info is not NULL. If registering adapter indicators
fails, virtio_ccw_find_vqs() falls back to classic interrupts but can
leave airq_info set. This patch uses vcdev->is_thinint to properly
select the lock.

> diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
> index bab6cad3fd5ce..b90299205698b 100644
> --- a/drivers/s390/virtio/virtio_ccw.c
> +++ b/drivers/s390/virtio/virtio_ccw.c
> @@ -1062,7 +1062,7 @@ static void virtio_ccw_synchronize_cbs(struct virtio_device *vdev)
>  	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
>  	struct airq_info *info = vcdev->airq_info;
>  
> -	if (info) {
> +	if (vcdev->is_thinint && info) {
>  		/*
>  		 * This device uses adapter interrupts: synchronize with
>  		 * vring_interrupt() called by virtio_airq_handler()

[ ... ]

> static void virtio_ccw_drop_indicator(struct virtio_ccw_device *vcdev,
> 				      struct ccw1 *ccw)
> {
> 	int ret;
> 	struct virtio_thinint_area *thinint_area = NULL;
> 	struct airq_info *airq_info = vcdev->airq_info;
> 	dma64_t *indicatorp = NULL;
> 
> 	if (vcdev->is_thinint) {
> 		thinint_area = ccw_device_dma_zalloc(vcdev->cdev,
> 						     sizeof(*thinint_area),
> 						     &ccw->cda);
> 		if (!thinint_area)
> 			return;

[Severity: High]
This is a pre-existing issue, but returning early here on allocation failure
skips deregistering indicators and removing stale pointers from the global
airq_areas array.

If ccw_device_dma_zalloc() fails, the caller virtio_ccw_del_vqs() continues
and frees all virtqueues, while the global airq_areas array retains pointers
to them.

A subsequent adapter interrupt in virtio_airq_handler() could then fetch the
stale pointer:

	vring_interrupt(0, (void *)airq_iv_get_ptr(info->aiv, ai));

and trigger a use-after-free on the freed virtqueue memory.

Does this early return need to gracefully handle indicator deregistration
when allocation fails?

[ ... ]

> static void virtio_ccw_del_vqs(struct virtio_device *vdev)
> {
> 	struct virtqueue *vq, *n;
> 	struct ccw1 *ccw;
> 	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> 
> 	ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw), NULL);
> 	if (!ccw)
> 		return;

[Severity: High]
This isn't a bug introduced by this patch, but returning early on allocation
failure skips the teardown loop entirely.

This leaks all virtqueues and their DMA memory. Since the virtqueues are not
deregistered from the host or removed from the global airq_areas routing
array, the virtio core will subsequently free the parent virtio_ccw_device.

A later adapter interrupt could invoke vring_interrupt() on the leaked
virtqueue, holding a stale pointer to the freed device and potentially
causing a use-after-free.

Should this fallback to a safe teardown path if ccw allocation fails?

[ ... ]

> static void virtio_ccw_reset(struct virtio_device *vdev)
> {
> 	struct virtio_ccw_device *vcdev = to_vc_device(vdev);
> 	struct ccw1 *ccw;
> 
> 	ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw), NULL);
> 	if (!ccw)
> 		return;

[Severity: Critical]
This is a pre-existing issue, but this silent return bypasses sending the
CCW_CMD_VDEV_RESET command to the host if allocation fails.

The virtio core assumes the device is fully quiesced after virtio_ccw_reset()
returns and proceeds to free virtqueues and data buffers. Since the device on
the host was never actually reset, the hardware state machine remains active
and may continue to execute pending DMA operations into the now-freed memory,
causing critical data corruption.

How should we ensure the device is safely quiesced if ccw allocation fails?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908053817.26065-1-kmehltretter@gmail.com?part=1

  reply	other threads:[~2026-09-08  5:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  5:38 [PATCH v3 0/6] virtio: fix and add callback synchronization hooks Karl Mehltretter
2026-09-08  5:38 ` [PATCH v3 1/6] virtio_ccw: fix synchronize_cbs() after interrupt fallback Karl Mehltretter
2026-09-08  5:50   ` sashiko-bot [this message]
2026-09-08  5:38 ` [PATCH v3 2/6] virtio_ccw: always take irq_lock in the classic interrupt handler Karl Mehltretter
2026-09-08  5:51   ` sashiko-bot
2026-09-08  8:14     ` Michael S. Tsirkin
2026-09-08  5:38 ` [PATCH v3 3/6] remoteproc: implement synchronize_cbs() for virtio devices Karl Mehltretter
2026-09-08  5:54   ` sashiko-bot
2026-09-08  5:38 ` [PATCH v3 4/6] um: virtio_uml: implement synchronize_cbs() Karl Mehltretter
2026-09-08  5:50   ` sashiko-bot
2026-09-08  5:38 ` [PATCH v3 5/6] platform/mellanox: mlxbf-tmfifo: " Karl Mehltretter
2026-09-08  5:52   ` sashiko-bot
2026-09-08  5:38 ` [PATCH v3 6/6] virtio_vdpa: " Karl Mehltretter
2026-09-08  5:51   ` sashiko-bot
2026-09-08  8:31     ` Michael S. Tsirkin
2026-09-08  8:06 ` [PATCH v3 0/6] virtio: fix and add callback synchronization hooks Michael S. Tsirkin
2026-09-08  8:25 ` Michael S. Tsirkin

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=20260908055011.87FB01F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kmehltretter@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-input@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