Skip to contentSkip to conversation

dm mirror: fix integer overflow in create_dirty_log()

PATCH In review Junrui Luo 2 participants 3 messages Mar 1 – Apr 5 Device mapper

lore
Share & tools
lore

Junrui Luo

author
#0 lore raw

PATCH 1/1 dm mirror: fix integer overflow in create_dirty_log()

The argument count calculation in create_dirty_log() performs *args_used = 2 + param_count before validating against argc. When a user provides a param_count close to UINT_MAX via the device mapper table string, this unsigned addition wraps around to a small value, causing the subsequent argc < *args_used check to be bypassed.

The overflowed param_count is then passed as argc to dm_dirty_log_create(), where it can cause out-of-bounds reads on the argv array.

Fix by comparing param_count against argc - 2 before performing the addition, following the same pattern used by parse_features() in the same file. Since argc >= 2 is already guaranteed, the subtraction is safe.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/md/dm-raid1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-raid1.c +3 -3
index 80a5c4127707..de5c00704e69 100644
@@ -993,13 +993,13 @@ static struct dm_dirty_log *create_dirty_log(struct dm_target *ti,
 		return NULL;
 	}
 
-	*args_used = 2 + param_count;
-
-	if (argc < *args_used) {
+	if (param_count > argc - 2) {
 		ti->error = "Insufficient mirror log arguments";
 		return NULL;
 	}
 
+	*args_used = 2 + param_count;
+
 	dl = dm_dirty_log_create(argv[0], ti, mirror_flush, param_count,
 				 argv + 2);
 	if (!dl) {

---
base-commit: 4d349ee5c7782f8b27f6cb550f112c5e26fff38d
change-id: 20260301-fixes-5b596967096c

Best regards,

Signature · 1 line
Junrui Luo <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Junrui Luo

The argument count calculation in create_dirty_log() performs *args_used = 2 + param_count before validating against argc. When a user provides a param_count close to UINT_MAX via the device mapper table string, this unsigned addition wraps around to a small value, causing the subsequent argc < *args_used check to be bypassed.

The overflowed param_count is then passed as argc to dm_dirty_log_create(), where it can cause out-of-bounds reads on the argv array.

Quoted 8 lines

Fix by comparing param_count against argc - 2 before performing the addition, following the same pattern used by parse_features() in the same file. Since argc >= 2 is already guaranteed, the subtraction is safe.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
author
#2 lore raw
In reply to Junrui Luo

Hi,

Gentle ping on this patch. It has Benjamin's Reviewed-by but hasn't been picked up yet. Could this be queued for the next merge window?

Thanks,
Junrui Luo