From: sashiko-bot@kernel.org
To: "Eric Farman" <farman@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH v5 10/10] s390/vfio_ccw: implement a crw lock
Date: Sun, 26 Jul 2026 04:27:47 +0000 [thread overview]
Message-ID: <20260726042748.222791F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726040129.2946151-11-farman@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing write-side lock in `vfio_ccw_mdev_set_irqs` renders `crw_lock` ineffective, leading to Use-After-Free of `eventfd_ctx`.
- [High] TOCTOU race between `vfio_ccw_mdev_remove` and asynchronous channel path events leads to Use-After-Free of `vfio_ccw_private`.
--
--- Patch [10]: [PATCH v5 10/10] s390/vfio_ccw: implement a crw lock ---
commit b1ac07dbd7bc9e331720d0ba13ad54e4a3ae455a
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: implement a crw lock
This commit introduces a new crw_lock to serialize access to the Channel
Report Word (CRW) list elements in the vfio_ccw driver. It replaces implicit
synchronization with explicit spinlocks when queueing, reading, and freeing
CRW structures, as well as when notifying userspace via eventfd.
> diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
> index 4830f0dd9c3a3..437d7709b4a56 100644
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -122,11 +122,14 @@ void vfio_ccw_sch_io_todo(struct work_struct *work)
> void vfio_ccw_crw_todo(struct work_struct *work)
> {
> struct vfio_ccw_private *private;
> + unsigned long flags;
>
> private = container_of(work, struct vfio_ccw_private, crw_work);
>
> + spin_lock_irqsave(&private->crw_lock, flags);
> if (!list_empty(&private->crw) && private->crw_trigger)
> eventfd_signal(private->crw_trigger);
> + spin_unlock_irqrestore(&private->crw_lock, flags);
[Severity: High]
This isn't a bug introduced by this patch, but does crw_lock fully protect
crw_trigger from concurrent modification?
In vfio_ccw_mdev_set_irqs(), the eventfd context can be updated and the old
context freed without acquiring crw_lock:
drivers/s390/cio/vfio_ccw_ops.c:vfio_ccw_mdev_set_irqs() {
...
if (*ctx)
eventfd_ctx_put(*ctx);
*ctx = efdctx;
...
}
Because the write side in vfio_ccw_mdev_set_irqs() doesn't take the lock,
could a concurrent VFIO_DEVICE_SET_IRQS ioctl free the context while
eventfd_signal() is executing here, leading to a Use-After-Free?
[ ... ]
> @@ -290,6 +293,7 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private,
> unsigned int rsid)
> {
> struct vfio_ccw_crw *crw;
> + unsigned long flags;
>
> /*
> * If unable to allocate a CRW, just drop the event and
> @@ -307,7 +311,9 @@ static void vfio_ccw_queue_crw(struct vfio_ccw_private *private,
> crw->crw.erc = erc;
> crw->crw.rsid = rsid;
>
> + spin_lock_irqsave(&private->crw_lock, flags);
[Severity: High]
This is a pre-existing issue, but could this lock access trigger a
Use-After-Free if the mdev is being concurrently removed?
The CSS core calls vfio_ccw_chp_event() asynchronously. It retrieves the
private pointer locklessly and then calls this function:
drivers/s390/cio/vfio_ccw_drv.c:vfio_ccw_chp_event() {
struct vfio_ccw_private *private = dev_get_drvdata(&parent->dev);
...
if (!private || !mask)
return 0;
...
vfio_ccw_queue_crw(private, ...);
}
If vfio_ccw_mdev_remove() runs concurrently, it clears the driver data and
drops the final reference:
drivers/s390/cio/vfio_ccw_ops.c:vfio_ccw_mdev_remove() {
...
dev_set_drvdata(&parent->dev, NULL);
vfio_put_device(&private->vdev);
...
}
If the channel path event handler passes the NULL check and gets preempted
before mdev removal finishes, won't taking private->crw_lock here access
freed memory?
> list_add_tail(&crw->next, &private->crw);
> + spin_unlock_irqrestore(&private->crw_lock, flags);
> queue_work(vfio_ccw_work_q, &private->crw_work);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260726040129.2946151-1-farman@linux.ibm.com?part=10
prev parent reply other threads:[~2026-07-26 4:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 4:01 [PATCH v5 00/10] s390/vfio_ccw fixes Eric Farman
2026-07-26 4:01 ` [PATCH v5 01/10] s390/vfio_ccw: free all memory if cp_init() fails Eric Farman
2026-07-26 4:15 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 02/10] s390/vfio_ccw: limit the number of channel program segments Eric Farman
2026-07-26 4:08 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 03/10] s390/vfio_ccw: fix out of bounds check on CCW array Eric Farman
2026-07-26 4:33 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 04/10] s390/vfio_ccw: ensure first IDAW remains constant Eric Farman
2026-07-26 4:18 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 05/10] s390/vfio_ccw: calculate idal length based on idaw type Eric Farman
2026-07-26 4:14 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 06/10] s390/vfio_ccw: ensure index for read/write regions are within range Eric Farman
2026-07-26 4:16 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 07/10] s390/vfio_ccw: cancel existing workqueues Eric Farman
2026-07-26 4:16 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 08/10] s390/vfio_ccw: move cp cleanup out of not operational Eric Farman
2026-07-26 4:14 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 09/10] s390/vfio_ccw: implement a channel program mutex Eric Farman
2026-07-26 4:18 ` sashiko-bot
2026-07-26 4:01 ` [PATCH v5 10/10] s390/vfio_ccw: implement a crw lock Eric Farman
2026-07-26 4:27 ` sashiko-bot [this message]
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=20260726042748.222791F000E9@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.