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>,
	kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH v4 4/9] s390/vfio_ccw: ensure first IDAW remains constant
Date: Sat, 25 Jul 2026 15:44:46 +0000	[thread overview]
Message-ID: <20260725154447.022231F00ADB@smtp.kernel.org> (raw)
In-Reply-To: <20260725152705.3958100-5-farman@linux.ibm.com>

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

Pre-existing issues:
- [High] `get_guest_idal` reads past the end of the guest's IDAL buffer for format-1 IDALs, potentially causing spurious DMA faults.
- [High] Untranslated guest IDALs are passed to the host channel subsystem when data transfer is skipped, causing hardware Program Checks.
--

--- Patch [4]: [PATCH v4 4/9] s390/vfio_ccw: ensure first IDAW remains constant ---
commit ff6c62bce82b594d19f9d6e95c9229ea752d6614
Author: Eric Farman <farman@linux.ibm.com>

s390/vfio_ccw: ensure first IDAW remains constant

The first IDAW in a list does not need to be on a 2K/4K boundary like all
others, and so is read separately to accurately calculate the size of the
buffer needed to read the full IDAL. This commit validates that the address
found in the first IDAW is unchanged between reads.

> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c
> index af632f9d54535..6275794751cb4 100644
> --- a/drivers/s390/cio/vfio_ccw_cp.c
> +++ b/drivers/s390/cio/vfio_ccw_cp.c
> @@ -523,6 +523,7 @@ static dma64_t *get_guest_idal(struct ccw1 *ccw, struct channel_program *cp, int
>  		&container_of(cp, struct vfio_ccw_private, cp)->vdev;
>  	dma64_t *idaws;
>  	dma32_t *idaws_f1;
> +	u64 first_idaw;
>  	int idal_len = idaw_nr * sizeof(*idaws);
        ^^^^

[Severity: High]
This is a pre-existing issue, but does get_guest_idal() read past the end of
the guest's IDAL buffer for format-1 IDALs?

It appears that idal_len is calculated using sizeof(*idaws), which is always 8
bytes (sizeof(dma64_t)), even when the guest uses 32-bit (format-1) IDAWs.

Later in get_guest_idal(), vfio_dma_rw() is called with this idal_len:

	if (ccw_is_idal(ccw)) {
		/* Copy IDAL from guest */
		ret = vfio_dma_rw(vdev, dma32_to_u32(ccw->cda), idaws, idal_len, false);

If a guest channel program uses Format-1 (32-bit) IDAWs, they are only 4 bytes
each. Calling vfio_dma_rw() with idaw_nr * 8 reads 100% past the end of the
guest's IDAL buffer.

If the guest's 32-bit IDAL ends near a page boundary and the adjacent page is
unmapped or restricted, this over-read could cross into unmapped guest memory
and fail, potentially spuriously rejecting a valid guest I/O request with a
DMA translation error.

>  	int idaw_size = idal_is_2k(cp) ? PAGE_SIZE / 2 : PAGE_SIZE;
>  	int idaw_mask = ~(idaw_size - 1);

[ ... ]

[Severity: High]
This is also a pre-existing issue, but does ccwchain_fetch_ccw() pass
untranslated guest IDALs to the host channel subsystem when data transfer is
skipped?

Looking at ccwchain_fetch_ccw(), if ccw_does_data_transfer(ccw) is false
(e.g., a READ CCW with the SKIP flag), pa->pa_nr is set to 0:

	if (ccw_does_data_transfer(ccw)) {
		ret = page_array_pin(pa, vdev, idal_is_2k(cp));
		if (ret < 0)
			goto out_unpin;
	} else {
		pa->pa_nr = 0;
	}

	ccw->cda = virt_to_dma32(idaws);
	ccw->flags |= CCW_FLAG_IDA;

	/* Populate the IDAL with pinned/translated addresses from page */
	page_array_idal_create_words(pa, idaws);

Consequently, page_array_idal_create_words() loops 0 times, leaving the idaws
buffer populated with raw guest IOVAs instead of valid host absolute addresses.

Since vfio-ccw forces orb.cmd.c64 = 1 (Format-2, 64-bit IDAWs) when issuing the
SSCH to the host channel subsystem, the hardware will fetch these untranslated
guest IOVAs. If the guest used 32-bit IDAWs, they are read as garbage 64-bit
pointers.

Will the hardware validate these invalid addresses during execution and trigger
a Channel Program Check, spuriously failing the guest's SKIP I/O request?

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

  reply	other threads:[~2026-07-25 15:44 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
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 [this message]
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=20260725154447.022231F00ADB@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.