From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: gregkh@linuxfoundation.org, johan@kernel.org, bjorn@mork.no,
mingo@kernel.org, oneukum@suse.com, viro@zeniv.linux.org.uk,
mark.rutland@arm.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] usb: cdc-wdm: Fix a sleep-in-atomic-context bug in service_outstanding_interrupt()
Date: Tue, 11 Sep 2018 09:49:31 +0200 [thread overview]
Message-ID: <20180911074930.2g6ryk7qe46cijhi@linutronix.de> (raw)
In-Reply-To: <20180901081210.16655-1-baijiaju1990@gmail.com>
On 2018-09-01 16:12:10 [+0800], Jia-Ju Bai wrote:
> wdm_in_callback() is a completion handler function for the USB driver.
> So it should not sleep. But it calls service_outstanding_interrupt(),
> which calls usb_submit_urb() with GFP_KERNEL.
At which point does wdm_in_callback() invoke
service_outstanding_interrupt()? I don't see it. I see one invocation
from wdm_read() and another from service_interrupt_work().
Also, if that would be the case, then spin_unlock_irq() in an USB
completion handler (which might run in IRQ context with interrupts
disabled) would be wrong.
> 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>
> ---
> v2:
> * Add more description.
> ---
> drivers/usb/class/cdc-wdm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
> index a0d284ef3f40..632a2bfabc08 100644
> --- a/drivers/usb/class/cdc-wdm.c
> +++ b/drivers/usb/class/cdc-wdm.c
> @@ -458,7 +458,7 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
>
> set_bit(WDM_RESPONDING, &desc->flags);
> spin_unlock_irq(&desc->iuspin);
> - rv = usb_submit_urb(desc->response, GFP_KERNEL);
> + rv = usb_submit_urb(desc->response, GFP_ATOMIC);
> spin_lock_irq(&desc->iuspin);
> if (rv) {
> dev_err(&desc->intf->dev,
Sebastian
next prev parent reply other threads:[~2018-09-11 7:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-01 8:12 Jia-Ju Bai
2018-09-11 7:49 ` Sebastian Andrzej Siewior [this message]
2018-09-11 8:00 ` [PATCH] Revert "usb: cdc-wdm: Fix a sleep-in-atomic-context bug in service_outstanding_interrupt()" Sebastian Andrzej Siewior
2018-09-11 8:25 ` [PATCH v2] usb: cdc-wdm: Fix a sleep-in-atomic-context bug in service_outstanding_interrupt() 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=20180911074930.2g6ryk7qe46cijhi@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=baijiaju1990@gmail.com \
--cc=bjorn@mork.no \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=oneukum@suse.com \
--cc=viro@zeniv.linux.org.uk \
/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®