From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
kvm@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v5 03/10] s390/vfio_ccw: fix out of bounds check on CCW array
Date: Sun, 26 Jul 2026 04:33:16 +0000 [thread overview]
Message-ID: <20260726043317.0B9201F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726040129.2946151-4-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Hardware Status Modifier skips allow the channel subsystem to fetch and execute CCWs from out-of-bounds host memory because VFIO prematurely truncates the allocated chain.
--
--- Patch [3]: [PATCH v5 03/10] s390/vfio_ccw: fix out of bounds check on CCW array ---
commit 7c8a75a862f0fe5c95ff1ad636c202fa276e66c2
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 array access in ccwchain_calc_length().
It restructures the loop to exit safely once the maximum number of CCWs
(256) have been processed, preventing the code from evaluating memory
outside the valid range.
> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> --- 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 termination condition fully
account for hardware status modifier skips?
If a guest constructs a channel program where a CCW specifies chaining
and executes a command that generates a status modifier, and the
immediately following CCW explicitly clears the chaining flag, will
ccwchain_calc_length() stop counting at the second CCW?
If the calculation stops there, it appears the subsystem would allocate a host
buffer sized for exactly two CCWs. When executed, the hardware would see
the status modifier, skip the second CCW, and fetch a third CCW from
memory immediately following the allocated buffer.
Could this allow the channel subsystem to fetch and execute an untranslated,
out-of-bounds CCW from host memory if the guest places one adjacent to the
allocation?
> + }
>
> - return cnt;
> + return -EINVAL;
> }
>
> static int tic_target_chain_exists(struct ccw1 *tic, struct channel_program *cp)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260726040129.2946151-1-farman@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-07-26 4:33 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 [this message]
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
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=20260726043317.0B9201F000E9@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