diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2017-09-30 04:15:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-04 04:39:28 -0400 |
commit | 378f79cab12b669928f3a4037f023837ead2ce0c (patch) | |
tree | 3c1e44ce1b50659550a0a956c2b81d7d8b778b69 | |
parent | a120fbddd59a3d04a63800824ea032dbf1c21b83 (diff) |
misc: pci_endpoint_test: Prevent some integer overflows
"size + max" can have an arithmetic overflow when we're allocating:
orig_src_addr = dma_alloc_coherent(dev, size + alignment, ...
I've added a few checks to prevent that.
Fixes: 13107c60681f ("misc: pci_endpoint_test: Add support to provide aligned buffer addresses")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/misc/pci_endpoint_test.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index deb203026496..c0d323077ad0 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c | |||
@@ -226,6 +226,9 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size) | |||
226 | u32 src_crc32; | 226 | u32 src_crc32; |
227 | u32 dst_crc32; | 227 | u32 dst_crc32; |
228 | 228 | ||
229 | if (size > SIZE_MAX - alignment) | ||
230 | goto err; | ||
231 | |||
229 | orig_src_addr = dma_alloc_coherent(dev, size + alignment, | 232 | orig_src_addr = dma_alloc_coherent(dev, size + alignment, |
230 | &orig_src_phys_addr, GFP_KERNEL); | 233 | &orig_src_phys_addr, GFP_KERNEL); |
231 | if (!orig_src_addr) { | 234 | if (!orig_src_addr) { |
@@ -311,6 +314,9 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size) | |||
311 | size_t alignment = test->alignment; | 314 | size_t alignment = test->alignment; |
312 | u32 crc32; | 315 | u32 crc32; |
313 | 316 | ||
317 | if (size > SIZE_MAX - alignment) | ||
318 | goto err; | ||
319 | |||
314 | orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, | 320 | orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, |
315 | GFP_KERNEL); | 321 | GFP_KERNEL); |
316 | if (!orig_addr) { | 322 | if (!orig_addr) { |
@@ -369,6 +375,9 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size) | |||
369 | size_t alignment = test->alignment; | 375 | size_t alignment = test->alignment; |
370 | u32 crc32; | 376 | u32 crc32; |
371 | 377 | ||
378 | if (size > SIZE_MAX - alignment) | ||
379 | goto err; | ||
380 | |||
372 | orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, | 381 | orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, |
373 | GFP_KERNEL); | 382 | GFP_KERNEL); |
374 | if (!orig_addr) { | 383 | if (!orig_addr) { |