memory: tegra: Shut down Tegra210 EMC timers before teardown
Subsystems (2)
PATCH v2 1/1 memory: tegra: Shut down Tegra210 EMC timers before teardown
The training and refresh timers can outlive the EMC state on removal or probe failure after clock attachment, causing use-after-free.
Shut down both timers before detaching the clock provider and releasing the timing tables to wait for callbacks and prevent rearming. Initialize them before clock attachment, since set_rate() can start training.
This issue was identified during our ongoing research while reviewing kernel code.
---
Changes in v2:
- Replace the static-analysis attribution with an ongoing-research note, following Krzysztof Kozlowski's feedback. No code changes.
v1: https://lore.kernel.org/r/[email protected]
Compile-tested with GCC, W=1 (arm). No runtime testing.
drivers/memory/tegra/tegra210-emc-core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/memory/tegra/tegra210-emc-core.c +10 -6
@@ -1946,12 +1946,6 @@ static int tegra210_emc_probe(struct platform_device *pdev) config->same_freq = true; } - err =tegra210_clk_emc_attach (emc->clk, &emc->provider); -if (err <0 ) { -dev_err (&pdev->dev,"failed to attach to EMC clock: %d\n" , err); - goto release; - } - emc->clkchange_delay =100 ; emc->training_interval =100 ;dev_set_drvdata (emc->dev, emc);
@@ -1963,6 +1957,12 @@ static int tegra210_emc_probe(struct platform_device *pdev)timer_setup (&emc->training, tegra210_emc_train,0 ); + err =tegra210_clk_emc_attach (emc->clk, &emc->provider); +if (err <0 ) { +dev_err (&pdev->dev,"failed to attach to EMC clock: %d\n" , err); + goto release; + } +tegra210_emc_debugfs_init (emc); cd = devm_thermal_of_child_cooling_device_register(emc->dev, np, "emc", emc,
@@ -1978,6 +1978,8 @@ static int tegra210_emc_probe(struct platform_device *pdev) detach:debugfs_remove_recursive (emc->debugfs.root); +timer_shutdown_sync (&emc->training); +timer_shutdown_sync (&emc->refresh_timer);tegra210_clk_emc_detach (emc->clk); release:of_reserved_mem_device_release (emc->dev);
@@ -1990,6 +1992,8 @@ static void tegra210_emc_remove(struct platform_device *pdev)struct tegra210_emc *emc =platform_get_drvdata (pdev);debugfs_remove_recursive (emc->debugfs.root); +timer_shutdown_sync (&emc->training); +timer_shutdown_sync (&emc->refresh_timer);tegra210_clk_emc_detach (emc->clk);of_reserved_mem_device_release (emc->dev); }
Quoted 9 lines · Myeonghun Pak
The training and refresh timers can outlive the EMC state on removal or probe failure after clock attachment, causing use-after-free.
Shut down both timers before detaching the clock provider and releasing the timing tables to wait for callbacks and prevent rearming. Initialize them before clock attachment, since
set_rate()can start training.This issue was identified during our ongoing research while reviewing kernel code.
Really? Or you just took Sashiko's report?
https://sashiko.dev/#/bug/linux-47538f77-fb50-4a06-b49b-92dbee8b538b
Running LLM is not an ongoing research.
Applied.
Best regards,
Krzysztof
Quoted 8 lines · Myeonghun Pak
The training and refresh timers can outlive the EMC state on removal or probe failure after clock attachment, causing use-after-free.
Shut down both timers before detaching the clock provider and releasing the timing tables to wait for callbacks and prevent rearming. Initialize them before clock attachment, since
set_rate()can start training.[...]
Applied, thanks!
[1/1] memory: tegra: Shut down Tegra210 EMC timers before teardown
https://git.kernel.org/krzk/linux-mem-ctrl/c/394c350a34b77f1bb065b675d356ab55b6462ed8
Best regards,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>