Skip to content

Commit 343dc69

Browse files
Dan Carpenterbjorn-helgaas
Dan Carpenter
authored andcommitted
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, ... Add a few checks to prevent that. Fixes: 13107c6 ("misc: pci_endpoint_test: Add support to provide aligned buffer addresses") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Acked-by: Kishon Vijay Abraham I <[email protected]>
1 parent 9e66317 commit 343dc69

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/misc/pci_endpoint_test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
226226
u32 src_crc32;
227227
u32 dst_crc32;
228228

229+
if (size > SIZE_MAX - alignment)
230+
goto err;
231+
229232
orig_src_addr = dma_alloc_coherent(dev, size + alignment,
230233
&orig_src_phys_addr, GFP_KERNEL);
231234
if (!orig_src_addr) {
@@ -311,6 +314,9 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
311314
size_t alignment = test->alignment;
312315
u32 crc32;
313316

317+
if (size > SIZE_MAX - alignment)
318+
goto err;
319+
314320
orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr,
315321
GFP_KERNEL);
316322
if (!orig_addr) {
@@ -369,6 +375,9 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
369375
size_t alignment = test->alignment;
370376
u32 crc32;
371377

378+
if (size > SIZE_MAX - alignment)
379+
goto err;
380+
372381
orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr,
373382
GFP_KERNEL);
374383
if (!orig_addr) {

0 commit comments

Comments
 (0)