From patchwork Wed Dec 2 17:20:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Stern X-Patchwork-Id: 336484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7BA7C83014 for ; Wed, 2 Dec 2020 17:20:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FBAF21D42 for ; Wed, 2 Dec 2020 17:20:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730811AbgLBRUq (ORCPT ); Wed, 2 Dec 2020 12:20:46 -0500 Received: from netrider.rowland.org ([192.131.102.5]:58719 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S2387667AbgLBRUq (ORCPT ); Wed, 2 Dec 2020 12:20:46 -0500 Received: (qmail 1060128 invoked by uid 1000); 2 Dec 2020 12:20:04 -0500 Date: Wed, 2 Dec 2020 12:20:04 -0500 From: Alan Stern To: Hans Verkuil Cc: syzbot , 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 Message-ID: <20201202172004.GB1057740@rowland.harvard.edu> References: <20201123215345.GA721643@rowland.harvard.edu> <0000000000004b629f05b4cd7124@google.com> <20201123222428.GB721643@rowland.harvard.edu> <20201124160026.GA749809@rowland.harvard.edu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Reported-and-tested-by: syzbot+44e64397bd81d5e84cba@syzkaller.appspotmail.com CC: --- 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;