Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH v2 2/7] s390/vfio_ccw: limit the number of channel program segments
Date: Mon, 20 Jul 2026 20:30:52 +0000	[thread overview]
Message-ID: <20260720203054.07C041F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720201931.976660-3-farman@linux.ibm.com>

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

New issues:
- [Low] Returning a pointer (`ERR_PTR`) from a function that returns an `int`.

Pre-existing issues:
- [High] Concurrent unprotected access to channel program structures via ioctl reset and write paths.
- [High] Out-of-bounds read on `cp->guest_cp` when calculating the CCW chain length.
--

--- Patch [2]: [PATCH v2 2/7] s390/vfio_ccw: limit the number of channel program segments ---
commit 55497ee3c2db8e265add0b6679cc5ddd751ba7ce
Author: Eric Farman <farman@linux.ibm.com>

s390/vfio_ccw: limit the number of channel program segments

This commit imposes a limit on the number of channel program segments to
prevent excessive recursive processing. It tracks the count in the
channel_program structure and fails if it exceeds CCWCHAIN_COUNT_MAX.

> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index 086d1b54bdb05..7abdebd8f7c3d 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;
>  
> +	/* Limit number of chains in a single channel program */
> +	if (cp->ccwchain_count >= CCWCHAIN_COUNT_MAX)
> +		return ERR_PTR(-EINVAL);

[Severity: Low]
Does this return a pointer from a function that returns an int?
ccwchain_handle_ccw() returns an int, but ERR_PTR(-EINVAL) returns a void
pointer, which could cause a type mismatch or compilation warning.

[ ... ]

[Severity: High]
This is a pre-existing issue, but can concurrent unprotected access to
channel program structures occur via the ioctl reset and write paths?

If a user-space process concurrently invokes ioctl(VFIO_DEVICE_RESET) and
write() on the VFIO device file descriptor:

drivers/s390/cio/vfio_ccw_ops.c:vfio_ccw_mdev_reset() {
    ...
    vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_CLOSE);
    ...
}

This calls into the state machine to close and free the channel program
without acquiring private->io_mutex:

drivers/s390/cio/vfio_ccw_fsm.c:fsm_close() {
    ...
    cp_free(&private->cp);
    ...
}

Concurrently, vfio_ccw_mdev_write_io_region() acquires io_mutex and processes
IO, allocating and using private->cp. Could this data race lead to a
use-after-free?

[Severity: High]
This is a pre-existing issue, but is there an out-of-bounds read on
cp->guest_cp when calculating the CCW chain length?

If an unprivileged user provides a channel program filled with exactly 256
command-chained CCWs:

drivers/s390/cio/vfio_ccw_cp.c:ccwchain_calc_length() {
    ...
    if (!ccw_is_chain(ccw) && !is_tic_within_range(ccw, iova, cnt))
        break;

    ccw++;
} while (cnt < CCWCHAIN_LEN_MAX + 1);

The loop executes a 257th iteration when cnt == 257, evaluating
!ccw_is_chain(ccw) on guest_cp[256], which points past the 256-element
guest_cp array.

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

  reply	other threads:[~2026-07-20 20:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 20:19 [PATCH v2 0/7] s390/vfio_ccw fixes Eric Farman
2026-07-20 20:19 ` [PATCH v2 1/7] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-20 20:31   ` sashiko-bot
2026-07-20 21:48   ` Farhan Ali
2026-07-20 20:19 ` [PATCH v2 2/7] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-20 20:30   ` sashiko-bot [this message]
2026-07-20 20:53     ` Eric Farman
2026-07-20 20:19 ` [PATCH v2 3/7] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-20 20:38   ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 4/7] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-20 20:33   ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 5/7] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-20 20:40   ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 6/7] s390/vfio_ccw: implement a channel program lock Eric Farman
2026-07-20 20:39   ` sashiko-bot
2026-07-20 20:19 ` [PATCH v2 7/7] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-20 20:47   ` 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=20260720203054.07C041F000E9@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