Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2484685pxj; Mon, 10 May 2021 04:13:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDIfIm+gKaswMDMuegBxL3UvY0lptxmosDlMFbUpFJTWESn5l2DYVmA73Yf6YS877RPg+P X-Received: by 2002:a05:6e02:1a8c:: with SMTP id k12mr21156619ilv.161.1620645191322; Mon, 10 May 2021 04:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645191; cv=none; d=google.com; s=arc-20160816; b=FLA2+o+AJHrxoZWRrCOxN9YkqVDFS2U/T+Py5vGC5nyPg0iUbvUMlkcjQ/19sMKEx0 TxfiP+M5pqiJAiEjQ8bJtR8xO4WS3+5Jc+PKkyf6BqYWJqpS9tT4bAigc/EYXdVIygDa gedFoOcarhDR796Q2Dfieq9iVPcrwBVlqe/a7g384gs72I/nFD+DWa2lyo6aSjgPa5Zx p6XC40w6yCpbgynvegq/34NulJrmz1Or6OEhVX8dD9IPNGrinSCP7vT+pmRaSWjbTLNF Rsnnea1PWltb8/G+b74Vngr/u3GR0AaxwbFOGpOTX1VpbysWrrTu5Pmi19icURfbIEbz 5vag== 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=2QHLrLAcp2teI+fCkCXDb8chEI/ksp+S59P5a6vlKTo=; b=UQZkcmPTtbKKAaajL4+35N5xZwTcCzAZDM2IVDy2KNIRemMaCVs7T3MYS+RGcOX1Vb RtlENb6WLDdx4u0Mcvwz11cmRmOM+5SWCpvHjH0QyviS3ZPdogveQKva+AjzSedDakyo aci12ZzkJV4P9rnOG87S6yC0hEwzaM72JAEe/43AO1vRN7e7Wmr/DKAvk2hj2r2WrgAM kuwdFeEECgME1xFfLgF2xfk2+5j4O5M+ZNc5FU0cHxu3R8ZVzMTFXrfGQnSXmPuMXtnQ TYrW6XbSXu0CdQd+v58TaJpvsXHDRv3vBgH4dnE9H1/I9ZFKyEflm2l95SGN26/oyPR5 4nZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t65cpgyJ; 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 r17si17213976iov.15.2021.05.10.04.12.58; Mon, 10 May 2021 04:13:11 -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=t65cpgyJ; 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 S237271AbhEJLLr (ORCPT + 99 others); Mon, 10 May 2021 07:11:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:41711 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233215AbhEJKtw (ORCPT ); Mon, 10 May 2021 06:49:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 368B561492; Mon, 10 May 2021 10:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643115; bh=r8UFkN2AuDgHpPR55vbdoKDopD8eGlpX6lyOUa+cLq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t65cpgyJKSd587AHOunoLoYz664+uni5m3JoTpo0trdIE4WNRXblQPQlNJqkpsbPX DentJsTwcxjT5ceMD8apCaVNZxA3+DD7iRm4OJK31MQvGBO6FWkQJYBVq0jh+5I2u7 ODG2jTbxJusxFE7a9b4CuJ4np9cJf/akKlvGOzGM= 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 5.10 184/299] media: gscpa/stv06xx: fix memory leak Date: Mon, 10 May 2021 12:19:41 +0200 Message-Id: <20210510102011.040433480@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 158c8e28ed2c..47d8f28bfdfc 100644 --- a/drivers/media/usb/gspca/gspca.c +++ b/drivers/media/usb/gspca/gspca.c @@ -1576,6 +1576,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 b0ced2e14006..a6554d5e9e1a 100644 --- a/drivers/media/usb/gspca/gspca.h +++ b/drivers/media/usb/gspca/gspca.h @@ -105,6 +105,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 95673fc0a99c..d9bc2aacc885 100644 --- a/drivers/media/usb/gspca/stv06xx/stv06xx.c +++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c @@ -529,12 +529,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