Browse Source

dm stats: fix divide by zero if 'number_of_areas' arg is zero

If the number_of_areas argument was zero the kernel would crash on
div-by-zero.  Add better input validation.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org # v3.12+
Mikulas Patocka 10 năm trước cách đây
mục cha
commit
dd4c1b7d0c
1 tập tin đã thay đổi với 2 bổ sung0 xóa
  1. 2 0
      drivers/md/dm-stats.c

+ 2 - 0
drivers/md/dm-stats.c

@@ -792,6 +792,8 @@ static int message_stats_create(struct mapped_device *md,
 		return -EINVAL;
 
 	if (sscanf(argv[2], "/%u%c", &divisor, &dummy) == 1) {
+		if (!divisor)
+			return -EINVAL;
 		step = end - start;
 		if (do_div(step, divisor))
 			step++;