* [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
@ 2026-11-18 19:00 Denis V. Lunev
2026-11-18 19:05 ` no-reply
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Denis V. Lunev @ 2026-11-18 19:00 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis; +Cc: devel
From: Denis V. Lunev <den@openvz.org>
ploop_try_delay_enospc() tests wants_suspend and adds the pio to
enospc_pios without deferred_lock, then arms enospc_timer and queues
event_work. Nothing keeps the struct ploop alive once the pio is on the
list. An endio that stalls after llist_add() can see ploop_presuspend()
set wants_suspend and resubmit the pio, the retry fail and complete the
request, and the device go away. The endio then calls mod_timer() and
schedule_work() on the freed struct ploop. timer_shutdown_sync() and
cancel_work_sync() in ploop_destroy() cannot close that, as the endio
writes into the freed memory itself.
Hold deferred_lock from the wants_suspend test through schedule_work().
ploop_presuspend() sets wants_suspend under the same lock, so either it
finds the pio on enospc_pios with the timer and the work already armed,
or the endio sees wants_suspend and leaves the request to its caller to
complete. The endio does not touch the struct ploop after the unlock.
https://virtuozzo.atlassian.net/browse/VSTOR-154847
Fixes: 6ddad5a4d226 ("dm-ploop: Add ploop target driver")
Feature: dm-ploop: ploop target driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Tested with an injected delay after llist_add() and the device
suspended and removed while the endio is held: the stock module oopses
in lock_timer_base() on the poisoned timer, the patched one makes the
suspend wait for the lock and stays clean.
drivers/md/dm-ploop-map.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 58d1c7092602..c62b414862b1 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -182,7 +182,9 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
struct ploop *ploop = pio->ploop;
unsigned long flags;
+ spin_lock_irqsave(&ploop->deferred_lock, flags);
if (unlikely(ploop->wants_suspend)) {
+ spin_unlock_irqrestore(&ploop->deferred_lock, flags);
PL_WARN("dropping pio enospc\n");
return false;
}
@@ -191,13 +193,12 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
pr_err_once(PL_FMT("underlying disk is almost full"),
ploop_device_name(ploop));
- spin_lock_irqsave(&ploop->deferred_lock, flags);
ploop->event_enospc = true;
- spin_unlock_irqrestore(&ploop->deferred_lock, flags);
llist_add((struct llist_node *)(&pio->list), &ploop->enospc_pios);
mod_timer(&ploop->enospc_timer, jiffies + PLOOP_ENOSPC_TIMEOUT);
schedule_work(&ploop->event_work);
+ spin_unlock_irqrestore(&ploop->deferred_lock, flags);
return true;
}
--
2.55.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
2026-11-18 19:00 [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop Denis V. Lunev
@ 2026-11-18 19:05 ` no-reply
2026-11-19 8:00 ` Alexander Ivanov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2026-11-18 19:05 UTC (permalink / raw)
To: Denis V. Lunev, alexander.ivanov, vasileios.almpanis; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dm-ploop: commit message overstates that ploop is not touched
after unlock
--
commit c20cb19ac7026c7127a0f474371e642c3aa24b0b
Author: Denis V. Lunev <den@openvz.org>
dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
The commit takes deferred_lock before the wants_suspend test in ploop_try_delay_enospc() and holds it through mod_timer() and schedule_work(). The aim is to stop the endio from touching a freed struct ploop after the pio is queued on enospc_pios.
> Hold deferred_lock from the wants_suspend test through schedule_work().
> ploop_presuspend() sets wants_suspend under the same lock, so either it
> finds the pio on enospc_pios with the timer and the work already armed,
> or the endio sees wants_suspend and leaves the request to its caller to
> complete. The endio does not touch the struct ploop after the unlock.
[Severity: Low]
Is the last sentence accurate? On the wants_suspend path, the patch drops the lock and then calls PL_WARN("dropping pio enospc\n"). PL_WARN() reads ploop->ti->table through ploop_device_name(), so struct ploop is still touched after the unlock.
This looks harmless, because no pio was queued on that path and the caller still holds the uncompleted request. The claim holds only on the path that returns true. Either move the PL_WARN() before the unlock, or limit the sentence to the case where the pio was queued.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118190006.3573492-1-den@openvz.org?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
2026-11-18 19:00 [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop Denis V. Lunev
2026-11-18 19:05 ` no-reply
@ 2026-11-19 8:00 ` Alexander Ivanov
2026-11-19 16:19 ` Konstantin Khorenko
2026-11-19 16:20 ` Konstantin Khorenko
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Ivanov @ 2026-11-19 8:00 UTC (permalink / raw)
To: Denis V. Lunev, vasileios.almpanis; +Cc: devel
On 11/18/26 20:00, Denis V. Lunev wrote:
> From: Denis V. Lunev <den@openvz.org>
>
> ploop_try_delay_enospc() tests wants_suspend and adds the pio to
> enospc_pios without deferred_lock, then arms enospc_timer and queues
> event_work. Nothing keeps the struct ploop alive once the pio is on the
> list. An endio that stalls after llist_add() can see ploop_presuspend()
> set wants_suspend and resubmit the pio, the retry fail and complete the
> request, and the device go away. The endio then calls mod_timer() and
> schedule_work() on the freed struct ploop. timer_shutdown_sync() and
> cancel_work_sync() in ploop_destroy() cannot close that, as the endio
> writes into the freed memory itself.
>
> Hold deferred_lock from the wants_suspend test through schedule_work().
> ploop_presuspend() sets wants_suspend under the same lock, so either it
> finds the pio on enospc_pios with the timer and the work already armed,
> or the endio sees wants_suspend and leaves the request to its caller to
> complete. The endio does not touch the struct ploop after the unlock.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-154847
>
> Fixes: 6ddad5a4d226 ("dm-ploop: Add ploop target driver")
> Feature: dm-ploop: ploop target driver
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> ---
> Tested with an injected delay after llist_add() and the device
> suspended and removed while the endio is held: the stock module oopses
> in lock_timer_base() on the poisoned timer, the patched one makes the
> suspend wait for the lock and stays clean.
>
> drivers/md/dm-ploop-map.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
> index 58d1c7092602..c62b414862b1 100644
> --- a/drivers/md/dm-ploop-map.c
> +++ b/drivers/md/dm-ploop-map.c
> @@ -182,7 +182,9 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
> struct ploop *ploop = pio->ploop;
> unsigned long flags;
>
> + spin_lock_irqsave(&ploop->deferred_lock, flags);
> if (unlikely(ploop->wants_suspend)) {
> + spin_unlock_irqrestore(&ploop->deferred_lock, flags);
> PL_WARN("dropping pio enospc\n");
> return false;
> }
> @@ -191,13 +193,12 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
>
> pr_err_once(PL_FMT("underlying disk is almost full"),
> ploop_device_name(ploop));
I'd move pr_err_once() out from under the lock, but it's not critical.
LGTM
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> - spin_lock_irqsave(&ploop->deferred_lock, flags);
> ploop->event_enospc = true;
> - spin_unlock_irqrestore(&ploop->deferred_lock, flags);
> llist_add((struct llist_node *)(&pio->list), &ploop->enospc_pios);
>
> mod_timer(&ploop->enospc_timer, jiffies + PLOOP_ENOSPC_TIMEOUT);
> schedule_work(&ploop->event_work);
> + spin_unlock_irqrestore(&ploop->deferred_lock, flags);
>
> return true;
> }
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
2026-11-18 19:00 [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop Denis V. Lunev
2026-11-18 19:05 ` no-reply
2026-11-19 8:00 ` Alexander Ivanov
@ 2026-11-19 16:19 ` Konstantin Khorenko
2026-11-19 16:20 ` Konstantin Khorenko
3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:19 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying with these fixes on my side:
- Fixes: 6ddad5a4d226 -> 90bb85536272, the driver add in this branch;
6ddad5a4d226 is not reachable from it
- "The endio does not touch the struct ploop after the unlock" ->
"ploop_try_delay_enospc() does not touch the struct ploop after the
unlock": its callers still do, see below
- the first paragraph split before "An endio that stalls"
Separate patches, not needed for this one. I created a task for each:
1. After the request completes, a split write still frees the child
pio into ploop->pio_pool in ploop_do_pio_endio(), and a write that
allocated a cluster still runs ploop_bat_write_finish() and
ploop_put_piwb() on the ploop. From an async fs completion this can
run after ploop_destroy(); not specific to ENOSPC and older than
this patch.
https://virtuozzo.atlassian.net/browse/VSTOR-155932
2. dm-qcow2 has the same window: qcow2_try_delay_enospc() arms
enospc_timer and queues event_work after dropping event_lock, and
the destroy path neither shuts the timer down nor cancels the work.
https://virtuozzo.atlassian.net/browse/VSTOR-155933
On Wed, 18 Nov 2026 20:00:06 +0100, Denis V. Lunev wrote:
> Hold deferred_lock from the wants_suspend test through schedule_work().
> ploop_presuspend() sets wants_suspend under the same lock, so either it
> finds the pio on enospc_pios with the timer and the work already armed,
> or the endio sees wants_suspend and leaves the request to its caller to
> complete. The endio does not touch the struct ploop after the unlock.
The fix itself is right: no lock order or context problem, and
nothing calls an endio under deferred_lock.
> pr_err_once(PL_FMT("underlying disk is almost full"),
> ploop_device_name(ploop));
Alexander suggested taking this pr_err_once() out from under the
lock. I keep it where the patch has it; the options were:
- After the unlock: no. ploop_device_name() reads ploop->ti->table,
the md and disk->disk_name. Once the pio is on enospc_pios,
presuspend can resubmit it, the request complete and a remove free
all of them, so the first ENOSPC delay after module load could read
freed memory: the use-after-free this patch closes.
- Copy the name into a DISK_NAME_LEN buffer under the lock and print
after the unlock: correct, but it copies the name on every delayed
pio, or needs a "once" flag of its own, for a message printed once.
- Before spin_lock_irqsave(): safe, the request pins the device until
the pio is queued, but the message then also comes on the
wants_suspend path, which does not delay the pio.
- Under the lock, as now: printk is fine with interrupts off and the
console path does not take deferred_lock; the cost is one console
write under the lock, once per module load.
Thanks.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
2026-11-18 19:00 [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop Denis V. Lunev
` (2 preceding siblings ...)
2026-11-19 16:19 ` Konstantin Khorenko
@ 2026-11-19 16:20 ` Konstantin Khorenko
3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:20 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis, Denis V. Lunev; +Cc: devel
On Wed, 18 Nov 2026 20:00:06 +0100, Denis V. Lunev wrote:
> dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.4.vz10, thanks!
[1/1] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/decb21b6b42e
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-19 16:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 19:00 [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop Denis V. Lunev
2026-11-18 19:05 ` no-reply
2026-11-19 8:00 ` Alexander Ivanov
2026-11-19 16:19 ` Konstantin Khorenko
2026-11-19 16:20 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox