Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp303238pxj; Thu, 20 May 2021 09:40:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdfAPw0viE2AkEe0PZFRgXPGoF6ItUbnv6c4BQ6aHN18HctE4fo05ZNGrPPn/z3dxZgNif X-Received: by 2002:a17:907:1002:: with SMTP id ox2mr5444244ejb.337.1621528815342; Thu, 20 May 2021 09:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621528815; cv=none; d=google.com; s=arc-20160816; b=XzQ65n3pdJl//BGgNDqYET2JYrg+v7eW54Q3n5QXo11gmHDjKjPIL4iiil/hIJAZvE Kny9PAH9zMPOyKRhSIdIINwk6+7tGxm/M41PoRopHrOcGQ8aFLJYzBbFD5MKh5FrNaWi ON7NoKM6unMiiVylaTz5x0L7Sf0M8/i3bKpeE4SnMJ4xpeOptoEjy8Ord2h/+WLl4G2E a5KtGQrs9jTEXEQjQQcmJaDNm30rr5ANmCPp5+GIW1JCCP08+0D2Gl6LM9jWE7Hr/JMF jHj7awYEovxdmaA0mUDkF9McYQxrsu3Wf7Z6WIvk5aRwv2216r0RceIbpWah9M4/MWme CCgA== 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=bdmb+KhSaAiEOP/YnnNKc2r5VdVauIo9psxXSH8M+C0=; b=CXDXZ2gqeqh8HekHUs8ZgxTuYoDIw+YbVeuZd5wfcFx62Tt8cpuHkDx5M7O/AVuKhP bYAdfSBAujhGqXQc8NWOb358DNN/F2MSYQfIcdkxZcwMKRHK8cVicQ/ZwNgFImYR2v+c hpcoAHtkZ1Aovd9DWSnSEk16s40c5zpvYLBT39UJISuTx48fZZvovBJzQqywe9Dbn0z2 eekHkFoR0+6aRJ+F6NI5MdRle5fa3iyv2IC7twLo5P7uL/4t7RbO6VvdrJM9BRfzfRSH fEnnL6nT5M4RU2qNZULoB8QaZ/o+nLKaHn/sGX5VK6w8d8k7YKS+nT27q0OrbJVrB1Ed 9yBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TsiYhktg; 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 z62si3097628ede.508.2021.05.20.09.39.51; Thu, 20 May 2021 09:40:15 -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=TsiYhktg; 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 S233118AbhETJm2 (ORCPT + 99 others); Thu, 20 May 2021 05:42:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:41074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232685AbhETJjr (ORCPT ); Thu, 20 May 2021 05:39:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86E936142F; Thu, 20 May 2021 09:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503089; bh=FioYxK1JVl1Z9iYz7eBh+7t5FbD8I6Vku1QOl4rzR48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TsiYhktguPNa26XAv5tyOg5t5iU7NJczZiOttbJTCtHZ5tDraFjGhR2cOJMyXKjfI F0E4D915gWEBmAx8varWTGG2kROhl6btHHXmvijYPuLXMOafXKvPWy1kjlvK3tfSpi KUPhyXAP6opsvaPJnUmkrnGS4vKhgUNTxGBHb3T8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Yang Yingliang , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.19 062/425] media: adv7604: fix possible use-after-free in adv76xx_remove() Date: Thu, 20 May 2021 11:17:11 +0200 Message-Id: <20210520092133.476798135@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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: Yang Yingliang [ Upstream commit fa56f5f1fe31c2050675fa63b84963ebd504a5b3 ] This driver's remove path calls cancel_delayed_work(). However, that function does not wait until the work function finishes. This means that the callback function may still be running after the driver's remove function has finished, which would result in a use-after-free. Fix by calling cancel_delayed_work_sync(), which ensures that the work is properly cancelled, no longer running, and unable to re-schedule itself. Reported-by: Hulk Robot Signed-off-by: Yang Yingliang Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/i2c/adv7604.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c index a4b0a89c7e7e..04577d409e63 100644 --- a/drivers/media/i2c/adv7604.c +++ b/drivers/media/i2c/adv7604.c @@ -3560,7 +3560,7 @@ static int adv76xx_remove(struct i2c_client *client) io_write(sd, 0x6e, 0); io_write(sd, 0x73, 0); - cancel_delayed_work(&state->delayed_work_enable_hotplug); + cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); v4l2_async_unregister_subdev(sd); media_entity_cleanup(&sd->entity); adv76xx_unregister_clients(to_state(sd)); -- 2.30.2