Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2483519pxj; Mon, 10 May 2021 04:11:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe8GBJfht7TfrbAwoNa4hAgJOwt78cqQD3R+n32Gtu0Qf4LBjE2xyq0uLX+jt8kJbD8FpU X-Received: by 2002:a92:cecc:: with SMTP id z12mr22170259ilq.89.1620645090321; Mon, 10 May 2021 04:11:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645090; cv=none; d=google.com; s=arc-20160816; b=O42moX1ppMQgjiCBztJ1UItZHeWj8Twen1gaNetzEnfImraOG6XPgqF12qPRusHzmc IyMbu4SQ7fQyLuOCYW110Es0h7juyOqsQUfIZPyan4T1968dPBmyE81zNY8V2Py6XzeS imXvozohrpa8xql1HS7iduo/T0NHwS5c3xOPw+5LTiyl0lICCs21SFTJMcQNtbjGwn6Y Si56/leX+tts54AGo3Fzdp9wie7L7yz9CmY/xZ2Yl6Yt41Hp6J+PJ4kgZdBlYk+cNOdm lyzprxw8hNsQ6V5NYmaExZikCc2oqPc4Vh7x5GfD6fc+pLy0LxYgnxcBx9qogjmxti5V fYSg== 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=niXrQvWsvJSl8VPUTjc+xWbq4XcHE70WKqZfk5PVpyc=; b=VzAsyxyKgGQRLHAy1yHvHKz0wcLdwyapEaXJk4mGL5Vycm+IiVsIBFWr6VzQmkOhrA m9ObuNRrrQUt4P/ZguNzRXLw3sXsvP9KtMYFVYCafJOwGnlBd5Mc1mjDjq0haWsL4On2 YxROlAKjpwr6f+gC4G8TFRBJd6NYjxLm0I9hhH7la/OvdIV4q+R6B5fIcnVZKroOvZxA kdW4vR2v+FniuxSHj311tDhfK8wDCRVmlWd06cv7rn4f7WoSEVw1rlWJiJ67EFpqD7ai wEPwvJ9oUkOsYI3cjbt7eCgxGm9XU8+4aLWhRhH7FKowkTKmg5T05HzQbFbJs8H97/iM 905g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aDPjuUlo; 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 b5si9304248ioh.5.2021.05.10.04.11.17; Mon, 10 May 2021 04:11:30 -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=aDPjuUlo; 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 S233409AbhEJLI5 (ORCPT + 99 others); Mon, 10 May 2021 07:08:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:32906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233143AbhEJKtk (ORCPT ); Mon, 10 May 2021 06:49:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5A8E4619C8; Mon, 10 May 2021 10:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643098; bh=EbJmfGcfFUZegJrpcKXCsCBQlYDEv1znjBfrxCgRBF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDPjuUloq1WKSrfWhdycsYvMOtVZRtzvvgWAMGkuIt6OQOR2ZMuxAx68LXYKEe5I4 FtfVpR3EwSsvuKOI0bc/DmbnlFZpwKY0si2vsVVb/AnjkWJSIcjEpQm5GWzzCiw6GW qKdU/+5CSNKT2fmeSWqfgOlEODyKDMdZzdD3zSAQ= 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 177/299] media: adv7604: fix possible use-after-free in adv76xx_remove() Date: Mon, 10 May 2021 12:19:34 +0200 Message-Id: <20210510102010.801567749@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 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 09004d928d11..d1f58795794f 100644 --- a/drivers/media/i2c/adv7604.c +++ b/drivers/media/i2c/adv7604.c @@ -3616,7 +3616,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