From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>
Cc: kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [GIT PULL v1 10/23] s390/vfio_ccw: Implement a crw lock
Date: Mon, 03 Aug 2026 16:51:48 +0000 [thread overview]
Message-ID: <20260803165150.1E2461F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803160924.236807-11-imbrenda@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing synchronization when updating eventfd triggers leads to a potential Use-After-Free of the `eventfd_ctx` during `eventfd_signal()`.
- [High] Concurrent execution of asynchronous CSS hardware callbacks and mdev removal allows a Use-After-Free of the `vfio_ccw_private` structure.
- [Medium] The `eventfd_ctx` for device triggers is leaked when the device file descriptor is closed without explicitly disabling the IRQs.
--
--- Patch [10]: [GIT PULL v1 10/23] s390/vfio_ccw: Implement a crw lock ---
commit e6c7aa37724a25bba44b60d5d9939f115e04276a
Author: Eric Farman <farman@linux.ibm.com>
s390/vfio_ccw: Implement a crw lock
Unlike the channel_program struct, which covers synchronous I/O
submissions and asynchronous interrupts, the CRW region relies
exclusively on asynchronous events coming from hardware.
Implement a lock to manage the list of those payloads, to ensure
they are read cohesively.
Cc: stable@vger.kernel.org
> diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
> index 757ff5b2556e3..ab6b518cc353f 100644
> --- a/drivers/s390/cio/vfio_ccw_drv.c
> +++ b/drivers/s390/cio/vfio_ccw_drv.c
> @@ -118,11 +118,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 is a pre-existing issue, but does this adequately protect against
concurrent modification of the eventfd context?
While this patch adds crw_lock around the read and signal path here in
vfio_ccw_crw_todo(), is the writer side in vfio_ccw_mdev_set_irqs()
also protected?
If vfio_ccw_mdev_set_irqs() replaces or unsets the eventfd without locks:
vfio_ccw_mdev_set_irqs()
if (*ctx)
eventfd_ctx_put(*ctx);
*ctx = efdctx;
Could a concurrent execution of vfio_ccw_crw_todo() read the pointer,
have the context freed by vfio_ccw_mdev_set_irqs(), and then use it in
eventfd_signal(), resulting in a use-after-free?
[ ... ]
> @@ -286,6 +289,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
> * carry on. The guest will either see a later one or
> * learn when it issues its own store subchannel.
> */
> crw = kzalloc_obj(*crw, GFP_ATOMIC);
> if (!crw)
> return;
>
> /*
> * Build the CRW based on the inputs given to us.
> */
> crw->crw.rsc = rsc;
> crw->crw.erc = erc;
> crw->crw.rsid = rsid;
>
> + spin_lock_irqsave(&private->crw_lock, flags);
> list_add_tail(&crw->next, &private->crw);
> + spin_unlock_irqrestore(&private->crw_lock, flags);
> queue_work(vfio_ccw_work_q, &private->crw_work);
> }
[Severity: High]
This is a pre-existing issue, but could vfio_ccw_queue_crw() dereference
a freed private pointer during device removal?
If an asynchronous CSS hardware callback like vfio_ccw_chp_event() fetches
the private struct locklessly, and concurrently the mdev is removed via
sysfs:
vfio_ccw_mdev_remove()
dev_set_drvdata(&parent->dev, NULL);
vfio_put_device(&private->vdev);
Since there is no synchronization stopping the CSS callback, could the
private structure be freed before vfio_ccw_chp_event() calls
vfio_ccw_queue_crw(), leading to a use-after-free when acquiring the
crw_lock here?
[ ... ]
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> index 1df6d649565b8..5ce91285c7d52 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
> @@ -131,6 +132,7 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)
> struct vfio_ccw_private *private =
> container_of(vdev, struct vfio_ccw_private, vdev);
> struct vfio_ccw_crw *crw, *temp;
> + unsigned long flags;
>
> /*
> * Ensure these work items are fully drained, so none can
> @@ -146,10 +148,12 @@ static void vfio_ccw_mdev_release_dev(struct vfio_device *vdev)
> cancel_work_sync(&private->crw_work);
> flush_work(&private->notoper_work);
>
> + spin_lock_irqsave(&private->crw_lock, flags);
> list_for_each_entry_safe(crw, temp, &private->crw, next) {
> list_del(&crw->next);
> kfree(crw);
> }
> + spin_unlock_irqrestore(&private->crw_lock, flags);
>
> kmem_cache_free(vfio_ccw_crw_region, private->crw_region);
> kmem_cache_free(vfio_ccw_schib_region, private->schib_region);
[Severity: Medium]
This isn't a bug introduced by this patch, but does closing the device leak
the eventfd contexts allocated for device triggers?
When userspace configures IRQs via VFIO_DEVICE_SET_IRQS, eventfd_ctx_fdget()
increments the reference count of the eventfd context.
If userspace closes the device without explicitly disabling the IRQs first,
vfio_ccw_mdev_release_dev() is invoked. Is it necessary to call
eventfd_ctx_put() here to release the references to private->io_trigger,
private->crw_trigger, and private->req_trigger?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260803160924.236807-1-imbrenda@linux.ibm.com?part=10
next prev parent reply other threads:[~2026-08-03 16:51 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 16:09 [GIT PULL v1 00/23] KVM: s390: Misc KVM and vfio-ccw fixes Claudio Imbrenda
2026-08-03 16:09 ` [GIT PULL v1 01/23] s390/vfio_ccw: Free all memory if cp_init() fails Claudio Imbrenda
2026-08-03 16:28 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 02/23] s390/vfio_ccw: Limit the number of channel program segments Claudio Imbrenda
2026-08-03 16:32 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 03/23] s390/vfio_ccw: Fix out of bounds check on CCW array Claudio Imbrenda
2026-08-03 16:09 ` [GIT PULL v1 04/23] s390/vfio_ccw: Ensure first IDAW remains constant Claudio Imbrenda
2026-08-03 16:24 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 05/23] s390/vfio_ccw: Calculate idal length based on idaw type Claudio Imbrenda
2026-08-03 16:24 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 06/23] s390/vfio_ccw: Ensure index for read/write regions are within range Claudio Imbrenda
2026-08-03 16:34 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 07/23] s390/vfio_ccw: Cancel existing workqueues Claudio Imbrenda
2026-08-03 16:41 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 08/23] s390/vfio_ccw: Move cp cleanup out of not operational Claudio Imbrenda
2026-08-03 16:39 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 09/23] s390/vfio_ccw: Selectively expand io_mutex Claudio Imbrenda
2026-08-03 16:54 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 10/23] s390/vfio_ccw: Implement a crw lock Claudio Imbrenda
2026-08-03 16:51 ` sashiko-bot [this message]
2026-08-03 16:09 ` [GIT PULL v1 11/23] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-08-03 16:43 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 12/23] KVM: s390: Do not free SCA if it was not allocated Claudio Imbrenda
2026-08-03 16:49 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 13/23] KVM: s390: Fix kvm_s390_vcpu_unsetup_cmma() Claudio Imbrenda
2026-08-03 16:54 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 14/23] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-08-03 17:03 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 15/23] KVM: s390: ucontrol: Fix sca_clear_ext_call() Claudio Imbrenda
2026-08-03 17:09 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 16/23] KVM: s390: Fix leaking of PGM_ADDRESSING to userspace Claudio Imbrenda
2026-08-03 17:14 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 17/23] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
2026-08-03 17:04 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 18/23] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
2026-08-03 17:12 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 19/23] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
2026-08-03 17:19 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 20/23] KVM: s390: Free the mmu cache when kvm_arch_vcpu_create() fails Claudio Imbrenda
2026-08-03 17:13 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 21/23] KVM: s390: Return -EINTR if a signal is pending while faulting-in Claudio Imbrenda
2026-08-03 17:40 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 22/23] KVM: s390: Fix ordering when adding to SCA Claudio Imbrenda
2026-08-03 17:26 ` sashiko-bot
2026-08-03 16:09 ` [GIT PULL v1 23/23] KVM: s390: Fix cleanup in kvm_s390_pv_create_cpu() Claudio Imbrenda
2026-08-03 17:19 ` sashiko-bot
2026-08-06 13:48 ` [GIT PULL v1 00/23] KVM: s390: Misc KVM and vfio-ccw fixes Paolo Bonzini
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=20260803165150.1E2461F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@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