linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: syzbot <syzbot+854768b99f19e89d7f81@syzkaller.appspotmail.com>
Cc: "Bjørn Mork" <bjorn@mork.no>, linux-usb@vger.kernel.org
Subject: Re: INFO: task hung in wdm_flush
Date: Tue, 19 Nov 2019 14:21:54 +0100	[thread overview]
Message-ID: <1574169714.28617.7.camel@suse.com> (raw)

#syz test: https://github.com/google/kasan.git e96407b4

From d3d9edf17e33889e0fc4238f3d03a2dce7af30e1 Mon Sep 17 00:00:00 2001
From: Oliver Neukum <oneukum@suse.com>
Date: Tue, 19 Nov 2019 14:09:41 +0100
Subject: [PATCH] cdc-wdm: add timeout in wdm_flush()

wdm_flush() will wait forever for IO to end. If a device
happens to crash exactly at that time and becomes unresponsive or
turns rogue and malicious exactly at that time, we get unkillable
tasks. The solition is to add a sensible timeout.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/usb/class/cdc-wdm.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index f9f7c8a5e091..17de5c88a325 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -587,8 +587,9 @@ static ssize_t wdm_read
 static int wdm_flush(struct file *file, fl_owner_t id)
 {
 	struct wdm_device *desc = file->private_data;
+	int timeout;
 
-	wait_event(desc->wait,
+	timeout = wait_event_timeout(desc->wait,
 			/*
 			 * needs both flags. We cannot do with one
 			 * because resetting it would cause a race
@@ -596,7 +597,14 @@ static int wdm_flush(struct file *file, fl_owner_t id)
 			 * a disconnect
 			 */
 			!test_bit(WDM_IN_USE, &desc->flags) ||
-			test_bit(WDM_DISCONNECTING, &desc->flags));
+			test_bit(WDM_DISCONNECTING, &desc->flags),
+			/* pulled out of thin air */
+			30 * HZ);
+
+	if (!timeout) {
+		usb_kill_urb(desc->command);
+		return -EIO;
+	}
 
 	/* cannot dereference desc->intf if WDM_DISCONNECTING */
 	if (test_bit(WDM_DISCONNECTING, &desc->flags))
-- 
2.16.4


             reply	other threads:[~2019-11-19 13:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19 13:21 Oliver Neukum [this message]
2019-11-20 22:40 ` INFO: task hung in wdm_flush syzbot
2019-11-21 11:07   ` Oliver Neukum
2019-11-22  9:11     ` Dmitry Vyukov
  -- strict thread matches above, loose matches on Subject: below --
2019-08-12 12:18 syzbot
2019-11-19  9:14 ` Bjørn Mork
2019-11-19 10:31   ` Oliver Neukum
2019-11-19 11:34     ` Bjørn Mork
2019-11-23  6:52       ` Dmitry Vyukov
2020-02-10 10:06         ` Dmitry Vyukov
2020-02-10 10:09           ` Dmitry Vyukov
2020-02-10 12:46             ` Tetsuo Handa
2020-02-10 15:04               ` Dmitry Vyukov
2020-02-10 15:06                 ` Dmitry Vyukov
2020-02-10 15:21                   ` Tetsuo Handa
2020-02-11 13:55                     ` Tetsuo Handa
2020-02-11 14:11                       ` Dmitry Vyukov
2020-02-11 14:01                     ` Dmitry Vyukov

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=1574169714.28617.7.camel@suse.com \
    --to=oneukum@suse.com \
    --cc=bjorn@mork.no \
    --cc=linux-usb@vger.kernel.org \
    --cc=syzbot+854768b99f19e89d7f81@syzkaller.appspotmail.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;
as well as URLs for NNTP newsgroup(s).