Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp61295pxj; Thu, 20 May 2021 04:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKKO2WhLG/stRSVqaDHoxRG7uFB+lwDZaMEQ1oSnkwx9XrprkJG5wCt9si4jDwzHHn+Aiy X-Received: by 2002:a17:906:158c:: with SMTP id k12mr4268684ejd.274.1621510561464; Thu, 20 May 2021 04:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621510561; cv=none; d=google.com; s=arc-20160816; b=fer6tnfLG/upvUw3I/seaAp/SdZO0XelfjafrIn92DBnyEi+ynoju2fX3uD1zInpc5 CKw7p0DjMidiUHAhmhrXQbB4PsCnytfI78OEN1+h9wFe2B80UrpvG1ywpel+tHIg4Y1U MT0iGre9IUnzU0j5NfOVB/wF4LnBiJtOIYBiyCO+j7cfsKUdzyas97JNabY1Pb3GGF9a Yr7rXzqTUzK+Vc+26cqUGM7+6uRwSAeqhdxXPRSCT9bL14yeZbNZ2la3TJQ48bz1U+1S 6IPlDeYkXbZ62wO5Br66K7WavyjCDgoct5ag5yaZwof1x1yc+D+YQoVsRocs5qYfwL60 z5Rw== 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=cikxawNxZq7GJxVPgm2yJG00mRZC+4VI4JiQxk+fg8M=; b=WrQs/E1RldJLV6h0MTyxQ9Jvz/l9LArUtQB2+XxOMIoXd6pGOuo7Awuo0jYOXd3/cu JQspea+tBn5qjnXTsr1TpGKzDsiy4EaCy151d3sPzBDUwT6jaDUBF/XNUvH83v8laQNK SbBmIKgZqVDLj8E6f9hhT2O7PJWK2dxsLBXo42aJVdpVwYW5ZtknBTC/RzgbltU9pHhQ NxOdrjh5/f/ieMUXuwBd6J8MoDtKPeo0dj7t67YZCiYoDDWwJrA6uyYjCjF0dIfOZL5Z g1W7btTpgqwFfMhg3Q4C/dzIZlfmngFn4PEqCP9Nkjmml5X2VfNCQCBmv21Ti2ji3i45 4rEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aWtO8AYe; 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 g11si1911828edw.414.2021.05.20.04.35.37; Thu, 20 May 2021 04:36:01 -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=aWtO8AYe; 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 S242214AbhETLfL (ORCPT + 99 others); Thu, 20 May 2021 07:35:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:58198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240449AbhETLOe (ORCPT ); Thu, 20 May 2021 07:14:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4513661944; Thu, 20 May 2021 10:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505315; bh=LDFQF0yxdLGA0Vnxu5lpdZzklKbAlmh2jqNWSeSsDy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aWtO8AYebMGciwIzPxkuaIkErPGmIcOgbq/t8BVCf5BW8DUhED5MUTq8/tHnRN9oo 5uYrnXtB6wFuKPZMh/jApaCfMy/gZJb+aOWiLu2azoyU1jdkAI3I3iX5so44jGx2YZ sCKu4SzlGESlphoyKvvkDRAaIwk03mLTWHPMStdM= 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.4 034/190] media: gscpa/stv06xx: fix memory leak Date: Thu, 20 May 2021 11:21:38 +0200 Message-Id: <20210520092103.299584226@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 17b7b02330c9..a4f64bdb8017 100644 --- a/drivers/media/usb/gspca/gspca.c +++ b/drivers/media/usb/gspca/gspca.c @@ -2131,6 +2131,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 d39adf90303b..bec8fccc2c94 100644 --- a/drivers/media/usb/gspca/gspca.h +++ b/drivers/media/usb/gspca/gspca.h @@ -101,6 +101,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 7d255529ed4c..40d4c99debb8 100644 --- a/drivers/media/usb/gspca/stv06xx/stv06xx.c +++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c @@ -541,12 +541,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