From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
linux-s390@vger.kernel.org
Subject: Re: [PATCH v9 03/10] s390/vfio_ccw: fix out of bounds check on CCW array
Date: Tue, 28 Jul 2026 03:59:50 +0000 [thread overview]
Message-ID: <20260728035950.D0EC51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728033022.2658232-4-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] A preexisting logic flaw allows a guest to cause the host's Channel Subsystem to execute out-of-bounds memory as a Channel Command Word (CCW), potentially leading to arbitrary host memory corruption via DMA.
--
--- Patch [3]: [PATCH v9 03/10] s390/vfio_ccw: fix out of bounds check on CCW array ---
commit 622cd15d4520f97b7f1bb4f1d15867ddea2a23a6
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: fix out of bounds check on CCW array
This commit modifies the loop in ccwchain_calc_length() to fix an
out-of-bounds array access that could examine the 257th CCW before failing.
It changes a do..while loop to a for loop to strictly bound the CCW array
examination.
> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index 1c2890d139c6b..af632f9d54535 100644
> --- a/drivers/s390/cio/vfio_ccw_cp.c
> +++ b/drivers/s390/cio/vfio_ccw_cp.c
[ ... ]
> @@ -377,11 +377,9 @@ static void ccwchain_cda_free(struct ccwchain *chain, int idx)
> static int ccwchain_calc_length(u64 iova, struct channel_program *cp)
> {
> struct ccw1 *ccw = cp->guest_cp;
> - int cnt = 0;
> -
> - do {
> - cnt++;
> + int cnt;
>
> + for (cnt = 1; cnt <= CCWCHAIN_LEN_MAX; cnt++, ccw++) {
> /*
> * We want to keep counting if the current CCW has the
> * command-chaining flag enabled, or if it is a TIC CCW
> @@ -391,15 +389,10 @@ static int ccwchain_calc_length(u64 iova, struct channel_program *cp)
> * after the TIC, depending on the results of its operation.
> */
> if (!ccw_is_chain(ccw) && !is_tic_within_range(ccw, iova, cnt))
> - break;
> -
> - ccw++;
> - } while (cnt < CCWCHAIN_LEN_MAX + 1);
> -
> - if (cnt == CCWCHAIN_LEN_MAX + 1)
> - cnt = -EINVAL;
> + return cnt;
[Severity: Critical]
This is a pre-existing issue, but does this calculation adequately account for
the hardware's behavior of skipping a CCW when a Status Modifier is presented?
If a guest submits a channel program where a CCW that can generate a Status
Modifier (like a Search CCW) has the command-chaining (CC) flag enabled and is
followed by a TIC CCW that lacks the CC flag and jumps to a different chain,
the loop will stop counting at the TIC because both !ccw_is_chain(ccw) and
!is_tic_within_range(...) are true.
In this scenario, ccwchain_calc_length() returns a length of exactly 2. The
host would then allocate 16 bytes for chain->ch_ccw from the DMA heap. When the
hardware executes the first CCW and encounters a Status Modifier, it skips the
TIC and fetches the next CCW from 16 bytes into the allocation, which is
out-of-bounds of the host's DMA heap allocation.
By grooming the host heap, could a guest place controlled data adjacent to this
allocation, which the hardware would then execute as an untranslated CCW,
potentially leading to arbitrary host memory corruption via DMA?
> + }
>
> - return cnt;
> + return -EINVAL;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728033022.2658232-1-farman@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-07-28 3:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 3:30 [PATCH v9 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-28 3:30 ` [PATCH v9 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-28 4:03 ` sashiko-bot
2026-07-28 3:30 ` [PATCH v9 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-28 3:52 ` sashiko-bot
2026-07-28 3:30 ` [PATCH v9 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-28 3:59 ` sashiko-bot [this message]
2026-07-28 3:30 ` [PATCH v9 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-28 3:59 ` sashiko-bot
2026-07-28 3:30 ` [PATCH v9 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-28 4:00 ` sashiko-bot
2026-07-28 3:30 ` [PATCH v9 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-28 4:02 ` sashiko-bot
2026-07-28 3:30 ` [PATCH v9 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-28 4:02 ` sashiko-bot
2026-07-28 3:30 ` [PATCH v9 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-28 4:01 ` sashiko-bot
2026-07-28 14:48 ` Matthew Rosato
2026-07-28 3:30 ` [PATCH v9 09/10] s390/vfio_ccw: selectively expand io_mutex Eric Farman
2026-07-28 4:05 ` sashiko-bot
2026-07-28 14:48 ` Matthew Rosato
2026-07-28 3:30 ` [PATCH v9 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-28 4:05 ` sashiko-bot
2026-07-28 14:45 ` [PATCH v9 00/10] s390/vfio_ccw fixes Christian Borntraeger
2026-07-28 14:53 ` Matthew Rosato
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=20260728035950.D0EC51F000E9@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.