Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2109878lkv; Thu, 20 May 2021 03:38:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg5tkg2t6ImDRGuFWP+4yeGnexCgRG7FVzDnXxIvQTgif4hE98IzNgVVMdGYRalQYUHAJT X-Received: by 2002:a02:cdda:: with SMTP id m26mr641311jap.71.1621507119780; Thu, 20 May 2021 03:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621507119; cv=none; d=google.com; s=arc-20160816; b=QvJBa+KZTAi6FZvHsdagY+yUlRn4iW1nSlNAhqa+hTk3LSzaoHkCMdEFZhMTr/kGgM UPDMkNWhymR2w15keNrJKaoLwNe/tT619p/anU9wPierVtN5gr0NY9G+7CvDD6XsBEjr mWbddrwrMpR9pfrKaVsXAI1QAHXfKO7KSWhaAWRK2vd4w84e+JsOiUBWe9E8YGeI+pw6 bib9cy3icImMotvC+A/Dyk3oLPDTe2AzIcMPAnKWsGWNJFv30jsTLZz4MQdCyvaKGkSj bcT3041CLcXeyoC3eT1nAWgeD4RTfBrqSr/8P1873w7UXtcjCAdoTDfmlIHk63OFAZLp TSVg== 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=IngSMc5L+iCBAYzwV00gdS6LMVaLNrh8sTqS/r+vWaQ=; b=IZCFL9SufzVrMr3eE5pcr7Cy5+bQXOPezAYiTCYw9NDLCcMH5x789bP5bt1JMZbVm9 ScBvRchdele7pWof8lggz6zsaTwk8i+en6KdL70nOyFplBpAHdYfizoEdqLHvCzxIV9C 1vnFLKRkeblmq6cxgsiqAyFrGQecu9+7zYCKMemEtdzfCa2NF9G87w6f87xUCzpP1ai/ KaOPpaA4dmAGAkR0B92rEv3TVuH81Ikqj4UophyM0q7Y//o3Dy648UsWbAkKF3zOv2xJ wsN+PfHUKyFkcjQniXFw7E7Mrh721t2SO1+xqaPWYoo6uGcP1uXmxZSJpuMkUsaFke/a yYZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C1STuiCH; 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 f184si1863022jac.102.2021.05.20.03.38.27; Thu, 20 May 2021 03:38:39 -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=C1STuiCH; 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 S237854AbhETKft (ORCPT + 99 others); Thu, 20 May 2021 06:35:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:51944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236295AbhETKWh (ORCPT ); Thu, 20 May 2021 06:22:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F357A61279; Thu, 20 May 2021 09:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504107; bh=9NXcl2QLLPSP09uPy+3hBBSYPkx27uTwu3P5s/p5jig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1STuiCHTD7LDCumdPslcWuenZ72zZ+RX/DJfYMnOdRPS+UZqukkMLpUVxVATh5tM mY06tAgjnjflRfto4Fk/TIQkhBqE7sgpj/YkNURUgRP/WgTf0xyYkUTTx/264cjA/N BYOiWp3d0pJqOLArQewAolxKVFY9w4RdiSTqFNdg= 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 4.14 061/323] power: supply: generic-adc-battery: fix possible use-after-free in gab_remove() Date: Thu, 20 May 2021 11:19:13 +0200 Message-Id: <20210520092122.207130216@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 371b5ec70087..c5bde3c24c31 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -384,7 +384,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