Skip to content

Commit a1e627a

Browse files
Dan Carpenterstorulf
authored andcommitted
mmc: mmc_test: Fix NULL dereference on allocation failure
If the "test->highmem = alloc_pages()" allocation fails then calling __free_pages(test->highmem) will result in a NULL dereference. Also change the error code to -ENOMEM instead of returning success. Fixes: 2661081 ("mmc_test: highmem tests") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 6275c7b commit a1e627a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/mmc/core/mmc_test.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,20 +3125,21 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
31253125
test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
31263126
#ifdef CONFIG_HIGHMEM
31273127
test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
3128+
if (!test->highmem) {
3129+
count = -ENOMEM;
3130+
goto free_test_buffer;
3131+
}
31283132
#endif
31293133

3130-
#ifdef CONFIG_HIGHMEM
3131-
if (test->buffer && test->highmem) {
3132-
#else
31333134
if (test->buffer) {
3134-
#endif
31353135
mutex_lock(&mmc_test_lock);
31363136
mmc_test_run(test, testcase);
31373137
mutex_unlock(&mmc_test_lock);
31383138
}
31393139

31403140
#ifdef CONFIG_HIGHMEM
31413141
__free_pages(test->highmem, BUFFER_ORDER);
3142+
free_test_buffer:
31423143
#endif
31433144
kfree(test->buffer);
31443145
kfree(test);

0 commit comments

Comments
 (0)