Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2771570imj; Mon, 11 Feb 2019 08:13:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IbUKjt3D6jEP78xeOthJ5GWG5vR/YgQDuqnCHGWAWaqVgc1FKyaP0i0GQebE5PkUycsCMma X-Received: by 2002:a63:2882:: with SMTP id o124mr8393064pgo.446.1549901611934; Mon, 11 Feb 2019 08:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549901611; cv=none; d=google.com; s=arc-20160816; b=BHI4KoGth4SuGr3nFGz1/km41pltM0T4D8DKj2l724Y+vip4Y88LXozenlrhb+aDV8 VKcv8fvmFfiSuyNnQgH/0PbSin8NARMotC8hAnWlMGs4Exb4SaTR9jOKPbe5soj3KR+i OXNisPpbt3UksuaDDhN8OP4mqfdFtT4jXJMdSe2AYXQbCXz7e+IrmhcUypBJa0ZDgGlM GwV8GQwG3JZvZT+hUnmaLXrkzEmbYY02/Nclr3FhH1dz58bEc5izP2iM8awIj6fQ4UIn Iocu6CXX6J7DqxhxDxra63/jviB/1AO8/L/EtlpnINEBVzIC14+7iyEs9J3MNArtbUoC Gj/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Go25oaWoXRaOMmbuGWvgK9PLU5+vC19zO0le51YC9/w=; b=kSu7hHHvn0aKSUh8LPD7GjLuDMZiaErXUrF/8n/ygTFTL09x96zzyL5cnnEzscBvr4 Jkub1SriXbaGhKdLgZRgBvyBnWeB+83l1FGtS2hMfjFAKEOqZsW36UTZmJ33giRoyWoG PUWMXxuf8yqqvPyHnJPDe7MezEIEo+13EnzbrrgKi5nQ2qJo8u5yheFlnManaCFh51Oh 4WiqzWlC/blFhJnvnxzgiINWe+YkzGFYqO9s9o+CbC+bZod0ATqcjdS7ZcYgKybUgKVR Cp1d1W7bSlMjTQezEhswFtSjs/Ab5fVetoLjVl6s+vMnjjEkDaxh+pxmitRPUlym4Aes ZvCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OkIIfUcF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g33si10935641plb.426.2019.02.11.08.13.10; Mon, 11 Feb 2019 08:13:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OkIIfUcF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728980AbfBKOXX (ORCPT + 99 others); Mon, 11 Feb 2019 09:23:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:56330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728965AbfBKOXT (ORCPT ); Mon, 11 Feb 2019 09:23:19 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CA03620844; Mon, 11 Feb 2019 14:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549894999; bh=GmuY4okhsNaTNHG6EROVwf2zIQ+J1UKxH1Jgi7kqG1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OkIIfUcFjGlANkTzLR58Vrm14oq7qGIRBt0p99kBidZAufaiDggPB4CoyP8EEtFm/ 8x1+6yxQF0QnNdwgMcg+B3v5S0p+bsdVzzzt2iX43am3hPxFtEqZD/nYP8hRLO77h8 Bi58Mxf0VfGmJ2cJ1JBPwKjVO2+8APbSOCStQJ24= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matt Ranostay , Akinobu Mita , Sakari Ailus , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.20 058/352] media: video-i2c: avoid accessing released memory area when removing driver Date: Mon, 11 Feb 2019 15:14:45 +0100 Message-Id: <20190211141849.844230911@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c764da98a600a4b068d25c77164f092f159cecec ] The video device release() callback for video-i2c driver frees the whole struct video_i2c_data. If there is no user left for the video device when video_unregister_device() is called, the release callback is executed. However, in video_i2c_remove() some fields (v4l2_dev, lock, and queue_lock) in struct video_i2c_data are still accessed after video_unregister_device() is called. This fixes the use after free by moving the code from video_i2c_remove() to the release() callback. Fixes: 5cebaac60974 ("media: video-i2c: add video-i2c driver") Reviewed-by: Matt Ranostay Signed-off-by: Akinobu Mita Acked-by: Sakari Ailus Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/i2c/video-i2c.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c index 4d49af86c15e..ec0758dca2fc 100644 --- a/drivers/media/i2c/video-i2c.c +++ b/drivers/media/i2c/video-i2c.c @@ -510,7 +510,12 @@ static const struct v4l2_ioctl_ops video_i2c_ioctl_ops = { static void video_i2c_release(struct video_device *vdev) { - kfree(video_get_drvdata(vdev)); + struct video_i2c_data *data = video_get_drvdata(vdev); + + v4l2_device_unregister(&data->v4l2_dev); + mutex_destroy(&data->lock); + mutex_destroy(&data->queue_lock); + kfree(data); } static int video_i2c_probe(struct i2c_client *client, @@ -608,10 +613,6 @@ static int video_i2c_remove(struct i2c_client *client) struct video_i2c_data *data = i2c_get_clientdata(client); video_unregister_device(&data->vdev); - v4l2_device_unregister(&data->v4l2_dev); - - mutex_destroy(&data->lock); - mutex_destroy(&data->queue_lock); return 0; } -- 2.19.1