All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	kvm@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v3 1/8] s390/vfio_ccw: free all memory if cp_init() fails
Date: Thu, 23 Jul 2026 18:31:58 +0000	[thread overview]
Message-ID: <20260723183158.7FD181F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723174751.1180334-2-farman@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Unbounded mutual recursion in channel program parsing leads to host kernel stack overflow.
- [High] Out-of-bounds read in `ccwchain_calc_length` due to an off-by-one error.
--

--- Patch [1]: [PATCH v3 1/8] s390/vfio_ccw: free all memory if cp_init() fails ---
commit e7fe5fe9c1f027187ba27b2948379cc2bd88397e
Author: Eric Farman <farman@linux.ibm.com>

s390/vfio_ccw: free all memory if cp_init() fails

The routine cp_free() is called to unpin/free any memory once an I/O
is completed successfully, or if cp_prefetch() fails. But if cp_init()
fails, and cp->initialized is not enabled, the same routine cannot be
used to free all the memory. This patch performs the cleanup outside of
the recursive ccwchain_handle_ccw()/ccwchain_loop_tic() logic.

> 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: Critical]
This is a pre-existing issue, but does this mutual recursion between
ccwchain_handle_ccw() and ccwchain_loop_tic() have a depth limit?

If a guest VM constructs a channel program with a long sequence of
transfer in channel commands that each jump to a distinct guest physical
address, tic_target_chain_exists() will return false.

This causes ccwchain_loop_tic() to recursively call ccwchain_handle_ccw():

drivers/s390/cio/vfio_ccw_cp.c:ccwchain_loop_tic() {
        ...
        if (tic_target_chain_exists(tic, cp))
                continue;

        ret = ccwchain_handle_ccw(tic->cda, cp);
        ...
}

Since there doesn't appear to be a limit on the recursion depth here,
could this exhaust the host kernel stack?

> -	if (ret)
> -		ccwchain_free(chain);
> -
>  	return ret;
>  }

[ ... ]

[Severity: High]
This is also a pre-existing issue, but is there a potential out-of-bounds
read in ccwchain_calc_length() due to an off-by-one error?

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);
        ...
}

Since cp->guest_cp is allocated with exactly CCWCHAIN_LEN_MAX elements,
if a guest provides a channel program where all 256 items have the
command-chaining flag enabled, the loop executes 256 times.

On the 257th iteration, cnt is 257 and ccw points to cp->guest_cp[256],
which is past the end of the allocation. The loop condition evaluates
to true (256 < 257), allowing ccw_is_chain(ccw) to dereference the
out-of-bounds pointer.

Could this read hit an unmapped guard page and crash the host?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723174751.1180334-1-farman@linux.ibm.com?part=1

  reply	other threads:[~2026-07-23 18:32 UTC|newest]

Thread overview: 18+ 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 [this message]
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
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 20:38     ` Eric Farman
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=20260723183158.7FD181F000E9@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.