Skip to contentSkip to conversation

scsi: be2iscsi: fix potential NULL pointer dereference

PATCH New Dmitry Voytik 1 participant 1 message Jan 16, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: be2iscsi: fix potential NULL pointer dereference

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().

---

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(-)
drivers/scsi/be2iscsi/be_main.c +4 -1
index 74e260027c7d..7b8c80318c38 100644
@@ -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);
Signature · 1 line
2.20.1