From: Johan Hovold <johan@kernel.org>
To: Valentin Vidic <vvidic@valentin-vidic.from.hr>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Oliver Neukum <oneukum@suse.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com
Subject: Re: [PATCH] usb: iowarrior: fix access to freed data structure
Date: Wed, 9 Oct 2019 09:36:07 +0200 [thread overview]
Message-ID: <20191009073607.GB27819@localhost> (raw)
In-Reply-To: <20191008222307.18587-1-vvidic@valentin-vidic.from.hr>
On Wed, Oct 09, 2019 at 12:23:07AM +0200, Valentin Vidic wrote:
> struct iowarrior gets freed prematurely in iowarrior_release while
> it is still being referenced from usb_interface, so let only
> iowarrior_disconnect call iowarrior_delete.
The proposed fix is broken since release() may happen long after
disconnect(), in which case you'd now leak memory.
> Fixes: KMSAN: uninit-value in iowarrior_disconnect
Fixes tags are supposed to refer to the commit introducing the issue.
> Reported-by: syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com
> Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
> ---
> drivers/usb/misc/iowarrior.c | 35 +++++++++++++++--------------------
> 1 file changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
> index f5bed9f29e56..0492ea76c4bf 100644
> --- a/drivers/usb/misc/iowarrior.c
> +++ b/drivers/usb/misc/iowarrior.c
> @@ -638,7 +638,6 @@ static int iowarrior_open(struct inode *inode, struct file *file)
> static int iowarrior_release(struct inode *inode, struct file *file)
> {
> struct iowarrior *dev;
> - int retval = 0;
>
> dev = file->private_data;
> if (!dev)
> @@ -650,27 +649,23 @@ static int iowarrior_release(struct inode *inode, struct file *file)
> mutex_lock(&dev->mutex);
>
> if (dev->opened <= 0) {
> - retval = -ENODEV; /* close called more than once */
> mutex_unlock(&dev->mutex);
> - } else {
> - dev->opened = 0; /* we're closing now */
> - retval = 0;
> - if (dev->present) {
> - /*
> - The device is still connected so we only shutdown
> - pending read-/write-ops.
> - */
> - usb_kill_urb(dev->int_in_urb);
> - wake_up_interruptible(&dev->read_wait);
> - wake_up_interruptible(&dev->write_wait);
> - mutex_unlock(&dev->mutex);
> - } else {
> - /* The device was unplugged, cleanup resources */
> - mutex_unlock(&dev->mutex);
> - iowarrior_delete(dev);
So you cannot just remove this bit.
> - }
> + return -ENODEV; /* close called more than once */
> }
> - return retval;
> +
> + dev->opened = 0; /* we're closing now */
> + if (dev->present) {
> + /*
> + * The device is still connected so we only shutdown
> + * pending read/write ops.
> + */
> + usb_kill_urb(dev->int_in_urb);
> + wake_up_interruptible(&dev->read_wait);
> + wake_up_interruptible(&dev->write_wait);
> + }
> +
> + mutex_unlock(&dev->mutex);
> + return 0;
> }
>
> static __poll_t iowarrior_poll(struct file *file, poll_table * wait)
Johan
prev parent reply other threads:[~2019-10-09 7:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-08 22:23 [PATCH] usb: iowarrior: fix access to freed data structure Valentin Vidic
2019-10-09 7:36 ` Johan Hovold [this message]
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=20191009073607.GB27819@localhost \
--to=johan@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oneukum@suse.com \
--cc=syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com \
--cc=vvidic@valentin-vidic.from.hr \
/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).