All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [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

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 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.