[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210805122412.130007-1-islituo@gmail.com>
Date: Thu, 5 Aug 2021 05:24:12 -0700
From: Tuo Li <islituo@...il.com>
To: mike.marciniszyn@...nelisnetworks.com,
dennis.dalessandro@...nelisnetworks.com, dledford@...hat.com,
jgg@...pe.ca
Cc: linux-rdma@...r.kernel.org, linux-kernel@...r.kernel.org,
baijiaju1990@...il.com, Tuo Li <islituo@...il.com>,
TOTE Robot <oslab@...nghua.edu.cn>
Subject: [PATCH] IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs()
kmalloc_array() is called to allocate memory for tx->descp. If it fails,
the function __sdma_txclean() is called:
__sdma_txclean(dd, tx);
However, in the function __sdma_txclean(), tx-descp is dereferenced if
tx->num_desc is not zero:
sdma_unmap_desc(dd, &tx->descp[0]);
To fix this possible null-pointer dereference, assign 0 to tx->num_desc if
kmalloc_array() returns NULL.
Reported-by: TOTE Robot <oslab@...nghua.edu.cn>
Signed-off-by: Tuo Li <islituo@...il.com>
---
drivers/infiniband/hw/hfi1/sdma.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c
index eb15c310d63d..00e29c3dfe96 100644
--- a/drivers/infiniband/hw/hfi1/sdma.c
+++ b/drivers/infiniband/hw/hfi1/sdma.c
@@ -3079,8 +3079,10 @@ static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
MAX_DESC,
sizeof(struct sdma_desc),
GFP_ATOMIC);
- if (!tx->descp)
+ if (!tx->descp) {
+ tx->num_desc = 0;
goto enomem;
+ }
/* reserve last descriptor for coalescing */
tx->desc_limit = MAX_DESC - 1;
--
2.25.1
Powered by blists - more mailing lists