From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
kvm@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [PATCH v4 1/9] s390/vfio_ccw: free all memory if cp_init() fails
Date: Sat, 25 Jul 2026 15:42:28 +0000 [thread overview]
Message-ID: <20260725154229.41ECF1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260725152705.3958100-2-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Unbounded recursion between `ccwchain_handle_ccw()` and `ccwchain_loop_tic()` can exhaust the host kernel stack.
- [High] An off-by-one error in `ccwchain_calc_length()` causes a heap out-of-bounds read past the end of the `cp->guest_cp` array.
--
--- Patch [1]: [PATCH v4 1/9] s390/vfio_ccw: free all memory if cp_init() fails ---
commit 8ee92e1dc4c9d7d0f67c0ba543dd404b37f81dcc
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: free all memory if cp_init() fails
This commit addresses a memory leak where CCW segments created as a result
of a Transfer in Channel would not be properly freed if cp_init() fails.
It moves the cleanup logic outside the recursive ccwchain_handle_ccw() and
ccwchain_loop_tic() loops.
> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index 7561aa7d3e017..086d1b54bdb05 100644
> --- a/drivers/s390/cio/vfio_ccw_cp.c
> +++ b/drivers/s390/cio/vfio_ccw_cp.c
> @@ -455,9 +455,6 @@ static int ccwchain_handle_ccw(dma32_t cda, struct channel_program *cp)
> /* Loop for tics on this new chain. */
> ret = ccwchain_loop_tic(chain, cp);
>
[Severity: High]
This isn't a bug introduced by this patch, but can this unbounded recursion
between ccwchain_handle_ccw() and ccwchain_loop_tic() exhaust the host kernel
stack?
If a guest constructs a channel program consisting of a long linear sequence
of TICs (Transfer in Channel), where each TIC points to a distinct, previously
unvisited address, could this lead to a kernel panic from stack overflow?
Since there is no limit on the recursion depth, ccwchain_handle_ccw() and
ccwchain_loop_tic() recursively call each other until the stack overflows:
ccwchain_handle_ccw() -> ccwchain_loop_tic() -> ccwchain_handle_ccw()
> - if (ret)
> - ccwchain_free(chain);
> -
> return ret;
> }
[Severity: High]
This is a pre-existing issue, but does an off-by-one error in
ccwchain_calc_length() cause a heap out-of-bounds read past the end of the
cp->guest_cp array?
If the guest provides a CCW chain of exactly CCWCHAIN_LEN_MAX (256) elements,
with all elements having the chain flag set, the loop logic permits
evaluating the chain flag on the out-of-bounds index before realizing
the maximum limit is reached:
drivers/s390/cio/vfio_ccw_cp.c:ccwchain_calc_length() {
...
} while (cnt < CCWCHAIN_LEN_MAX + 1);
...
}
Could this lead to a kernel Oops if it crosses a page boundary into an
unmapped page, or trigger KASAN panics?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725152705.3958100-1-farman@linux.ibm.com?part=1
next prev parent reply other threads:[~2026-07-25 15:42 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 15:26 [PATCH v4 0/9] s390/vfio_ccw fixes Eric Farman
2026-07-25 15:26 ` [PATCH v4 1/9] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-25 15:42 ` sashiko-bot [this message]
2026-07-25 15:26 ` [PATCH v4 2/9] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-25 15:39 ` sashiko-bot
2026-07-25 15:26 ` [PATCH v4 3/9] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-25 15:33 ` sashiko-bot
2026-07-25 16:09 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 4/9] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-25 15:44 ` sashiko-bot
2026-07-25 15:27 ` [PATCH v4 5/9] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-25 15:34 ` sashiko-bot
2026-07-25 15:27 ` [PATCH v4 6/9] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-25 15:42 ` sashiko-bot
2026-07-25 16:27 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 7/9] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-25 15:42 ` sashiko-bot
2026-07-25 16:39 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 8/9] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-25 15:43 ` sashiko-bot
2026-07-25 17:04 ` Matthew Rosato
2026-07-25 15:27 ` [PATCH v4 9/9] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-25 15:46 ` sashiko-bot
2026-07-25 17:03 ` 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=20260725154229.41ECF1F00A3E@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