Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] dm persistent data: lost shadow root on -ENODATA in remove_one() --
commit 4eeca185df6005174039047dc72433972f6d625f Author: Mikulas Patocka <[email protected]> dm persistent data: assign new_root only when removal succeeds This commit changes remove_one() to update *new_root only when r is 0, so that uninitialized spine.root is not read on error. > diff --git a/drivers/md/persistent-data/dm-btree-remove.c > b/drivers/md/persistent-data/dm-btree-remove.c > index 18f53c6722027..cdcaf36bbc9e9 100644 > --- a/drivers/md/persistent-data/dm-btree-remove.c > +++ b/drivers/md/persistent-data/dm-btree-remove.c > @@ -755,7 +755,8 @@ static int remove_one(struct dm_btree_info *info, > dm_block_t root, > r = -ENODATA; > > out: > - *new_root = shadow_root(&spine); > + if (!r) > + *new_root = shadow_root(&spine); > exit_shadow_spine(&spine); > > return r; [Severity: High] Does skipping *new_root = shadow_root(&spine) when r == -ENODATA leak the new shadow root block and leave *new_root pointing to a freed block? remove_one() only sets r = -ENODATA after remove_raw() and remove_nearest() have already called shadow_step() on root. If root was not already in the transaction manager's shadow table (for example, on the first iteration of dm_btree_remove_leaves() when no key lies in the target range, or after insert_shadow() silently drops a GFP_NOIO allocation), __shadow_block() allocates a new block for spine.root and decrements the old root block's reference count. Because dm_btree_remove_leaves() treats -ENODATA as normal completion: drivers/md/persistent-data/dm-btree-remove.c:dm_btree_remove_leaves() { do { r = remove_one(info, root, first_key, end_key, &root, nr_removed); if (!r) (*nr_removed)++; } while (!r); *new_root = root; return r == -ENODATA ? 0 : r; } not updating *new_root on -ENODATA discards the newly allocated shadow root and returns 0 with *new_root still referencing the old root block whose space-map reference count was already decremented. Checking if (!r || r == -ENODATA) would avoid reading an uninitialized spine.root on I/O errors while preserving the shadowed root on -ENODATA. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
