From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
linux-s390@vger.kernel.org
Subject: Re: [PATCH v5 06/10] s390/vfio_ccw: ensure index for read/write regions are within range
Date: Sun, 26 Jul 2026 04:16:24 +0000 [thread overview]
Message-ID: <20260726041624.B2CA61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726040129.2946151-7-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Lockless operations on the `private->crw` linked list can lead to list corruption, Use-After-Free, and double free.
- [High] Missing cancellation of background work items (`crw_work` and `io_work`) during device teardown allows them to execute on freed memory.
--
--- Patch [6]: [PATCH v5 06/10] s390/vfio_ccw: ensure index for read/write regions are within range ---
commit 9645c29c603d4b1935d8c4e94d4ecac3dcd69174
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: ensure index for read/write regions are within range
This commit clamps region indexes for read/write operations to be within
the bounds of private->num_regions. It also uses array_index_nospec() to
prevent speculative out-of-bounds access.
> diff --git a/drivers/s390/cio/vfio_ccw_chp.c b/drivers/s390/cio/vfio_ccw_chp.c
> index 38c176cf62957..f3015132d4b5f 100644
> --- a/drivers/s390/cio/vfio_ccw_chp.c
> +++ b/drivers/s390/cio/vfio_ccw_chp.c
[ ... ]
> @@ -97,6 +105,12 @@ static ssize_t vfio_ccw_crw_region_read(struct vfio_ccw_private *private,
> list_del(&crw->next);
[Severity: High]
This is a pre-existing issue, but does this locklessly dequeue elements from
private->crw and cause list corruption or use-after-free?
The userspace read syscall path calls vfio_ccw_crw_region_read(), which
dequeues elements from private->crw using list_del():
drivers/s390/cio/vfio_ccw_chp.c:vfio_ccw_crw_region_read() {
...
crw = list_first_entry_or_null(&private->crw, struct vfio_ccw_crw, next);
if (crw)
list_del(&crw->next);
...
}
Concurrently, the asynchronous hardware event path locklessly appends elements
to private->crw using list_add_tail():
drivers/s390/cio/vfio_ccw_drv.c:vfio_ccw_queue_crw() {
...
list_add_tail(&crw->next, &private->crw);
queue_work(vfio_ccw_work_q, &private->crw_work);
...
}
Could an unprivileged guest with VFIO access trigger this race by executing
a read() syscall on the CRW region concurrently with a hardware asynchronous
channel path event to crash the host kernel?
>
> mutex_lock(&private->io_mutex);
> + if (i >= private->num_regions) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + i = array_index_nospec(i, private->num_regions);
> region = private->region[i].data;
[ ... ]
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> index 45ec722d25ea6..032a1cdf4df70 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
[ ... ]
> @@ -338,11 +340,8 @@ static int vfio_ccw_mdev_ioctl_get_region_info(struct vfio_device *vdev,
> VFIO_CCW_NUM_REGIONS + private->num_regions)
> return -EINVAL;
>
> - info->index = array_index_nospec(info->index,
> - VFIO_CCW_NUM_REGIONS +
> - private->num_regions);
> -
> i = info->index - VFIO_CCW_NUM_REGIONS;
> + i = array_index_nospec(i, private->num_regions);
[Severity: High]
This is a pre-existing issue, but does device teardown safely cancel background
work items before freeing memory?
Asynchronous events can queue crw_work (via vfio_ccw_chp_event) or io_work
(via fsm_irq). When the device is torn down, fsm_close() conditionally flushes
the workqueue only on an error/busy path, leaving pending work active on the
success path:
drivers/s390/cio/vfio_ccw_fsm.c:fsm_close() {
...
ret = cio_disable_subchannel(sch);
if (ret == -EBUSY)
ret = vfio_ccw_sch_quiesce(sch);
...
}
Then, vfio_ccw_mdev_release_dev() frees the private structure and destroys the
mutex without invoking cancel_work_sync() for crw_work and io_work:
drivers/s390/cio/vfio_ccw_ops.c:vfio_ccw_mdev_release_dev() {
...
kfree(private->cp.guest_cp);
mutex_destroy(&private->io_mutex);
...
}
Can this lead to a use-after-free on the vfio_ccw_private structure if the
pending work executes on the freed private pointer after it is destroyed by
the VFIO core?
>
> info->offset = VFIO_CCW_INDEX_TO_OFFSET(info->index);
> info->size = private->region[i].size;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260726040129.2946151-1-farman@linux.ibm.com?part=6
next prev parent reply other threads:[~2026-07-26 4:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 4:01 [PATCH v5 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-26 4:01 ` [PATCH v5 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-26 4:15 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-26 4:08 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-26 4:33 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-26 4:18 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-26 4:14 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-26 4:16 ` sashiko-bot [this message]
2026-07-26 4:01 ` [PATCH v5 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-26 4:16 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-26 4:14 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 09/10] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-26 4:18 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-26 4:27 ` 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=20260726041624.B2CA61F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=farman@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 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.