Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2108741lkv; Thu, 20 May 2021 03:36:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAUKvT0KJ7qhszRj6/+S3m6eFhjQngQ0O9tZRgCD19NMf9bbTUBRPTjKSvF49DbrqyrcvZ X-Received: by 2002:a92:dcd1:: with SMTP id b17mr3838193ilr.145.1621507018348; Thu, 20 May 2021 03:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621507018; cv=none; d=google.com; s=arc-20160816; b=efXRk9mMI21AMFRsXfdAQgCj6dDqZhZYJjLK6ad0n1B6S5T0blUPvja7dQotijww4C Ifw8fHe4Er6WKimQFoUmKqSQ8TjUfe6rq4p4HA1F/N3oypLQnIm8+AdQ6Ke8Ufeca+Ha g0wsFcNOvRGjCBwJ266KTMcnTa6dV47ADIpXGgZPKopjuFaMyiHgWyRYx4+eSiw3rscj D98w0FCAKA7hlWIWghR/mOthtNzYaKzlvnDHl+cDT7H0ON/ncIRSHQJEgmla1IKqirxu TkZnZjsPX3xiDUuc36uZETt3y7VBlfOt2SyDC2ner9H+dZsmzP0GwqPUtkm9zDelgVm3 bdIg== 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=OEFpT+ky/wiIYPdsqDAE2uFdBiNfLGAlQaTuKQmkx/g=; b=JEIPWmz2vLDJFz7kIKWIb/ag1qHJkW+BUrMBhfdRdmheBUCUDChOXfeEcQE7HvZP0Y jz0f2ltYLubymCVc8x9CAhmp2UqUX0SJ18bm8ckiddkKPbK+vnSMznpZeHwbok0kHU/5 ud1V0k6TCLgXh3qZXpKTm6WWiDzL69gAlZa6eo3D/oCj7T/eoGrVnBPRB/4amwq/Y6zQ pDb2W/u79OaKgJvWsSE/6+hrOqy6uzdE7JpKT7yD4Lyh3PQ+K5WtyZ4lvIOWVQ5U+jtO /UvRgn2ENY0CbLQnfEd5HTiX5opQuqB+ARn6dC8YUnNCBY/pCpLu+EvbXMdZDqjqKtVs P3Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HRvOqi9M; 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 y3si1830154jat.97.2021.05.20.03.36.45; Thu, 20 May 2021 03:36:58 -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=HRvOqi9M; 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 S237889AbhETKf6 (ORCPT + 99 others); Thu, 20 May 2021 06:35:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:51826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236290AbhETKWg (ORCPT ); Thu, 20 May 2021 06:22:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35E94619FE; Thu, 20 May 2021 09:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504109; bh=hereJ0RyJy+lofiGg9BMhXrGaktzxvAE3AhkPHBnmZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRvOqi9MDgiLCVlW23yFw2z3rTCwzSr+QJHGRm9F+pp2WzbolRb3oFO6CSMGdOoiy WaWUFc20tNREe9QhuAImbiYdzWPQ5FsQteo6Ww6cQcM+lvqbbr2s1ckjabUqLclmxD SefbvpQWvE4lOMz1bKDaz7PcSrEPKWD4+9bC2o/Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Yang Yingliang , Krzysztof Kozlowski , Sebastian Reichel , Sasha Levin Subject: [PATCH 4.14 062/323] power: supply: s3c_adc_battery: fix possible use-after-free in s3c_adc_bat_remove() Date: Thu, 20 May 2021 11:19:14 +0200 Message-Id: <20210520092122.238707521@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 68ae256945d2abe9036a7b68af4cc65aff79d5b7 ] 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 Reviewed-by: Krzysztof Kozlowski Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/s3c_adc_battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/s3c_adc_battery.c b/drivers/power/supply/s3c_adc_battery.c index 0ffe5cd3abf6..06b412c43aa7 100644 --- a/drivers/power/supply/s3c_adc_battery.c +++ b/drivers/power/supply/s3c_adc_battery.c @@ -392,7 +392,7 @@ static int s3c_adc_bat_remove(struct platform_device *pdev) gpio_free(pdata->gpio_charge_finished); } - cancel_delayed_work(&bat_work); + cancel_delayed_work_sync(&bat_work); if (pdata->exit) pdata->exit(); -- 2.30.2