linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: syzbot <syzbot+44e64397bd81d5e84cba@syzkaller.appspotmail.com>,
	linux-media@vger.kernel.org, linux-usb@vger.kernel.org,
	mchehab@kernel.org, syzkaller-bugs@googlegroups.com
Subject: [PATCH v2] media: gspca: Fix memory leak in probe
Date: Wed, 2 Dec 2020 12:20:04 -0500	[thread overview]
Message-ID: <20201202172004.GB1057740@rowland.harvard.edu> (raw)
In-Reply-To: <eb89a572-3022-39a9-989c-f2f80cc69edf@xs4all.nl>

The gspca driver leaks memory when a probe fails.  gspca_dev_probe2()
calls v4l2_device_register(), which takes a reference to the
underlying device node (in this case, a USB interface).  But the
failure pathway neglects to call v4l2_device_unregister(), the routine
responsible for dropping this reference.  Consequently the memory for
the USB interface and its device never gets released.

This patch adds the missing function call.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: syzbot+44e64397bd81d5e84cba@syzkaller.appspotmail.com
CC: <stable@vger.kernel.org>

---

v2: Replace v4l2_device_disconnect() call with v4l2_device_unregister().


[as1949b]


 drivers/media/usb/gspca/gspca.c |    1 +
 1 file changed, 1 insertion(+)

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_unregister(&gspca_dev->v4l2_dev);
 	kfree(gspca_dev->usb_buf);
 	kfree(gspca_dev);
 	return ret;

  reply	other threads:[~2020-12-02 17:20 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
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                                   ` Alan Stern [this message]
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=20201202172004.GB1057740@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).