From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org, kvm@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v2 3/7] s390/vfio_ccw: fix out of bounds check on CCW array
Date: Mon, 20 Jul 2026 20:38:53 +0000 [thread overview]
Message-ID: <20260720203854.5F4661F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720201931.976660-4-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver does not explicitly cancel asynchronous background works (io_work and crw_work) during device removal or release, which can lead to a Use-After-Free if a work executes after the private device structure is freed.
--
--- Patch [3]: [PATCH v2 3/7] s390/vfio_ccw: fix out of bounds check on CCW array ---
commit c4537e2a2ac0b540c3111dbbbb37763f251c94df
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: fix out of bounds check on CCW array
This commit fixes an out-of-bounds check in ccwchain_calc_length() when
counting CCWs. It restructures the loop to break as soon as the maximum of
256 CCWs are examined, preventing memory reads outside the array range.
> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index 7abdebd8f7c3d..ce61858c82eb6 100644
> --- a/drivers/s390/cio/vfio_ccw_cp.c
> +++ b/drivers/s390/cio/vfio_ccw_cp.c
> @@ -393,11 +393,14 @@ static int ccwchain_calc_length(u64 iova, struct channel_program *cp)
> if (!ccw_is_chain(ccw) && !is_tic_within_range(ccw, iova, cnt))
> break;
>
> - ccw++;
> - } while (cnt < CCWCHAIN_LEN_MAX + 1);
> + /* Exit the loop when we reach the maximum */
> + if (cnt >= CCWCHAIN_LEN_MAX) {
> + cnt = -EINVAL;
> + break;
> + }
>
> - if (cnt == CCWCHAIN_LEN_MAX + 1)
> - cnt = -EINVAL;
> + ccw++;
> + } while (1);
>
> return cnt;
> }
[Severity: High]
This is a pre-existing issue, but I noticed a potential use-after-free
during device teardown in drivers/s390/cio/vfio_ccw_ops.c.
Looking at vfio_ccw_mdev_remove() and vfio_ccw_mdev_release_dev(), the
driver tears down the device and the VFIO core frees the private
structure without explicitly cancelling asynchronous background works
(io_work and crw_work).
While flush_workqueue() is called in vfio_ccw_sch_quiesce(), this only
flushes currently queued work and does not prevent concurrent queuing.
For instance, if vfio_ccw_chp_event() reads the private structure and
queues private->crw_work right before or during teardown, the work item
can remain on vfio_ccw_work_q and execute after private has been freed.
Does this teardown path need a cancel_work_sync() for these work items
to prevent them from accessing freed memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720201931.976660-1-farman@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-07-20 20:38 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 20:19 [PATCH v2 0/7] s390/vfio_ccw fixes Eric Farman
2026-07-20 20:19 ` [PATCH v2 1/7] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-20 20:31 ` sashiko-bot
2026-07-20 21:48 ` Farhan Ali
2026-07-20 20:19 ` [PATCH v2 2/7] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-20 20:30 ` sashiko-bot
2026-07-20 20:53 ` Eric Farman
2026-07-20 20:19 ` [PATCH v2 3/7] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-20 20:38 ` sashiko-bot [this message]
2026-07-20 20:19 ` [PATCH v2 4/7] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-20 20:33 ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 5/7] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-20 20:40 ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 6/7] s390/vfio_ccw: implement a channel program lock Eric Farman
2026-07-20 20:39 ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 7/7] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-20 20:47 ` 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=20260720203854.5F4661F000E9@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.