linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] qedi: Fix a possible sleep-in-atomic bug in qedi_process_tmf_resp
@ 2017-12-13  9:11 Jia-Ju Bai
  2017-12-13  9:12 ` Rangankar, Manish
  2017-12-19  3:33 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2017-12-13  9:11 UTC (permalink / raw)
  To: QLogic-Storage-Upstream, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, Jia-Ju Bai

The driver may sleep under a spinlock.
The function call path is:
qedi_cpu_offline (acquire the spinlock)
  qedi_fp_process_cqes
    qedi_mtask_completion
      qedi_process_tmf_resp
        kzalloc(GFP_KERNEL) --> may sleep

To fix it, GFP_KERNEL is replaced with GFP_ATOMIC.

This bug is found by my static analysis tool(DSAC) and checked by my code review.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/scsi/qedi/qedi_fw.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c
index bd302d3..20a9259 100644
--- a/drivers/scsi/qedi/qedi_fw.c
+++ b/drivers/scsi/qedi/qedi_fw.c
@@ -198,7 +198,7 @@ static void qedi_process_tmf_resp(struct qedi_ctx *qedi,
 	cqe_tmp_response = &cqe->cqe_common.iscsi_hdr.tmf_response;
 
 	qedi_cmd = task->dd_data;
-	qedi_cmd->tmf_resp_buf = kzalloc(sizeof(*resp_hdr_ptr), GFP_KERNEL);
+	qedi_cmd->tmf_resp_buf = kzalloc(sizeof(*resp_hdr_ptr), GFP_ATOMIC);
 	if (!qedi_cmd->tmf_resp_buf) {
 		QEDI_ERR(&qedi->dbg_ctx,
 			 "Failed to allocate resp buf, cid=0x%x\n",
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] qedi: Fix a possible sleep-in-atomic bug in qedi_process_tmf_resp
  2017-12-13  9:11 [PATCH] qedi: Fix a possible sleep-in-atomic bug in qedi_process_tmf_resp Jia-Ju Bai
@ 2017-12-13  9:12 ` Rangankar, Manish
  2017-12-19  3:33 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Rangankar, Manish @ 2017-12-13  9:12 UTC (permalink / raw)
  To: Jia-Ju Bai, Dept-Eng QLogic Storage Upstream,
	jejb@linux.vnet.ibm.com, martin.petersen@oracle.com
  Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org



On 13/12/17 2:41 PM, "Jia-Ju Bai" <baijiaju1990@gmail.com> wrote:

>The driver may sleep under a spinlock.
>The function call path is:
>qedi_cpu_offline (acquire the spinlock)
>  qedi_fp_process_cqes
>    qedi_mtask_completion
>      qedi_process_tmf_resp
>        kzalloc(GFP_KERNEL) --> may sleep
>
>To fix it, GFP_KERNEL is replaced with GFP_ATOMIC.
>
>This bug is found by my static analysis tool(DSAC) and checked by my code
>review.
>
>Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>---
> drivers/scsi/qedi/qedi_fw.c |    2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/scsi/qedi/qedi_fw.c b/drivers/scsi/qedi/qedi_fw.c
>index bd302d3..20a9259 100644
>--- a/drivers/scsi/qedi/qedi_fw.c
>+++ b/drivers/scsi/qedi/qedi_fw.c
>@@ -198,7 +198,7 @@ static void qedi_process_tmf_resp(struct qedi_ctx
>*qedi,
> 	cqe_tmp_response = &cqe->cqe_common.iscsi_hdr.tmf_response;
> 
> 	qedi_cmd = task->dd_data;
>-	qedi_cmd->tmf_resp_buf = kzalloc(sizeof(*resp_hdr_ptr), GFP_KERNEL);
>+	qedi_cmd->tmf_resp_buf = kzalloc(sizeof(*resp_hdr_ptr), GFP_ATOMIC);
> 	if (!qedi_cmd->tmf_resp_buf) {
> 		QEDI_ERR(&qedi->dbg_ctx,
> 			 "Failed to allocate resp buf, cid=0x%x\n",
>-- 
>1.7.9.5

Thanks,

Acked-by: Manish Rangankar <Manish.Rangankar@cavium.com>

>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] qedi: Fix a possible sleep-in-atomic bug in qedi_process_tmf_resp
  2017-12-13  9:11 [PATCH] qedi: Fix a possible sleep-in-atomic bug in qedi_process_tmf_resp Jia-Ju Bai
  2017-12-13  9:12 ` Rangankar, Manish
@ 2017-12-19  3:33 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2017-12-19  3:33 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: QLogic-Storage-Upstream, jejb, martin.petersen, linux-scsi,
	linux-kernel


Jia-Ju,

> To fix it, GFP_KERNEL is replaced with GFP_ATOMIC.
>
> This bug is found by my static analysis tool(DSAC) and checked by my
> code review.

Applied to 4.16/scsi-queue. Thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-19  3:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13  9:11 [PATCH] qedi: Fix a possible sleep-in-atomic bug in qedi_process_tmf_resp Jia-Ju Bai
2017-12-13  9:12 ` Rangankar, Manish
2017-12-19  3:33 ` Martin K. Petersen

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