Patch "spmi: mediatek: Fix UAF on device remove" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    spmi: mediatek: Fix UAF on device remove

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     spmi-mediatek-fix-uaf-on-device-remove.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f709738e0bb0cdcf18e03bebb4b2329b4071b50f
Author: Yu-Che Cheng <giver@xxxxxxxxxxxx>
Date:   Wed Dec 6 15:17:25 2023 -0800

    spmi: mediatek: Fix UAF on device remove
    
    [ 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 <fshao@xxxxxxxxxxxx>
    Signed-off-by: Yu-Che Cheng <giver@xxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20230717173934.1.If004a6e055a189c7f2d0724fa814422c26789839@changeid
    Tested-by: Fei Shao <fshao@xxxxxxxxxxxx>
    Reviewed-by: Fei Shao <fshao@xxxxxxxxxxxx>
    Reviewed-by: Chen-Yu Tsai <wenst@xxxxxxxxxxxx>
    Signed-off-by: Stephen Boyd <sboyd@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20231206231733.4031901-3-sboyd@xxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c
index 54c35f5535cb..1261f381cae6 100644
--- a/drivers/spmi/spmi-mtk-pmif.c
+++ b/drivers/spmi/spmi-mtk-pmif.c
@@ -475,7 +475,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;
@@ -484,7 +484,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;
@@ -510,6 +510,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;
@@ -521,6 +523,7 @@ static void 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);
 }




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux