mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: gregkh@linuxfoundation.org, quytelda@tamalin.org,
	Larry.Finger@lwfinger.net, harshasharmaiitr@gmail.com,
	arushisinghal19971997@gmail.com, amitoj1606@gmail.com,
	jeremy.lefaure@lse.epita.fr, teo.dacquet@gmail.com
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] staging: rtl8723bs: Fix two possible sleep-in-atomic-context bugs in translate_scan()
Date: Wed, 20 Jun 2018 17:50:16 +0800	[thread overview]
Message-ID: <20180620095016.8484-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.7 are:

[FUNC] kzalloc(GFP_KERNEL)
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 323: 
		kzalloc in translate_scan
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1554: 
		translate_scan in rtw_wx_get_scan
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1533: 
		spin_lock_bh in rtw_wx_get_scan

[FUNC] kzalloc(GFP_KERNEL)
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 455: 
		kzalloc in translate_scan
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1554: 
		translate_scan in rtw_wx_get_scan
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1533: 
		spin_lock_bh in rtw_wx_get_scan

To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC.

These bugs are found by my static analysis tool (DSAC-2) and checked by
my code review.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index b26533983864..7632b8974563 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -321,7 +321,7 @@ static char *translate_scan(struct adapter *padapter,
 		RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: ssid =%s\n", pnetwork->network.Ssid.Ssid));
 		RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len));
 
-		buf = kzalloc(MAX_WPA_IE_LEN*2, GFP_KERNEL);
+		buf = kzalloc(MAX_WPA_IE_LEN*2, GFP_ATOMIC);
 		if (!buf)
 			return start;
 		if (wpa_len > 0) {
@@ -453,7 +453,7 @@ static char *translate_scan(struct adapter *padapter,
 		u8 *buf;
 		u8 *p, *pos;
 
-		buf = kzalloc(MAX_WPA_IE_LEN, GFP_KERNEL);
+		buf = kzalloc(MAX_WPA_IE_LEN, GFP_ATOMIC);
 		if (!buf)
 			goto exit;
 		p = buf;
-- 
2.17.0


             reply	other threads:[~2018-06-20  9:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20  9:50 Jia-Ju Bai [this message]
2018-06-20  9:56 ` Dan Carpenter
2018-06-20 10:05   ` Jia-Ju Bai
2018-06-20 10:22     ` Dan Carpenter

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=20180620095016.8484-1-baijiaju1990@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=amitoj1606@gmail.com \
    --cc=arushisinghal19971997@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=harshasharmaiitr@gmail.com \
    --cc=jeremy.lefaure@lse.epita.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quytelda@tamalin.org \
    --cc=teo.dacquet@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

all inboxes | Powered by JetHome®