From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v7 06/10] s390/vfio_ccw: ensure index for read/write regions are within range
Date: Mon, 27 Jul 2026 20:03:48 +0000 [thread overview]
Message-ID: <20260727200348.A4ED21F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260727192230.2715207-7-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Concurrent lockless modification and usage of `private->*_trigger` eventfd pointers can lead to use-after-free.
- [High] Concurrent lockless accesses and modifications to the `private->crw` list lead to list corruption, infinite loops, and potential use-after-free.
- [High] Work items `io_work` and `crw_work` are not unconditionally cancelled before freeing the device structure.
--
--- Patch [6]: [PATCH v7 06/10] s390/vfio_ccw: ensure index for read/write regions are within range ---
commit f8eafc3dc61a7fdadf00091fc10c59686336cf60
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: ensure index for read/write regions are within range
This patch adds bounds checking to the region indexes in the read/write paths.
The capability chain previously clamped the region indexes, but the existing
read/write regions lacked these checks, which are now enforced.
> 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);
>
> mutex_lock(&private->io_mutex);
[Severity: High]
This is a pre-existing issue, but is the private->crw list modified locklessly
here?
If an asynchronous host event handler queues a 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 a concurrent read from userspace calling vfio_ccw_crw_region_read()
corrupt the list pointers when calling list_del() since neither operation
appears to hold a lock protecting private->crw?
> + if (i >= private->num_regions) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + i = array_index_nospec(i, private->num_regions);
> region = private->region[i].data;
>
> if (crw)
> 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
[ ... ]
> @@ -243,6 +243,7 @@ static ssize_t vfio_ccw_mdev_read(struct vfio_device *vdev,
> return vfio_ccw_mdev_read_io_region(private, buf, count, ppos);
> default:
> index -= VFIO_CCW_NUM_REGIONS;
[Severity: High]
This is a pre-existing issue, but are io_work and crw_work unconditionally
cancelled before freeing the device structure?
Looking at vfio_ccw_mdev_release_dev(), the private structure is freed:
drivers/s390/cio/vfio_ccw_ops.c:vfio_ccw_mdev_release_dev() {
...
kfree(private->cp.guest_cp);
mutex_destroy(&private->io_mutex);
}
If a background event queues io_work or crw_work, and the work item is not
flushed before release, could vfio_ccw_crw_todo() dereference the freed
private pointer when accessing private->crw_trigger?
drivers/s390/cio/vfio_ccw_drv.c:vfio_ccw_crw_todo() {
private = container_of(work, struct vfio_ccw_private, crw_work);
if (!list_empty(&private->crw) && private->crw_trigger)
...
}
[Severity: Critical]
This is another pre-existing issue, but can concurrent modification and usage
of the private->*_trigger eventfd pointers lead to a use-after-free?
The VFIO_DEVICE_SET_IRQS ioctl can locklessly drop the reference and clear the
eventfd pointer:
drivers/s390/cio/vfio_ccw_ops.c:vfio_ccw_mdev_set_irqs() {
...
if (fd == -1) {
if (*ctx)
eventfd_ctx_put(*ctx);
*ctx = NULL;
...
}
If background work items like vfio_ccw_crw_todo() check the pointer and then
call eventfd_signal():
drivers/s390/cio/vfio_ccw_drv.c:vfio_ccw_crw_todo() {
...
if (!list_empty(&private->crw) && private->crw_trigger)
eventfd_signal(private->crw_trigger);
...
}
Could the eventfd context be freed between the check and the signal call,
resulting in a dereference of the freed context?
> + index = array_index_nospec(index, private->num_regions);
> return private->region[index].ops->read(private, buf, count,
> ppos);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727192230.2715207-1-farman@linux.ibm.com?part=6
next prev parent reply other threads:[~2026-07-27 20:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 19:22 [PATCH v7 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-27 19:22 ` [PATCH v7 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-27 19:58 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-27 19:52 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-27 19:53 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-27 19:59 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-27 19:54 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-27 20:03 ` sashiko-bot [this message]
2026-07-27 19:22 ` [PATCH v7 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-27 20:02 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-27 20:04 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 09/10] s390/vfio_ccw: selectively expand io_mutex Eric Farman
2026-07-27 20:12 ` sashiko-bot
2026-07-27 19:22 ` [PATCH v7 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-27 20:07 ` sashiko-bot
2026-07-27 21:35 ` Farhan Ali
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=20260727200348.A4ED21F00A3A@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox