Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2488003pxj; Mon, 10 May 2021 04:18:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMwlmXdbu7tCig0Q/lVX6Oxq0fswmnsXUqb5mBteD7sxLWAfEWkOMmSH6/EiNSXISAyzrt X-Received: by 2002:a05:6e02:1aaa:: with SMTP id l10mr21059112ilv.29.1620645498937; Mon, 10 May 2021 04:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645498; cv=none; d=google.com; s=arc-20160816; b=PJ2v8oJQxGil7Z+gOxn8dpbo+kWCWRIkphUtbDMRrn592SME/MjDe2BEqUkhTY4C3D uSkPM6UyivNf8pSwBJ97HzlKGZ0xS1gFthiemyAub/gNy24mgz6/UN6Y1XPWL6+OACxm BoeQgIpoekxAHvfNkID7Y4TBxfzxBWUli6gDcrMt3dPI1tfpj7Ftnnlf0d/jsshO7ua/ IX+9z1aPOS51HLZ3t6Tupjl6wwTvywNkg94j9T6n1W1vbUHG37mcrT9mKQ6uF5ury4ZG KwCQzW9HYhwLprpjGzDFWiTsCeUSU1hOjmgLKN3wMa7+cOHIs/KAqp7GqyxJUXY1Alkp s/EA== 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=61BEFHa9fpK8VnJrazQQel/YF5BAR0WOip43nAEA8JA=; b=zn8Dq3Vozm6nMwIvgNN9o6GsNGLz1kJjyHO7sLeTOQVD5cuS17gXp8lX30DsVBrn2C aX1SBNfLPDgjzelqRamKBggrnfKQZSuVDRWEj/cnONY3d0Q3J8dMcmPhqNVNJCewrX4/ h/WrA+NzS3I+IC8ZsHvdlati97t92MxlRs52PVo+fW+YQG1iVLctnCl36YkrDdFzQQ+f M2qzxCD3xPUC+8gLN6EtffOOxbK1lSnXVoF0AvL6IDevgs+F+PxrutgMv1/fiDywswo/ EdJZoR3gqCjRkTTsDHjZ48hZQ5SDP1fxq3XQ3aotGQbb8SzyoeeE78zzaEr+9EwUAop+ vspQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lN1GwQzs; 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 r189si9467442jar.1.2021.05.10.04.18.06; Mon, 10 May 2021 04:18:18 -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=lN1GwQzs; 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 S233208AbhEJLL4 (ORCPT + 99 others); Mon, 10 May 2021 07:11:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:33618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233171AbhEJKtl (ORCPT ); Mon, 10 May 2021 06:49:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 29201619C3; Mon, 10 May 2021 10:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643103; bh=jSFnpPCMOcIv5/ncZmQy4KGPp60iGDNp1gQ4t8bTZgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lN1GwQzsYxmO+vgnpIICyxb60gzFtYp3PEx1YiHdOqT2V2uo9nIp2lnZyDWftmmou GnZ3g1KV1VZ/IPGKca0qjkqFuAW5qEmt1zR5KRHFCKpbcxY4PUcse1L0x4M4cguAPF 0kVlh7xYhKsv70UAeIImYVClMIe8jRp4K6Y0Z5dY= 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 179/299] media: i2c: tda1997: Fix possible use-after-free in tda1997x_remove() Date: Mon, 10 May 2021 12:19:36 +0200 Message-Id: <20210510102010.877921535@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 7f820ab5d4eebfe2d970d32a76ae496a6c286f0f ] 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/tda1997x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c index a09bf0a39d05..89bb7e6dc7a4 100644 --- a/drivers/media/i2c/tda1997x.c +++ b/drivers/media/i2c/tda1997x.c @@ -2804,7 +2804,7 @@ static int tda1997x_remove(struct i2c_client *client) media_entity_cleanup(&sd->entity); v4l2_ctrl_handler_free(&state->hdl); regulator_bulk_disable(TDA1997X_NUM_SUPPLIES, state->supplies); - cancel_delayed_work(&state->delayed_work_enable_hpd); + cancel_delayed_work_sync(&state->delayed_work_enable_hpd); mutex_destroy(&state->page_lock); mutex_destroy(&state->lock); -- 2.30.2