[Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop

Konstantin Khorenko khorenko at virtuozzo.com
Thu Nov 19 19:19:49 MSK 2026


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



More information about the Devel mailing list