From: Benjamin Marzinski <bmarz...@redhat.com> [ Upstream commit 8ca719b81987be690f197e82fdb030580c0a07f3 ]
Due to the semantics of iterate_devices(), the current code allows a request-based dm table as long as it includes one request-stackable device. It is supposed to only allow tables where there are no non-request-stackable devices. Signed-off-by: Benjamin Marzinski <bmarz...@redhat.com> Reviewed-by: Mike Snitzer <snit...@kernel.org> Signed-off-by: Mikulas Patocka <mpato...@redhat.com> Signed-off-by: Sasha Levin <sas...@kernel.org> --- LLM Generated explanations, may be completely bogus: Based on my analysis of the commit and the code context, here's my assessment: **Backport Status: YES** This commit fixes a clear logic bug in the device mapper table validation code that could lead to incorrect device stacking configurations. Here's the detailed analysis: **1. The Bug:** The original code had inverted logic when checking if devices are request-stackable: - The function `device_is_rq_stackable()` returned `true` (non-zero) for stackable devices - But `iterate_devices()` stops iteration on non-zero returns and returns that non-zero value - The check `!ti->type->iterate_devices(ti, device_is_rq_stackable, NULL)` would pass if ANY device returned true (stackable), not if ALL devices were stackable **2. The Fix:** - Renamed function to `device_is_not_rq_stackable()` to clarify its purpose - Inverted the return values: returns `true` for non-stackable devices - Changed the logic check to `ti->type->iterate_devices(ti, device_is_not_rq_stackable, NULL)` without negation - Now correctly fails if ANY device is not stackable **3. Why This Should Be Backported:** a) **Fixes a real bug**: The current code allows invalid device stacking configurations where request-based DM tables could include non-request- stackable devices, potentially leading to: - Data corruption - System crashes - I/O failures b) **Small and contained fix**: The change is minimal (4 lines changed) and only affects the validation logic without changing any core functionality c) **Clear semantics**: The fix makes the code's intent clearer by renaming the function to match what it actually checks d) **No architectural changes**: This is purely a bug fix that corrects validation logic e) **Critical subsystem**: Device mapper is a critical component used in production environments for LVM, encryption, and other storage features f) **Follows stable rules**: This is exactly the type of fix stable kernels want - important bug fixes with minimal risk The commit message clearly explains the bug: "the current code allows a request-based dm table as long as it includes one request-stackable device. It is supposed to only allow tables where there are no non- request-stackable devices." This could lead to serious issues in production systems using device mapper. drivers/md/dm-table.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 24a857ff6d0b..79ba4bacd0f9 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -899,17 +899,17 @@ static bool dm_table_supports_dax(struct dm_table *t, return true; } -static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev, - sector_t start, sector_t len, void *data) +static int device_is_not_rq_stackable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) { struct block_device *bdev = dev->bdev; struct request_queue *q = bdev_get_queue(bdev); /* request-based cannot stack on partitions! */ if (bdev_is_partition(bdev)) - return false; + return true; - return queue_is_mq(q); + return !queue_is_mq(q); } static int dm_table_determine_type(struct dm_table *t) @@ -1005,7 +1005,7 @@ static int dm_table_determine_type(struct dm_table *t) /* Non-request-stackable devices can't be used for request-based dm */ if (!ti->type->iterate_devices || - !ti->type->iterate_devices(ti, device_is_rq_stackable, NULL)) { + ti->type->iterate_devices(ti, device_is_not_rq_stackable, NULL)) { DMERR("table load rejected: including non-request-stackable devices"); return -EINVAL; } -- 2.39.5