[Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
Denis V. Lunev
den at openvz.org
Wed Nov 18 22:00:06 MSK 2026
From: Denis V. Lunev <den at 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 at 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
More information about the Devel
mailing list