* [PATCH v2] scsi: be2iscsi: fix potential NULL pointer dereference
@ 2019-01-16 22:47 Dmitry Voytik
0 siblings, 0 replies; only message in thread
From: Dmitry Voytik @ 2019-01-16 22:47 UTC (permalink / raw)
To: James E . J . Bottomley, Martin K . Petersen
Cc: Ketan Mukadam, Jitendra Bhivare, linux-scsi, linux-kernel, Dmitry Voytik
Fix potential NULL pointer dereference wich might happen in
beiscsi_alloc_mem(). If kmalloc_array() fails and mem_descr->mem_array
is set to NULL, then its dereferencing happens when passing
mem_descr->mem_array[] to dma_free_coherent().
Signed-off-by: Dmitry Voytik <voytikd@gmail.com>
---
Changes since v1:
- prevent double free by setting mem_arr_orig to NULL
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..7b8c80318c38 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_descr->mem_array = mem_arr_orig;
+ mem_arr_orig = NULL;
goto free_mem;
+ }
memcpy(mem_descr->mem_array, mem_arr_orig,
sizeof(struct mem_array) * j);
--
2.20.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-01-16 22:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-16 22:47 [PATCH v2] scsi: be2iscsi: fix potential NULL pointer dereference Dmitry Voytik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).