From: no-reply@sashiko.virtuozzo.com
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>, den@openvz.org
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v4 09/11] dm-ploop: fix use-after-free on the last inflight_md decrement
Date: Mon, 12 Oct 2026 13:40:12 +0000 [thread overview]
Message-ID: <010701a13057a4cc-1d50ebeb-4ae1-4f7f-bf17-c13696949a2a-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261012132646.41494-10-alexander.ivanov@virtuozzo.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dm-ploop: ploop_destroy() self-deadlocks using wait_event_lock_irq() on wq.lock
--
commit e7aad5678d9b3ec2b2234a7e4beccd4508f457af
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
dm-ploop: fix use-after-free on the last inflight_md decrement
This patch moves the inflight_md decrement and wakeup to the end of the
piwb completion path, so that it is the last access to the ploop. The
decrement and wakeup are done under inflight_md_wq.lock, the waiters check
the counter under the same lock, and ploop_destroy() now waits for
inflight_md to reach zero before freeing anything.
Link: https://virtuozzo.atlassian.net/browse/VSTOR-148171
> diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
> --- a/drivers/md/dm-ploop-target.c
> +++ b/drivers/md/dm-ploop-target.c
[ ... ]
> @@ -192,6 +192,13 @@ static void ploop_destroy(struct ploop *ploop)
> if (ploop->kt_allocator)
> kthread_stop(ploop->kt_allocator->task);
>
> + /* BAT writes may still be completing from aio context */
> + spin_lock_irq(&ploop->inflight_md_wq.lock);
> + wait_event_lock_irq(ploop->inflight_md_wq,
> + !atomic_read(&ploop->inflight_md),
> + ploop->inflight_md_wq.lock);
> + spin_unlock_irq(&ploop->inflight_md_wq.lock);
> +
[Severity: High]
Can this deadlock on the waitqueue lock when inflight_md is non-zero?
ploop_destroy() takes inflight_md_wq.lock and then passes that same lock
as the lock argument to wait_event_lock_irq(). If the condition is
already true, the macro exits through its fast path and nothing goes
wrong. If inflight_md is still non-zero, the call chain is:
ploop_destroy()
spin_lock_irq(&ploop->inflight_md_wq.lock)
wait_event_lock_irq()
__wait_event_lock_irq()
___wait_event()
prepare_to_wait_event()
spin_lock_irqsave(&wq_head->lock, flags)
prepare_to_wait_event() acquires wq_head->lock, which is the lock the
caller already holds. The spinlock is not recursive, so the task would
spin on itself with interrupts disabled. The spin_unlock_irq() inside the
macro, before schedule(), is never reached.
This is the case the patch is meant to handle, namely BAT writes still
completing from aio context when ploop_destroy() runs.
wait_event_lock_irq() looks only usable when the lock argument is a
different lock from the waitqueue's own lock. ploop_suspend_submitting_pios()
uses wait_event_interruptible_locked_irq() for this situation.
Would it work to drop the outer spin_lock_irq()/spin_unlock_irq() and use a
plain wait_event() here, since the waker already takes the waitqueue lock
in wake_up_locked()? Alternatively, a *_locked_irq style wait could be
used, as in ploop_suspend_submitting_pios().
> WARN_ON(!llist_empty(&ploop->pios[PLOOP_LIST_PREPARE]));
> WARN_ON(!llist_empty(&ploop->llresubmit_pios));
> WARN_ON(!llist_empty(&ploop->enospc_pios));
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261012132646.41494-1-alexander.ivanov@virtuozzo.com?part=9
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-10-12 13:41 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 13:26 [Devel] [PATCH hci-8.1 v4 00/11] dm-ploop: give back unused tail of top delta on suspend Alexander Ivanov
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 01/11] dm-ploop: fix u32 overflow of the delta BAT byte size Alexander Ivanov
2026-10-12 13:33 ` no-reply
2026-10-13 6:42 ` Alexander Ivanov
2026-10-13 7:00 ` Alexander Ivanov
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 02/11] dm-ploop: fix lost wakeup in ploop_allocator() Alexander Ivanov
2026-10-12 13:30 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 03/11] dm-ploop: reject a delta header whose BAT does not cover the target Alexander Ivanov
2026-10-12 13:31 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 04/11] dm-ploop: reject empty deltas Alexander Ivanov
2026-10-12 13:32 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 05/11] dm-ploop: set delta is_raw before applying its mappings Alexander Ivanov
2026-10-12 13:34 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 06/11] dm-ploop: factor out ploop_read_delta() from ploop_add_delta() Alexander Ivanov
2026-10-12 13:34 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 07/11] dm-ploop: take bat_lock around md page lookup in ploop_llseek_hole() Alexander Ivanov
2026-10-12 13:36 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 08/11] dm-ploop: use wake_up() for inflight_md_wq and dispatcher_wq_prealloc Alexander Ivanov
2026-10-12 13:35 ` no-reply
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 09/11] dm-ploop: fix use-after-free on the last inflight_md decrement Alexander Ivanov
2026-10-12 13:40 ` no-reply [this message]
2026-10-13 6:54 ` Alexander Ivanov
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 10/11] dm-ploop: reload metadata on resume Alexander Ivanov
2026-10-12 13:44 ` no-reply
2026-10-13 7:04 ` Alexander Ivanov
2026-10-12 13:26 ` [Devel] [PATCH hci-8.1 v4 11/11] dm-ploop: truncate unused tail of top delta on suspend Alexander Ivanov
2026-10-12 13:47 ` no-reply
2026-10-13 7:08 ` Alexander Ivanov
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=010701a13057a4cc-1d50ebeb-4ae1-4f7f-bf17-c13696949a2a-000000@eu-central-1.amazonses.com \
--to=no-reply@sashiko.virtuozzo.com \
--cc=alexander.ivanov@virtuozzo.com \
--cc=den@openvz.org \
--cc=devel@openvz.org \
/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