Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp302923pxj; Thu, 20 May 2021 09:39:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRiILW9IG0CvG+pQlv6BVSDGRfSa9IbzXu5bjE2cFmHnMeKEyJnL4BPgBKgaLI6bbpzYSH X-Received: by 2002:a05:6402:5169:: with SMTP id d9mr5959264ede.347.1621528790316; Thu, 20 May 2021 09:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621528790; cv=none; d=google.com; s=arc-20160816; b=M7IhbYtzIo/Xv89nLqhabHZ3dial2qhM74k92iv3Xgo9KUYewnGO5frPShRNbyToHB em9FV2zeOSN1EipREeBv3eFF6LFNQo4vsKwbJP5Uue/3FgfVD0fiCc9WmMwYZmFFCuVY z7ddQMs2FspXXye4JxqZuP4mhURvnaSn+P6uAF+1uRG+5w/D7jolkxQgQ5IwQfNlpOdf jHtsCuZl0GtDGuefJNmvxyQ/Xq2BMMSuRP9NSXAP5cU1OflG01J2Pt/U7bSZxnaIXO9w HLX8hE0EUgparq1nO9lez+FIRF1C9WBEAQNkGa/D7ssp9G1VIPJ6lywpH6ne7pldoxS0 aCmw== 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=kHs0hLYrXEMq4IODL5D6gj91/aL59VwACUHDbsXZjnY=; b=zmx/vL85IKEQHlXWlW0heeOmA9+wtnwKPgzK0dfpq2/OZlbSSzZW5ElhOBNQQtosV6 uFofzcV5ZYf/Q6BF2B0a6C9WKo+ODxLF+xKAEHx4HZhS/Xiq5LOPxnL5mnG4lYamA9i6 n/BBMm8gKbADCRBqTqm/c8DlWofVOriPbSqhgNqJOWxXYSCEIgsBwAg2Kwu7i0HxbKZo cbFP07zI9HwZiYlhyz1JXGfCJRtxiCNYmWrtowZ/prPzeKr+ujTxriTf/dnG/97QcA3v U8vPZFxXlA+AQB10QDeBj8U9x2Qn8Ljco/9sFKB9E/VYaOC0crj5rNT1qa0/NdhwDGGa BTgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fl8+RJfI; 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 p3si311629edu.599.2021.05.20.09.39.26; Thu, 20 May 2021 09:39:50 -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=fl8+RJfI; 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 S232208AbhETJmh (ORCPT + 99 others); Thu, 20 May 2021 05:42:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:41238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232919AbhETJkQ (ORCPT ); Thu, 20 May 2021 05:40:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EFDA360FDB; Thu, 20 May 2021 09:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503093; bh=evni02BbwAdeZIzay0TcfA75MDlrzK9isldoS+5pYSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fl8+RJfIE8JpNfoaGQ/X893X8dZ7gCF+ZUjk1CJiAdPohcMLOU5rocdqTu5/PWLRO s0o1PIvyYY4NmI5QYZgJIihKRakCETSNFcliseB5kUUTvTuXnoG8GF6TsAbcKZecVP w2yfTRkF2xaw5tAqOUaUqhHrhz/fIpeOAUfC5G68= 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 064/425] media: i2c: adv7842: fix possible use-after-free in adv7842_remove() Date: Thu, 20 May 2021 11:17:13 +0200 Message-Id: <20210520092133.551140389@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 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 58662ba92d4f..d0ed20652ddb 100644 --- a/drivers/media/i2c/adv7842.c +++ b/drivers/media/i2c/adv7842.c @@ -3585,7 +3585,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