linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: syzbot <syzbot+44e64397bd81d5e84cba@syzkaller.appspotmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-usb@vger.kernel.org, linux-media@vger.kernel.org,
	syzkaller-bugs@googlegroups.com
Subject: Re: memory leak in hub_event
Date: Mon, 23 Nov 2020 16:53:45 -0500	[thread overview]
Message-ID: <20201123215345.GA721643@rowland.harvard.edu> (raw)
In-Reply-To: <000000000000cc9e3405b4cc4ff8@google.com>

Quick summary: syzbot found a memory leak in the gspca driver, 
apparently caused by a reference being taken but not released in a 
probe failure pathway.

On Mon, Nov 23, 2020 at 12:48:08PM -0800, syzbot wrote:
> Hello,
> 
> syzbot has tested the proposed patch but the reproducer is still triggering an issue:
> memory leak in usb_set_configuration
> 
> BUG: memory leak
> unreferenced object 0xffff8881268a1800 (size 1024):
>   comm "kworker/0:2", pid 3644, jiffies 4294944749 (age 12.820s)
>   hex dump (first 32 bytes):
>     48 f3 6a 26 81 88 ff ff 48 f3 6a 26 81 88 ff ff  H.j&....H.j&....
>     01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>   backtrace:
>     [<0000000089bfe22c>] kmalloc include/linux/slab.h:552 [inline]
>     [<0000000089bfe22c>] kzalloc include/linux/slab.h:664 [inline]
>     [<0000000089bfe22c>] usb_set_configuration+0x18c/0xb90 drivers/usb/core/message.c:1987
>     [<00000000207f81de>] usb_generic_driver_probe+0x8c/0xc0 drivers/usb/core/generic.c:238
>     [<000000007aa490e0>] usb_probe_device+0x5c/0x140 drivers/usb/core/driver.c:293

Okay, this does seem to pinpoint the problem.  gspca_dev_probe2() calls 
v4l2_device_register() at the start, but doesn't call 
v4l2_device_disconnect() upon failure.

I'm not at all familiar with the design of the v4l2 subsystem.  Mauro or 
Hans: Is this the right solution?

Alan Stern

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 4d02da97

Index: usb-devel/drivers/media/usb/gspca/gspca.c
===================================================================
--- usb-devel.orig/drivers/media/usb/gspca/gspca.c
+++ usb-devel/drivers/media/usb/gspca/gspca.c
@@ -1575,6 +1575,7 @@ out:
 		input_unregister_device(gspca_dev->input_dev);
 #endif
 	v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler);
+	v4l2_device_disconnect(&gspca_dev->v4l2_dev);
 	kfree(gspca_dev->usb_buf);
 	kfree(gspca_dev);
 	return ret;


  reply	other threads:[~2020-11-23 21:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20 15:15 memory leak in hub_event syzbot
2020-11-20 16:56 ` Alan Stern
2020-11-20 16:56   ` syzbot
2020-11-20 17:00     ` Alan Stern
2020-11-23 18:29       ` Andrey Konovalov
2020-11-23 18:44         ` syzbot
2020-11-23 19:32           ` Alan Stern
2020-11-23 19:42             ` syzbot
2020-11-23 19:53               ` Alan Stern
2020-11-23 20:01                 ` syzbot
2020-11-23 20:38                   ` Alan Stern
2020-11-23 20:48                     ` syzbot
2020-11-23 21:53                       ` Alan Stern [this message]
2020-11-23 22:09                         ` syzbot
2020-11-23 22:24                           ` Alan Stern
2020-11-24 11:38                             ` Hans Verkuil
2020-11-24 16:00                               ` [PATCH] media: gspca: Fix memory leak in probe Alan Stern
2020-12-02  8:58                                 ` Hans Verkuil
2020-12-02 17:20                                   ` [PATCH v2] " Alan Stern
2020-12-02 16:22                           ` memory leak in hub_event Alan Stern
2020-12-02 16:37                             ` syzbot

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=20201123215345.GA721643@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=syzbot+44e64397bd81d5e84cba@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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).