From: "Marciniszyn, Mike" <mike.marciniszyn@cornelisnetworks.com>
To: Tuo Li <islituo@gmail.com>,
"Dalessandro, Dennis" <dennis.dalessandro@cornelisnetworks.com>,
"dledford@redhat.com" <dledford@redhat.com>,
"jgg@ziepe.ca" <jgg@ziepe.ca>
Cc: "linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"baijiaju1990@gmail.com" <baijiaju1990@gmail.com>,
TOTE Robot <oslab@tsinghua.edu.cn>
Subject: RE: [PATCH] IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs()
Date: Thu, 5 Aug 2021 17:46:05 +0000 [thread overview]
Message-ID: <CH0PR01MB7153B254480BACBE8D2028EFF2F29@CH0PR01MB7153.prod.exchangelabs.com> (raw)
In-Reply-To: <20210805122412.130007-1-islituo@gmail.com>
> 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@tsinghua.edu.cn>
> Signed-off-by: Tuo Li <islituo@gmail.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;
Thanks for seeing an issue here, but the correct solution is to store descp locally first.
Once the allocation is shown to be non-NULL, then store to tx-descp:
diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c
index eb15c310d..b6c554a 100644
--- a/drivers/infiniband/hw/hfi1/sdma.c
+++ b/drivers/infiniband/hw/hfi1/sdma.c
@@ -3055,6 +3055,7 @@ static void __sdma_process_event(struct sdma_engine *sde,
static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
{
int i;
+ struct sdma_desc *descp;
/* Handle last descriptor */
if (unlikely((tx->num_desc == (MAX_DESC - 1)))) {
@@ -3075,12 +3076,12 @@ static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
if (unlikely(tx->num_desc == MAX_DESC))
goto enomem;
- tx->descp = kmalloc_array(
- MAX_DESC,
- sizeof(struct sdma_desc),
- GFP_ATOMIC);
- if (!tx->descp)
+ descp = kmalloc_array(MAX_DESC,
+ sizeof(struct sdma_desc),
+ GFP_ATOMIC);
+ if (!descp)
goto enomem;
+ tx->descp = descp;
/* reserve last descriptor for coalescing */
tx->desc_limit = MAX_DESC - 1;
prev parent reply other threads:[~2021-08-05 17:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-05 12:24 [PATCH] IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs() Tuo Li
2021-08-05 17:46 ` Marciniszyn, Mike [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CH0PR01MB7153B254480BACBE8D2028EFF2F29@CH0PR01MB7153.prod.exchangelabs.com \
--to=mike.marciniszyn@cornelisnetworks.com \
--cc=baijiaju1990@gmail.com \
--cc=dennis.dalessandro@cornelisnetworks.com \
--cc=dledford@redhat.com \
--cc=islituo@gmail.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=oslab@tsinghua.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).