linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ath9k: fix possible sleep-in-atomic-context bugs in hif_usb_send_regout()
@ 2019-12-18 11:45 Jia-Ju Bai
  2019-12-18 12:02 ` Kalle Valo
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2019-12-18 11:45 UTC (permalink / raw)
  To: ath9k-devel, kvalo, davem
  Cc: linux-wireless, netdev, linux-kernel, Jia-Ju Bai

The driver may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:

drivers/net/wireless/ath/ath9k/hif_usb.c, 108: 
	usb_alloc_urb(GFP_KERNEL) in hif_usb_send_regout
drivers/net/wireless/ath/ath9k/hif_usb.c, 470: 
	hif_usb_send_regout in hif_usb_send
drivers/net/wireless/ath/ath9k/htc_hst.c, 34: 
	(FUNC_PTR)hif_usb_send in htc_issue_send
drivers/net/wireless/ath/ath9k/htc_hst.c, 295: 
	htc_issue_send in htc_send
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 250: 
	htc_send in ath9k_htc_send_beacon
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 207: 
	spin_lock_bh in ath9k_htc_send_beacon

drivers/net/wireless/ath/ath9k/hif_usb.c, 112: 
	kzalloc(GFP_KERNEL) in hif_usb_send_regout
drivers/net/wireless/ath/ath9k/hif_usb.c, 470: 
	hif_usb_send_regout in hif_usb_send
drivers/net/wireless/ath/ath9k/htc_hst.c, 34: 
	(FUNC_PTR)hif_usb_send in htc_issue_send
drivers/net/wireless/ath/ath9k/htc_hst.c, 295: 
	htc_issue_send in htc_send
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 250: 
	htc_send in ath9k_htc_send_beacon
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 207: 
	spin_lock_bh in ath9k_htc_send_beacon

drivers/net/wireless/ath/ath9k/hif_usb.c, 127: 
	usb_submit_urb(GFP_KERNEL) in hif_usb_send_regout
drivers/net/wireless/ath/ath9k/hif_usb.c, 470: 
	hif_usb_send_regout in hif_usb_send
drivers/net/wireless/ath/ath9k/htc_hst.c, 34: 
	(FUNC_PTR)hif_usb_send in htc_issue_send
drivers/net/wireless/ath/ath9k/htc_hst.c, 295: 
	htc_issue_send in htc_send
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 250: 
	htc_send in ath9k_htc_send_beacon
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 207: 
	spin_lock_bh in ath9k_htc_send_beacon

(FUNC_PTR) means a function pointer is called.

To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC.

These bugs are found by a static analysis tool STCheck written by myself.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/net/wireless/ath/ath9k/hif_usb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
index fb649d85b8fc..37231fde102d 100644
--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
+++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -105,11 +105,11 @@ static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
 	struct cmd_buf *cmd;
 	int ret = 0;
 
-	urb = usb_alloc_urb(0, GFP_KERNEL);
+	urb = usb_alloc_urb(0, GFP_ATOMIC);
 	if (urb == NULL)
 		return -ENOMEM;
 
-	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+	cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
 	if (cmd == NULL) {
 		usb_free_urb(urb);
 		return -ENOMEM;
@@ -124,7 +124,7 @@ static int hif_usb_send_regout(struct hif_device_usb *hif_dev,
 			 hif_usb_regout_cb, cmd, 1);
 
 	usb_anchor_urb(urb, &hif_dev->regout_submitted);
-	ret = usb_submit_urb(urb, GFP_KERNEL);
+	ret = usb_submit_urb(urb, GFP_ATOMIC);
 	if (ret) {
 		usb_unanchor_urb(urb);
 		kfree(cmd);
-- 
2.17.1


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

* Re: [PATCH] ath9k: fix possible sleep-in-atomic-context bugs in hif_usb_send_regout()
  2019-12-18 11:45 [PATCH] ath9k: fix possible sleep-in-atomic-context bugs in hif_usb_send_regout() Jia-Ju Bai
@ 2019-12-18 12:02 ` Kalle Valo
  0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2019-12-18 12:02 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: ath9k-devel, davem, linux-wireless, netdev, linux-kernel

Jia-Ju Bai <baijiaju1990@gmail.com> writes:

> The driver may sleep while holding a spinlock.
> The function call path (from bottom to top) in Linux 4.19 is:
>
> drivers/net/wireless/ath/ath9k/hif_usb.c, 108: 
> 	usb_alloc_urb(GFP_KERNEL) in hif_usb_send_regout
> drivers/net/wireless/ath/ath9k/hif_usb.c, 470: 
> 	hif_usb_send_regout in hif_usb_send
> drivers/net/wireless/ath/ath9k/htc_hst.c, 34: 
> 	(FUNC_PTR)hif_usb_send in htc_issue_send
> drivers/net/wireless/ath/ath9k/htc_hst.c, 295: 
> 	htc_issue_send in htc_send
> drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 250: 
> 	htc_send in ath9k_htc_send_beacon
> drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 207: 
> 	spin_lock_bh in ath9k_htc_send_beacon
>
> drivers/net/wireless/ath/ath9k/hif_usb.c, 112: 
> 	kzalloc(GFP_KERNEL) in hif_usb_send_regout
> drivers/net/wireless/ath/ath9k/hif_usb.c, 470: 
> 	hif_usb_send_regout in hif_usb_send
> drivers/net/wireless/ath/ath9k/htc_hst.c, 34: 
> 	(FUNC_PTR)hif_usb_send in htc_issue_send
> drivers/net/wireless/ath/ath9k/htc_hst.c, 295: 
> 	htc_issue_send in htc_send
> drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 250: 
> 	htc_send in ath9k_htc_send_beacon
> drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 207: 
> 	spin_lock_bh in ath9k_htc_send_beacon
>
> drivers/net/wireless/ath/ath9k/hif_usb.c, 127: 
> 	usb_submit_urb(GFP_KERNEL) in hif_usb_send_regout
> drivers/net/wireless/ath/ath9k/hif_usb.c, 470: 
> 	hif_usb_send_regout in hif_usb_send
> drivers/net/wireless/ath/ath9k/htc_hst.c, 34: 
> 	(FUNC_PTR)hif_usb_send in htc_issue_send
> drivers/net/wireless/ath/ath9k/htc_hst.c, 295: 
> 	htc_issue_send in htc_send
> drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 250: 
> 	htc_send in ath9k_htc_send_beacon
> drivers/net/wireless/ath/ath9k/htc_drv_beacon.c, 207: 
> 	spin_lock_bh in ath9k_htc_send_beacon
>
> (FUNC_PTR) means a function pointer is called.
>
> To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC.
>
> These bugs are found by a static analysis tool STCheck written by myself.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>

Can someone else verify this and provide Reviewed-by?

-- 
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

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

end of thread, other threads:[~2019-12-18 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-18 11:45 [PATCH] ath9k: fix possible sleep-in-atomic-context bugs in hif_usb_send_regout() Jia-Ju Bai
2019-12-18 12:02 ` Kalle Valo

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