lkml.org 
[lkml]   [2019]   [Jan]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] scsi: be2iscsi: fix potential NULL pointer dereference
Date
From: Dmitry Voytik <voytikd@gmail.com>

Fix potential NULL pointer dereference wich might happen
in function beiscsi_alloc_mem() if kmalloc_array() for
mem_descr->mem_array fails and as a result deref of NULL
occurs while passing parameters to dma_free_coherent().

Signed-off-by: Dmitry Voytik <voytikd@gmail.com>
---
drivers/scsi/be2iscsi/be_main.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 74e260027c7d..7867f7d2aca7 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -2527,8 +2527,11 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
mem_descr->size_in_bytes = phba->mem_req[i];
mem_descr->mem_array = kmalloc_array(j, sizeof(*mem_arr),
GFP_KERNEL);
- if (!mem_descr->mem_array)
+ if (!mem_descr->mem_array) {
+ /* mem_array must point to valid memory. */
+ mem_descr->mem_array = mem_arr_orig;
goto free_mem;
+ }

memcpy(mem_descr->mem_array, mem_arr_orig,
sizeof(struct mem_array) * j);
--
2.20.1
\
 
 \ /
  Last update: 2019-01-16 00:52    [W:0.025 / U:5.140 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site