dm table: fail dm_table_create on dm_round_up overflow
authorMikulas Patocka <mpatocka@redhat.com>
Sat, 23 Nov 2013 00:52:06 +0000 (19:52 -0500)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 3 Jan 2014 04:33:29 +0000 (04:33 +0000)
commit 5b2d06576c5410c10d95adfd5c4d8b24de861d87 upstream.

The dm_round_up function may overflow to zero.  In this case,
dm_table_create() must fail rather than go on to allocate an empty array
with alloc_targets().

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

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/md/dm-table.c

index 72c0dfb..5c52582 100644 (file)
@@ -215,6 +215,11 @@ int dm_table_create(struct dm_table **result, fmode_t mode,
 
        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);
                t = NULL;