Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2484194pxj; Mon, 10 May 2021 04:12:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXgsITkWsavdGnUxXobvJzKYicktvIA+u3pSulKSqZhgIKtg1kgTFmfAfo9TqAnmJeL1wT X-Received: by 2002:a05:6e02:14c:: with SMTP id j12mr14900896ilr.202.1620645148197; Mon, 10 May 2021 04:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645148; cv=none; d=google.com; s=arc-20160816; b=dtbZmjMYdzrOdTGh/+4lJsukBU1VDgK9VMewDFte6x4zs7KTwOOKBPmKdk8jg2MKH/ y/G1qoV2fyDk9YSQ34F1gCrwfHa7b4VRYSyzewI3G9Fkx6WPzg4E8j5e8OGpZYQxiXSZ bHrlXyFhnnVXDl2zpQpJq51YKzQTvYluVBinmsQ+SjAep5q9usD1/fWZYVwZqKHzNhC+ FCohIuLGJGwPJCtXj8WNFXejCBdJl8pUOXr/cu8q2aHURy5swcGBx+T7yeTgsSKOXbHD SSQO0Qk67kY5zHD+qElFSPvYJQ95Y5B0j1endd3RQbU2Ry+yO1ZmVGbFTyzfaFDdlLK9 zDqw== 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=h+3JMeOkFOPmKEHbvPS0xq6ZKFLSXxkXySsD172HNPc=; b=gJQJJ9SHx4vXpXiNorlork0BEhin9Y4M3FeiVGgI36aJh25orHFLnHW2SMT0bNF+N6 SAd6zFKdS97SOT6jdC6AX2e6dEiKh/GRV5FfIFbHABy1+PrQA7cwT2vJ5W8Qtv1F1Vq5 JJSVf5evdk7oqUnbVMeJeiphwLC9ozlQsIgwlFfEoVGBOpcQL98rlh/3tCE24k/xEUUQ W+MEnGThpCmtMILB8kOLQML7AV2VVJP0tuwNShYblUG5FxrGI49wRuqzgEO3IXP1FPDx tvbiJR4di8DXXeZZCUNXdnFBylc1roA7+1hO58GBz7hlK3LkvfD4GVRpW0nz6dSeSFMw eGgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eRVa2aVb; 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 d7si18930364jak.52.2021.05.10.04.12.14; Mon, 10 May 2021 04:12:28 -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=eRVa2aVb; 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 S236733AbhEJLIk (ORCPT + 99 others); Mon, 10 May 2021 07:08:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:59362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232776AbhEJKtM (ORCPT ); Mon, 10 May 2021 06:49:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B98B6613D3; Mon, 10 May 2021 10:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643089; bh=v7Y0wNr23gfihcKJRdFlfl9Db4iABnZHp/ley6aKNiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRVa2aVbW25MMjX5r6I3qOiSJ/ZLphzBS4/fUbwRtim73Tw8/C7GxhSroICxOXzSp MfjzIFOjh3K+FUUJrojLEvbO3jtrLv6ImMDWFObQEaBmDVo4RfnuYlW5K7lkjSlPFR Fj0HubBPHwBg/AuYPwYY/uPpaQIlhXQnxhhDw7vU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Yang Yingliang , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.10 174/299] power: supply: generic-adc-battery: fix possible use-after-free in gab_remove() Date: Mon, 10 May 2021 12:19:31 +0200 Message-Id: <20210510102010.710547540@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 b6cfa007b3b229771d9588970adb4ab3e0487f49 ] 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: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/generic-adc-battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index caa829738ef7..58f09314741a 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -382,7 +382,7 @@ static int gab_remove(struct platform_device *pdev) } kfree(adc_bat->psy_desc.properties); - cancel_delayed_work(&adc_bat->bat_work); + cancel_delayed_work_sync(&adc_bat->bat_work); return 0; } -- 2.30.2