staging: rtl8723bs: Fix two possible sleep-in-atomic-context bugs in translate_scan()
authorJia-Ju Bai <baijiaju1990@gmail.com>
Wed, 20 Jun 2018 09:50:16 +0000 (17:50 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Jun 2018 13:05:05 +0000 (22:05 +0900)
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c

index 3950215..5f02919 100644 (file)
@@ -313,7 +313,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) {
@@ -445,7 +445,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;