Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2484828pxj; Mon, 10 May 2021 04:13:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsxk5MuBjtpMHl7eI8SWRnC8UaU8hIh07ZdrOyaYY9P6jA6lnp+Mi1lCKlXsa5g+z5jdul X-Received: by 2002:a05:6638:a2c:: with SMTP id 12mr20787943jao.99.1620645202184; Mon, 10 May 2021 04:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645202; cv=none; d=google.com; s=arc-20160816; b=t07OcF0fZdHrgfhZGWLotGcyg7X2ZQPD+ZcTjiJq8k2aAX9cvKk8nOqoYG/FdrYsmx Fao5iSeMUe2bCucXJgZ34vV8c9r53ju6Lg+6AGr+7mbWnFHtQdOHy1llYhhvlQsnzWEH BEA85buRvGHyC92LG8i2SszYr/7Y5bt5a7RcttUHNryO0fdyUe/pMBwEV4L7Oy9PY5fo ktgKFTLtbzkHVURhwQ4eLEGCw+zx3nwIyWvO1wV5e4OHk/gtdikDAOO/DuuNeRCKAWPg JUY0l2Hlvv/+PY+n+chIIM7CYdBWR29D/MJNgs6j+hR7tRqDADQ2o9nOpAt9AtMVHrq7 5sfA== 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=VI/9c1aHq1Q0RlFaxzIlly22xChcN5P6J+zouprAdRk=; b=JmM5pohscDia0uo2yvonlJeu/ap9GmrMoVcHnil4ZxUnq2cgAc5An//0NMIZz1vkm+ o2dAWuwuRIxVGrh2FI4rDIaetD8njiTaWhLb2IYXwzP7W1TKswaGqmdhOeebVqQ9rlF+ xqDDhDcv7T7U6Vp1K1VSTOTAy9rO83FFKKw2Pgw8D9EtfVHxnXuAAdC6fEuMg4JoxOha N9VW5T8Jji+pgRRs9RCSpUANV1Nt7/7wxeXmZ5JR0+VxuWj/31DVxiRXrQaiCSvHs7q8 Cv2dM+fDdABThLSV2CLVRL7c3w/vxNXmqYDrLtLNTuhRAgI2TW2Tv7YqOTq/N989+7aK S1jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jcoH33+i; 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 w3si13505368iow.99.2021.05.10.04.13.10; Mon, 10 May 2021 04:13:22 -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=jcoH33+i; 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 S231846AbhEJLLx (ORCPT + 99 others); Mon, 10 May 2021 07:11:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:41486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbhEJKtm (ORCPT ); Mon, 10 May 2021 06:49:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 916D9619D1; Mon, 10 May 2021 10:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643106; bh=kW+Kz7+iyT/blgzYJhQ6JJtZ8Tz4bngwHmfpwDRDbB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jcoH33+iLsdQllw+k6qXQIqLwoPV1Sc2S7lkkIJzlZ7d6WKFNQ7J75wc4grH9QbIJ WV2nROgdjYIc+kZXUeUJ1/OkVsfmMPq9SzmiilGKg7fXbJoW0wS0gLtrguQHlc6KHY Ow5N5RqDndHtVGlhQjIs75YsUlTOJNSAnkwfvQ9Y= 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 5.10 180/299] media: i2c: adv7842: fix possible use-after-free in adv7842_remove() Date: Mon, 10 May 2021 12:19:37 +0200 Message-Id: <20210510102010.908442541@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: Yang Yingliang [ Upstream commit 4a15275b6a18597079f18241c87511406575179a ] 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/adv7842.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c index 0855f648416d..f7d2b6cd3008 100644 --- a/drivers/media/i2c/adv7842.c +++ b/drivers/media/i2c/adv7842.c @@ -3586,7 +3586,7 @@ static int adv7842_remove(struct i2c_client *client) struct adv7842_state *state = to_state(sd); adv7842_irq_enable(sd, false); - cancel_delayed_work(&state->delayed_work_enable_hotplug); + cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); v4l2_device_unregister_subdev(sd); media_entity_cleanup(&sd->entity); adv7842_unregister_clients(sd); -- 2.30.2