From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EB2FC77B6C for ; Mon, 3 Apr 2023 14:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbjDCOO6 (ORCPT ); Mon, 3 Apr 2023 10:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232929AbjDCOO4 (ORCPT ); Mon, 3 Apr 2023 10:14:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C344C37 for ; Mon, 3 Apr 2023 07:14:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2717B61C9C for ; Mon, 3 Apr 2023 14:14:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A643C433EF; Mon, 3 Apr 2023 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680531294; bh=5RJSKIK5ew6Sg+i0x6krCE1POLGK0hC9xrp4doolEGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0NZxBzZEQVFcJ+Ob0LxsEje5o20gqbLkJvjQva/o66qHsRuzy7VYnu1ae3FDOCABC gRJNtdEOdrBQLbdYQDqzPoxHltAIdxomWgI3moNvDvX/JaHw/oLcRpg3FrTM8kKFq8 qPWtMvrPomi8tzu/kHHKdmmYMugJLkgVldd/Lvhw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zheng Wang , Sebastian Reichel , Sasha Levin Subject: [PATCH 4.19 01/84] power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition Date: Mon, 3 Apr 2023 16:08:02 +0200 Message-Id: <20230403140353.464636868@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230403140353.406927418@linuxfoundation.org> References: <20230403140353.406927418@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zheng Wang [ Upstream commit 06615d11cc78162dfd5116efb71f29eb29502d37 ] In da9150_charger_probe, &charger->otg_work is bound with da9150_charger_otg_work. da9150_charger_otg_ncb may be called to start the work. If we remove the module which will call da9150_charger_remove to make cleanup, there may be a unfinished work. The possible sequence is as follows: Fix it by canceling the work before cleanup in the da9150_charger_remove CPU0 CPUc1 |da9150_charger_otg_work da9150_charger_remove | power_supply_unregister | device_unregister | power_supply_dev_release| kfree(psy) | | | power_supply_changed(charger->usb); | //use Fixes: c1a281e34dae ("power: Add support for DA9150 Charger") Signed-off-by: Zheng Wang Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/da9150-charger.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/power/supply/da9150-charger.c b/drivers/power/supply/da9150-charger.c index 60099815296e7..b2d38eb32288a 100644 --- a/drivers/power/supply/da9150-charger.c +++ b/drivers/power/supply/da9150-charger.c @@ -666,6 +666,7 @@ static int da9150_charger_remove(struct platform_device *pdev) if (!IS_ERR_OR_NULL(charger->usb_phy)) usb_unregister_notifier(charger->usb_phy, &charger->otg_nb); + cancel_work_sync(&charger->otg_work); power_supply_unregister(charger->battery); power_supply_unregister(charger->usb); -- 2.39.2