Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp407038pxj; Thu, 20 May 2021 12:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwERlW0ByRpwH0m63i+69/bPExtN3BaWsMz4PyLx+0N3UigXh29mb5Kbev4jSIVATUHCF7U X-Received: by 2002:a05:6602:2437:: with SMTP id g23mr6674154iob.142.1621537529379; Thu, 20 May 2021 12:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621537529; cv=none; d=google.com; s=arc-20160816; b=GO3YKaRe7t5EvMVxIEg+/DyixYHbzJkiUHyCSQ2KzFsuuTTqYxCPcQ8BwawkwLrY2U k6zT8cIvIyUA+9uuXTsy6RZ3kSJjBHLbdG4RgAizAHV/htBiHQ+yXzMQ1s/GvhRd7Djo enlt8ny6sXpbw8iI+qr7QpUQs8kyjhE+yd48H/rFY3kRw6jvss6yFNSQ/OrJ3W5c9Fyl kcDv50Iq5z7uxXcdvgdP99EyxGtl4mdgszkLR0O4gMUPVgajQAX78opDoD6eOx13pdmS Y79VoSxmePWmh9RZI1FZ+v5y5E5sAMO4MYY0DqXsB6NyAS7oHK8M/GoIXJZGKHRWayD7 iMdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ObRgpdjFp+LZdxmkH5bwH1jNE7QdyE0gTrg85oC3B2w=; b=ZHVyXFTTRVYmyDU9KHf1F6p9vrNiJ8U2PlzvR76jfvCj3SXquaXb8KyUiSqOHoRIb3 CtLbW2UgPLirXS04TRB2JK5vrIpCLI+C/NgA9LVfHLL7z8T2h5t2p5vG07Sbai1KzoNR x32cmGa6EP3dCejx+H2jb8vzOu3pKiNtltBRXU+ON8OlhCBF9xhpET8bnVtmDpkxK0g0 qibkYRi7qnHHIlnJMfqAh8EfQkzgdanM69fzuDaLYei2Nho3IYD0MSozyLACPsO11Urs oIr2SBs87yZqLAjbw5CWqucD57k4KT1ipECE7vfsJlZI8/oZgs6WfFoEBcOQifmWwZuo PlMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NFX8qnpf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si3862475ilv.29.2021.05.20.12.05.15; Thu, 20 May 2021 12:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NFX8qnpf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237179AbhETKdD (ORCPT + 99 others); Thu, 20 May 2021 06:33:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:49144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236449AbhETKTh (ORCPT ); Thu, 20 May 2021 06:19:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E35EE6145C; Thu, 20 May 2021 09:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504038; bh=sdqO4KNpL4jVN8j8Qu6OmKzkDZ+/X1g/go5kI28KtLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NFX8qnpf7XsIwm9Z/R+DS9o3mwnAsU3xxmwiOzUv0TrGcdG6iGIrLnXWxjcpNXAkm o6R+2iV48trLUYGOtcHCgutZ8KvmeAsTQYxhM6Pf8D9/t0L+d4Y4lAYj8LiO0vceIc wGj/dMV13cmf5WWY6uFbjSiDw+77mRFSu1edihAw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , syzbot+e7f4c64a4248a0340c37@syzkaller.appspotmail.com Subject: [PATCH 4.14 067/323] media: gscpa/stv06xx: fix memory leak Date: Thu, 20 May 2021 11:19:19 +0200 Message-Id: <20210520092122.401202873@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Verkuil [ Upstream commit 4f4e6644cd876c844cdb3bea2dd7051787d5ae25 ] For two of the supported sensors the stv06xx driver allocates memory which is stored in sd->sensor_priv. This memory is freed on a disconnect, but if the probe() fails, then it isn't freed and so this leaks memory. Add a new probe_error() op that drivers can use to free any allocated memory in case there was a probe failure. Thanks to Pavel Skripkin for discovering the cause of the memory leak. Reported-and-tested-by: syzbot+e7f4c64a4248a0340c37@syzkaller.appspotmail.com Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/gspca/gspca.c | 2 ++ drivers/media/usb/gspca/gspca.h | 1 + drivers/media/usb/gspca/stv06xx/stv06xx.c | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c index 66543518938b..a384d5d83026 100644 --- a/drivers/media/usb/gspca/gspca.c +++ b/drivers/media/usb/gspca/gspca.c @@ -2141,6 +2141,8 @@ out: #endif v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler); v4l2_device_unregister(&gspca_dev->v4l2_dev); + if (sd_desc->probe_error) + sd_desc->probe_error(gspca_dev); kfree(gspca_dev->usb_buf); kfree(gspca_dev); return ret; diff --git a/drivers/media/usb/gspca/gspca.h b/drivers/media/usb/gspca/gspca.h index 9e0cf711642b..2550af00d6fb 100644 --- a/drivers/media/usb/gspca/gspca.h +++ b/drivers/media/usb/gspca/gspca.h @@ -102,6 +102,7 @@ struct sd_desc { cam_cf_op config; /* called on probe */ cam_op init; /* called on probe and resume */ cam_op init_controls; /* called on probe */ + cam_v_op probe_error; /* called if probe failed, do cleanup here */ cam_op start; /* called on stream on after URBs creation */ cam_pkt_op pkt_scan; /* optional operations */ diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx.c b/drivers/media/usb/gspca/stv06xx/stv06xx.c index 9caa5ef9d9e0..b14f30a8f3bd 100644 --- a/drivers/media/usb/gspca/stv06xx/stv06xx.c +++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c @@ -534,12 +534,21 @@ static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, static int stv06xx_config(struct gspca_dev *gspca_dev, const struct usb_device_id *id); +static void stv06xx_probe_error(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *)gspca_dev; + + kfree(sd->sensor_priv); + sd->sensor_priv = NULL; +} + /* sub-driver description */ static const struct sd_desc sd_desc = { .name = MODULE_NAME, .config = stv06xx_config, .init = stv06xx_init, .init_controls = stv06xx_init_controls, + .probe_error = stv06xx_probe_error, .start = stv06xx_start, .stopN = stv06xx_stopN, .pkt_scan = stv06xx_pkt_scan, -- 2.30.2