Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm stats: limit the number of entries

The kvmalloc function fails with a warning if the size is larger than
INT_MAX. Linus said that there should be limits that prevent this warning
from being hit. This commit adds the limits to the dm-stats subsystem
in DM core.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>

authored by

Mikulas Patocka and committed by
Mike Snitzer
9cf11ce0 bd504bcf

+9
+9
drivers/md/dm-stats.c
··· 66 66 unsigned int last_rw; 67 67 }; 68 68 69 + #define DM_STAT_MAX_ENTRIES 8388608 70 + #define DM_STAT_MAX_HISTOGRAM_ENTRIES 134217728 71 + 69 72 /* 70 73 * A typo on the command line could possibly make the kernel run out of memory 71 74 * and crash. To prevent the crash we account all used memory. We fail if we ··· 288 285 if (n_entries != (size_t)n_entries || !(size_t)(n_entries + 1)) 289 286 return -EOVERFLOW; 290 287 288 + if (n_entries > DM_STAT_MAX_ENTRIES) 289 + return -EOVERFLOW; 290 + 291 291 shared_alloc_size = struct_size(s, stat_shared, n_entries); 292 292 if ((shared_alloc_size - sizeof(struct dm_stat)) / sizeof(struct dm_stat_shared) != n_entries) 293 293 return -EOVERFLOW; ··· 301 295 302 296 histogram_alloc_size = (n_histogram_entries + 1) * (size_t)n_entries * sizeof(unsigned long long); 303 297 if (histogram_alloc_size / (n_histogram_entries + 1) != (size_t)n_entries * sizeof(unsigned long long)) 298 + return -EOVERFLOW; 299 + 300 + if ((n_histogram_entries + 1) * (size_t)n_entries > DM_STAT_MAX_HISTOGRAM_ENTRIES) 304 301 return -EOVERFLOW; 305 302 306 303 if (!check_shared_memory(shared_alloc_size + histogram_alloc_size +