Skip to content

Commit fc5d2ff

Browse files
lituo1996gregkh
authored andcommitted
IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs()
[ Upstream commit cbe71c61992c38f72c2b625b2ef25916b9f0d060 ] 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 the return value of kmalloc_array() to a local variable descp, and then assign it to tx->descp if it is not NULL. Otherwise, go to enomem. Fixes: 7724105 ("IB/hfi1: add driver files") Link: https://lore.kernel.org/r/20210806133029.194964-1-islituo@gmail.com Reported-by: TOTE Robot <oslab@tsinghua.edu.cn> Signed-off-by: Tuo Li <islituo@gmail.com> Tested-by: Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com> Acked-by: Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9b66008 commit fc5d2ff

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

  • drivers/infiniband/hw/hfi1

drivers/infiniband/hw/hfi1/sdma.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,7 @@ static void __sdma_process_event(struct sdma_engine *sde,
30283028
static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
30293029
{
30303030
int i;
3031+
struct sdma_desc *descp;
30313032

30323033
/* Handle last descriptor */
30333034
if (unlikely((tx->num_desc == (MAX_DESC - 1)))) {
@@ -3048,12 +3049,10 @@ static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
30483049
if (unlikely(tx->num_desc == MAX_DESC))
30493050
goto enomem;
30503051

3051-
tx->descp = kmalloc_array(
3052-
MAX_DESC,
3053-
sizeof(struct sdma_desc),
3054-
GFP_ATOMIC);
3055-
if (!tx->descp)
3052+
descp = kmalloc_array(MAX_DESC, sizeof(struct sdma_desc), GFP_ATOMIC);
3053+
if (!descp)
30563054
goto enomem;
3055+
tx->descp = descp;
30573056

30583057
/* reserve last descriptor for coalescing */
30593058
tx->desc_limit = MAX_DESC - 1;

0 commit comments

Comments
 (0)