diff mbox

[2/2] dm-table: fail on overflow in dm_round_up

Message ID alpine.LRH.2.02.1311221951400.31923@file01.intranet.prod.int.rdu2.redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Mikulas Patocka Nov. 23, 2013, 12:52 a.m. UTC
The dm_round_up function may overflow to zero. In this case, we need to
fail, rather than allocate empty array.

This fixes a possible memory corruption that could be caused by passing
too big number in "param->target_count".

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@kernel.org

---
 drivers/md/dm-table.c |    5 +++++
 1 file changed, 5 insertions(+)


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

Index: linux-3.12-fast/drivers/md/dm-table.c
===================================================================
--- linux-3.12-fast.orig/drivers/md/dm-table.c	2013-11-22 21:24:52.000000000 +0100
+++ linux-3.12-fast/drivers/md/dm-table.c	2013-11-22 21:25:59.000000000 +0100
@@ -194,6 +194,11 @@  int dm_table_create(struct dm_table **re
 
 	num_targets = dm_round_up(num_targets, KEYS_PER_NODE);
 
+	if (!num_targets) {
+		kfree(t);
+		return -ENOMEM;
+	}
+
 	if (alloc_targets(t, num_targets)) {
 		kfree(t);
 		return -ENOMEM;