From patchwork Tue Nov 24 16:00:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Stern X-Patchwork-Id: 11929297 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=ham 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 7D022C63777 for ; Tue, 24 Nov 2020 16:00:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FACC20715 for ; Tue, 24 Nov 2020 16:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389954AbgKXQA2 (ORCPT ); Tue, 24 Nov 2020 11:00:28 -0500 Received: from netrider.rowland.org ([192.131.102.5]:32883 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S2389913AbgKXQA2 (ORCPT ); Tue, 24 Nov 2020 11:00:28 -0500 Received: (qmail 750208 invoked by uid 1000); 24 Nov 2020 11:00:26 -0500 Date: Tue, 24 Nov 2020 11:00:26 -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] media: gspca: Fix memory leak in probe Message-ID: <20201124160026.GA749809@rowland.harvard.edu> References: <20201123215345.GA721643@rowland.harvard.edu> <0000000000004b629f05b4cd7124@google.com> <20201123222428.GB721643@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-media@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_disconnect(), 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: --- This doesn't fully fix syzbot's test case, because the test goes on and encounters another memory leak in a different driver. [as1949] 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_disconnect(&gspca_dev->v4l2_dev); kfree(gspca_dev->usb_buf); kfree(gspca_dev); return ret;