* [PATCH] sound/pci/riptide or drivers/base/firmware: Fix a possible sleep-in-atomic bug
@ 2017-10-09 2:13 Jia-Ju Bai
2017-10-09 6:43 ` [alsa-devel] " Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2017-10-09 2:13 UTC (permalink / raw)
To: mcgrof, gregkh, perex, tiwai, dhowells, bhumirks, fabf
Cc: alsa-devel, linux-kernel, Jia-Ju Bai
The riptide driver may sleep under a spinlock, and the function call path is:
snd_riptide_prepare (acquire the spinlock)
setsampleformat
sendcmd
riptide_reset
try_to_load_firmware
request_firmware
_request_firmware (drivers/base/firmware_class.c)
_request_firmware_prepare
kzalloc(GFP_KERNEL) --> may sleep
To fix it, GFP_KERNEL is replaced with GFP_ATOMIC in _request_firmware_prepare.
This bug is found by my static analysis tool and my code review.
Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
drivers/base/firmware_class.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4b57cf5..d89f676 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1138,7 +1138,7 @@ static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
struct firmware_buf *buf;
int ret;
- *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
+ *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_ATOMIC);
if (!firmware) {
dev_err(device, "%s: kmalloc(struct firmware) failed\n",
__func__);
--
1.7.9.5
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [alsa-devel] [PATCH] sound/pci/riptide or drivers/base/firmware: Fix a possible sleep-in-atomic bug
2017-10-09 2:13 [PATCH] sound/pci/riptide or drivers/base/firmware: Fix a possible sleep-in-atomic bug Jia-Ju Bai
@ 2017-10-09 6:43 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2017-10-09 6:43 UTC (permalink / raw)
To: Jia-Ju Bai
Cc: mcgrof, gregkh, perex, tiwai, dhowells, bhumirks, fabf,
alsa-devel, linux-kernel
On Mon, 09 Oct 2017 04:13:16 +0200,
Jia-Ju Bai wrote:
>
> The riptide driver may sleep under a spinlock, and the function call path is:
> snd_riptide_prepare (acquire the spinlock)
> setsampleformat
> sendcmd
> riptide_reset
> try_to_load_firmware
> request_firmware
> _request_firmware (drivers/base/firmware_class.c)
> _request_firmware_prepare
> kzalloc(GFP_KERNEL) --> may sleep
>
> To fix it, GFP_KERNEL is replaced with GFP_ATOMIC in _request_firmware_prepare.
> This bug is found by my static analysis tool and my code review.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
This doesn't happen. try_to_load_firmware() aborts before the
request_firmware() call when chip == NULL, which is the case from
sendcmd().
And, moreover, the call of request_firmware() itself inside the
spinlock would be already buggy.
thanks,
Takashi
> ---
> drivers/base/firmware_class.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index 4b57cf5..d89f676 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -1138,7 +1138,7 @@ static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
> struct firmware_buf *buf;
> int ret;
>
> - *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
> + *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_ATOMIC);
> if (!firmware) {
> dev_err(device, "%s: kmalloc(struct firmware) failed\n",
> __func__);
> --
> 1.7.9.5
>
>
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-09 6:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-09 2:13 [PATCH] sound/pci/riptide or drivers/base/firmware: Fix a possible sleep-in-atomic bug Jia-Ju Bai
2017-10-09 6:43 ` [alsa-devel] " Takashi Iwai
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®