Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp779714rdb; Sun, 28 Jan 2024 08:34:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEI2wEEpgQrgS5RHW9QDXK/U5IoIj9Y3TLVIggtHm/JpvlbHE8VsaiJRqFsVMD7U5jl6mWJ X-Received: by 2002:a2e:5c84:0:b0:2cd:3663:979d with SMTP id q126-20020a2e5c84000000b002cd3663979dmr2268566ljb.0.1706459692362; Sun, 28 Jan 2024 08:34:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706459692; cv=pass; d=google.com; s=arc-20160816; b=s03pVbU658HvR1MmlB1KTcO0T4nHJw2A1popmN9GFosbKpFQoih8II689XUrdX5lNO qq5qLPp3cLY9O/5WtJHI6qETJ2UQmhGQdc59QFVsOLy1FD8i7eFodrMmSdUkbvzDkUJ6 2cf9gHowOjyL+YeptPFuMKHEEwb8voYxKR4GVRtIxAQsO80Z3SLUiMj9lmcwgXomeCM9 b7YQGaVvea9J48SZXfIaQFue78RVk+jvxcEKJa+Ys0NVrsyuJ/zh6K/EXd/sOLH1hKyC YXtyiEArDUv6bW1Ww0HuWjLZfYRFLYHAuFQxMMT9jTe8LWxLGuQKlRLYLi3n48np/hf0 P7xA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sx90af6B8DuDpDTNrby1WTFnL3cUcGe/cR3sKgS9ulw=; fh=HjnIKDYix/x5Rcj/R2yA2t2OQjTSjySFRfbRU1HFWXk=; b=Nba3hGmPPNTfQIVbCVLtuK8fIMTtj1R/lnKo3HT0OMYHHfKHhqi/6/rJavzNM0jZLl cy9WKxY3TclaLz6s94g1tHKMaBwfwn3suh8Ehkxu0eak3gOd5ABph4Y5i4tGTGGz5LAe Fv7R4MBIPdkhwzXay71pw46IIoxFDN1oV3ZZ2IObzhBB+td04smses6x+oPKjJhhqRWj Ek9aRPh5N5ajJiKI2+B+qijSVStd6hURtPFHOmzVINRIFHzScz1BnkzgZPVMpIXORjK1 +ZknUOUXE1TPxbWyLph/ORTT+W8YNUqgLA+jupO0lTfwXxj6osUf+ICJE4kVoL5GV8rt HFFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=StZIe2FK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w5-20020a056402070500b0055ef5b57ce7si307219edx.555.2024.01.28.08.34.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 08:34:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=StZIe2FK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DD5931F23309 for ; Sun, 28 Jan 2024 16:34:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 526726DD0A; Sun, 28 Jan 2024 16:14:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="StZIe2FK" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A2E16DCEF; Sun, 28 Jan 2024 16:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706458483; cv=none; b=IZNIxfwbaP+RtsSf81qSHGBEqDL/3L6E8uTNJDdJ4Xnojy8YmMBaNMYgbn2urLHvYp0/SDehfZUOkTMm/84ZEG7v027HCAVHfpVNIISR8IFeg/G9edJoKtTEpbzlhGJD+BrLPlxS3HhrdpSKmmDnjZlu2/1Lqs5clrXq3zK2UXk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706458483; c=relaxed/simple; bh=hTRedzamfT7vm1GzvHYsLVvCpmoG43xST20/Q2nAqJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dNNStv2LYP6raRzGx4u0XRoISxlXtnpz3YOQnEAkGogqnfSmLM5+/B+uWeujEwl2GkK1E2EnjRUxsm6OQEBpg9uKp9yWZZ06B6jG2ttXGVlSiNAYvpe+xXpb2CklPGPh/uotV4UO5PRqgt/jH4Ss46xwI6kb1a1LrfrR3uTfeDM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=StZIe2FK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11DEFC433F1; Sun, 28 Jan 2024 16:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706458483; bh=hTRedzamfT7vm1GzvHYsLVvCpmoG43xST20/Q2nAqJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=StZIe2FKjBqXTL6gYgCPmim4w0duhKxwsKWlR6Q8AEfvBSn8cGGt13613gNJMnVWU OfvBxzmemZwlswlUvXtDRfDsHts3OYi38hsjCmw1sJo0cuGJs/ttCX2psp0INbLEaT +0aqSohTecP7YwgEgEUmoiJ7DRvoXW14xelYSyGmMp/chWDKm+4lQh3hRYSCAtvlRA 1EJ3YtSxmPS6Ca1oTQpXiQQTe+PhouXEY3OITxHFALTnQkIVt5DU2XUF5zALB2mqyr cffDVeWKDDW82xpYKiQvOr12j8N9Hz43RVrpqwOGDOAyG7qNu+aoFyHRk24O+iokTZ Qf7GNHhNP7LHg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yu-Che Cheng , Fei Shao , Chen-Yu Tsai , Stephen Boyd , Greg Kroah-Hartman , Sasha Levin , matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 6.1 10/27] spmi: mediatek: Fix UAF on device remove Date: Sun, 28 Jan 2024 11:13:55 -0500 Message-ID: <20240128161424.203600-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128161424.203600-1-sashal@kernel.org> References: <20240128161424.203600-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.75 Content-Transfer-Encoding: 8bit From: Yu-Che Cheng [ Upstream commit e821d50ab5b956ed0effa49faaf29912fd4106d9 ] The pmif driver data that contains the clocks is allocated along with spmi_controller. On device remove, spmi_controller will be freed first, and then devres , including the clocks, will be cleanup. This leads to UAF because putting the clocks will access the clocks in the pmif driver data, which is already freed along with spmi_controller. This can be reproduced by enabling DEBUG_TEST_DRIVER_REMOVE and building the kernel with KASAN. Fix the UAF issue by using unmanaged clk_bulk_get() and putting the clocks before freeing spmi_controller. Reported-by: Fei Shao Signed-off-by: Yu-Che Cheng Link: https://lore.kernel.org/r/20230717173934.1.If004a6e055a189c7f2d0724fa814422c26789839@changeid Tested-by: Fei Shao Reviewed-by: Fei Shao Reviewed-by: Chen-Yu Tsai Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20231206231733.4031901-3-sboyd@kernel.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/spmi/spmi-mtk-pmif.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c index ad511f2c3324..739ad0cbd3bb 100644 --- a/drivers/spmi/spmi-mtk-pmif.c +++ b/drivers/spmi/spmi-mtk-pmif.c @@ -465,7 +465,7 @@ static int mtk_spmi_probe(struct platform_device *pdev) for (i = 0; i < arb->nclks; i++) arb->clks[i].id = pmif_clock_names[i]; - err = devm_clk_bulk_get(&pdev->dev, arb->nclks, arb->clks); + err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks); if (err) { dev_err(&pdev->dev, "Failed to get clocks: %d\n", err); goto err_put_ctrl; @@ -474,7 +474,7 @@ static int mtk_spmi_probe(struct platform_device *pdev) err = clk_bulk_prepare_enable(arb->nclks, arb->clks); if (err) { dev_err(&pdev->dev, "Failed to enable clocks: %d\n", err); - goto err_put_ctrl; + goto err_put_clks; } ctrl->cmd = pmif_arb_cmd; @@ -498,6 +498,8 @@ static int mtk_spmi_probe(struct platform_device *pdev) err_domain_remove: clk_bulk_disable_unprepare(arb->nclks, arb->clks); +err_put_clks: + clk_bulk_put(arb->nclks, arb->clks); err_put_ctrl: spmi_controller_put(ctrl); return err; @@ -509,6 +511,7 @@ static int mtk_spmi_remove(struct platform_device *pdev) struct pmif *arb = spmi_controller_get_drvdata(ctrl); clk_bulk_disable_unprepare(arb->nclks, arb->clks); + clk_bulk_put(arb->nclks, arb->clks); spmi_controller_remove(ctrl); spmi_controller_put(ctrl); return 0; -- 2.43.0