Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dm-verity: race between verity_message() and __dm_destroy() postsuspend --
commit f3898ae3e053835b95d79be7c97db5541a15ab64 Author: Yongpeng Yang <[email protected]> dm-verity: add messages to prefetch and drop the hash cache This commit adds the prefetch_hash and drop_hash target messages to dm-verity to allow userspace to warm or evict blocks from the hash cache. > diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c > index 44b95dbdaebbc..04a986c343666 100644 > --- a/drivers/md/dm-verity-target.c > +++ b/drivers/md/dm-verity-target.c [ ... ] > @@ -1885,6 +1990,21 @@ static int verity_message(struct dm_target *ti, > unsigned int argc, char **argv, > if (!strcasecmp(argv[0], "retain_bytes")) > return verity_retain_bytes(v, argc, argv, result, maxlen); > > + /* > + * prefetch/drop touch the bufio cache and the backing device, whose > + * reads bypass the suspended dm queue: reject them while suspended. > + */ > + if (dm_suspended(ti)) { > + DMERR("message during suspend"); > + return -EBUSY; > + } > + > + if (!strcasecmp(argv[0], "prefetch_hash")) > + return verity_prefetch_hash(v, argc, argv, result, maxlen); > + > + if (!strcasecmp(argv[0], "drop_hash")) > + return verity_drop_hash(v, argc, argv, result, maxlen); [Severity: Medium] Can verity_prefetch_hash() still race with verity_postsuspend() when an active, unsuspended device is removed? Unlike __dm_suspend(), __dm_destroy() sets DMF_SUSPENDED and immediately calls dm_table_postsuspend_targets() without an intervening synchronize_srcu(&md->io_barrier) and before waiting for md->holders to drain: drivers/md/dm.c:__dm_destroy() { ... if (!dm_suspended_md(md)) { dm_table_presuspend_targets(map); set_bit(DMF_SUSPENDED, &md->flags); set_bit(DMF_POST_SUSPENDING, &md->flags); dm_table_postsuspend_targets(map); } ... } Because target_message() only takes a holder reference (via find_device()) and does not increment md->open_count, removing an unmounted device via dev_remove() while prefetch_hash is running allows verity_postsuspend() to run concurrently with dm_bufio_prefetch(): CPU0 CPU1 target_message() dm_get_live_table() verity_message() dm_suspended(ti) -> false verity_prefetch_hash() dm_bufio_prefetch() __bufio_new() /* b->hold_count == 1 */ dm_bufio_unlock(c) dev_remove() __dm_destroy() set_bit(DMF_SUSPENDED, ...) dm_table_postsuspend_targets() verity_postsuspend() dm_bufio_client_reset() drop_buffers() <-- fails eviction / WARN_ON submit_io(...) dm_bufio_release(b) When drop_buffers() encounters the buffer held with hold_count == 1 outside dm_bufio_lock, eviction fails and triggers WARN_ON in warn_leak() and drop_buffers() (or a use-after-free if CONFIG_DM_DEBUG_BLOCK_STACK_TRACING is enabled, where warn_leak() zeroes b->hold_count and drop_buffers() frees b while __dm_bufio_prefetch() is still submitting I/O on it). -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4
