From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: dledford@redhat.com, jgg@ziepe.ca, leon@kernel.org,
ira.weiny@intel.com, pravin.shedge4linux@gmail.com,
hal@mellanox.com, parav@mellanox.com, haakon.bugge@oracle.com,
bart.vanassche@sandisk.com
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] infiniband: core: mad: Fix a sleep-in-atomic-context bug in ib_mad_recv_done()
Date: Sat, 1 Sep 2018 20:06:59 +0800 [thread overview]
Message-ID: <20180901120659.32509-1-baijiaju1990@gmail.com> (raw)
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16 are:
[FUNC] alloc_mad_private(GFP_KERNEL)
drivers/infiniband/core/mad.c, 2264:
alloc_mad_private in ib_mad_recv_done
drivers/infiniband/core/cq.c, 45:
[FUNC_PTR]ib_mad_recv_done in __ib_process_cq
drivers/infiniband/core/cq.c, 77:
__ib_process_cq in ib_process_cq_direct
drivers/infiniband/ulp/srp/ib_srp.c, 2010:
ib_process_cq_direct in __srp_get_tx_iu
drivers/infiniband/ulp/srp/ib_srp.c, 2353:
__srp_get_tx_iu in srp_queuecommand
drivers/infiniband/ulp/srp/ib_srp.c, 2352:
_raw_spin_lock_irqsave in srp_queuecommand
[FUNC] alloc_mad_private(GFP_KERNEL)
drivers/infiniband/core/mad.c, 2264:
alloc_mad_private in ib_mad_recv_done
drivers/infiniband/core/cq.c, 45:
[FUNC_PTR]ib_mad_recv_done in __ib_process_cq
drivers/infiniband/core/cq.c, 77:
__ib_process_cq in ib_process_cq_direct
drivers/infiniband/ulp/srp/ib_srp.c, 2010:
ib_process_cq_direct in __srp_get_tx_iu
drivers/infiniband/ulp/srp/ib_srp.c, 2903:
__srp_get_tx_iu in srp_send_tsk_mgmt
drivers/infiniband/ulp/srp/ib_srp.c, 2902:
spin_lock_irq in srp_send_tsk_mgmt
To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.
This bug is found by my static analysis tool DSAC.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/infiniband/core/mad.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index f742ae7a768b..0db954f6958a 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -2263,7 +2263,7 @@ static void ib_mad_recv_done(struct ib_cq *cq, struct ib_wc *wc)
goto out;
mad_size = recv->mad_size;
- response = alloc_mad_private(mad_size, GFP_KERNEL);
+ response = alloc_mad_private(mad_size, GFP_ATOMIC);
if (!response)
goto out;
--
2.17.0
next reply other threads:[~2018-09-01 12:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-01 12:06 Jia-Ju Bai [this message]
2018-09-02 20:32 ` [PATCH] infiniband: core: mad: Fix a sleep-in-atomic-context bug in ib_mad_recv_done() Jason Gunthorpe
2018-09-03 1:41 ` Jia-Ju Bai
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=20180901120659.32509-1-baijiaju1990@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=bart.vanassche@sandisk.com \
--cc=dledford@redhat.com \
--cc=haakon.bugge@oracle.com \
--cc=hal@mellanox.com \
--cc=ira.weiny@intel.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=parav@mellanox.com \
--cc=pravin.shedge4linux@gmail.com \
/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