From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v3 2/8] s390/vfio_ccw: limit the number of channel program segments
Date: Thu, 23 Jul 2026 18:26:07 +0000 [thread overview]
Message-ID: <20260723182608.3BE1F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723174751.1180334-3-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Off-by-one error in ccwchain_calc_length allows a guest-triggered out-of-bounds read.
--
--- Patch [2]: [PATCH v3 2/8] s390/vfio_ccw: limit the number of channel program segments ---
commit b0f514e864a35fcb11c0505d666fd9d7fbad12c0
Author: Eric Farman <farman@linux.ibm.com>
Subject: s390/vfio_ccw: limit the number of channel program segments
This commit limits the number of channel program segments that can exist
in a single channel program. It breaks channel programs into segments
when it encounters a Transfer-In-Channel (TIC) CCW, and adds a check to
ensure the segment count does not exceed a global limit. This prevents
hitting an arbitrary limit due to recursive processing.
> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index 086d1b54bdb05..1c2890d139c6b 100644
> --- a/drivers/s390/cio/vfio_ccw_cp.c
> +++ b/drivers/s390/cio/vfio_ccw_cp.c
[ ... ]
> @@ -441,6 +442,10 @@ static int ccwchain_handle_ccw(dma32_t cda, struct channel_program *cp)
> if (len < 0)
> return len;
>
[Severity: High]
This isn't a bug introduced by this patch, but does ccwchain_calc_length()
contain an off-by-one error that allows a guest-triggered out-of-bounds read?
When a guest VM submits a channel program containing a sequence of 256 CCWs
with the command-chaining or data-chaining flag set, the driver handles
this request and calls ccwchain_calc_length() to parse the chain.
The array cp->guest_cp is allocated to hold exactly CCWCHAIN_LEN_MAX (256)
elements. However, the loop in ccwchain_calc_length() uses the condition
while (cnt < CCWCHAIN_LEN_MAX + 1):
drivers/s390/cio/vfio_ccw_cp.c:ccwchain_calc_length() {
do {
cnt++;
...
if (!ccw_is_chain(ccw) && !is_tic_within_range(ccw, iova, cnt))
break;
ccw++;
} while (cnt < CCWCHAIN_LEN_MAX + 1);
}
Does this allow the loop to iterate up to 257 times? During the 257th
iteration (cnt = 257), does the pointer ccw advance past the end of the
cp->guest_cp array, causing the ccw_is_chain(ccw) macro to dereference
an out-of-bounds pointer to read ccw->flags?
Could this lead to a kernel heap out-of-bounds read and subsequent kernel
panic if KASAN is enabled, allowing an unprivileged guest to impact host
stability?
> + /* Limit number of chains in a single channel program */
> + if (cp->ccwchain_count >= CCWCHAIN_COUNT_MAX)
> + return -EINVAL;
> +
> /* Need alloc a new chain for this one. */
> chain = ccwchain_alloc(cp, len);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723174751.1180334-1-farman@linux.ibm.com?part=2
next prev parent reply other threads:[~2026-07-23 18:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 17:47 [PATCH v3 0/8] s390/vfio_ccw fixes Eric Farman
2026-07-23 17:47 ` [PATCH v3 1/8] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-23 18:31 ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 2/8] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-23 18:26 ` sashiko-bot [this message]
2026-07-23 17:47 ` [PATCH v3 3/8] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-23 18:22 ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 4/8] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-23 18:29 ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 5/8] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-23 18:23 ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 6/8] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-23 18:30 ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 7/8] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-23 18:32 ` sashiko-bot
2026-07-23 17:47 ` [PATCH v3 8/8] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-23 18:34 ` 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=20260723182608.3BE1F1F000E9@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