clk: imx: fix NULL pointer deref in imx_unregister_hw_clocks() error path - #49
Conversation
…path
imx_unregister_hw_clocks() unconditionally calls clk_hw_unregister()
for every entry in the hws[] array up to count, including entries that
were never populated because the calling probe function (e.g.
imx93_clocks_probe()) returned early on error before filling the whole
array. Those unfilled entries are still NULL/zeroed, so
clk_hw_unregister(NULL) dereferences a NULL pointer and crashes.
Reproduced on FRDM-IMX91 (i.MX91) when imx93_clocks_probe() jumps to
the unregister_hws error path after devm_of_iomap() fails on the
"fsl,imx93-anatop" node (WARN_ON at clk-imx93.c:339): the subsequent
imx_unregister_hw_clocks(clks, IMX93_CLK_END) call walks past the ~10
clocks actually registered and hits NULL entries, turning a recoverable
probe failure into a full kernel panic ("Attempted to kill init!").
Skip entries that are NULL or an error pointer before unregistering.
Signed-off-by: ThangNN99 <ngocthang2710.1999@gmail.com>
|
@MrVan @Anson-Huang could you please take a look when you have a chance? This fixes a NULL pointer deref crash in the shared clk_hw_unregister() error path that I hit while bringing up a standalone build on FRDM-IMX91 (imx93_clocks_probe() failing on the anatop iomap). Thanks! |
|
Correction for @MrVan @Anson-Huang: I initially speculated the root |
Separate finding: lf-6.18.y regression report (issues are disabled on this repo, posting here instead)Since this repo has Issues disabled, filing the full root-cause writeup for the underlying Summary: on FRDM-IMX91, (full deferred-probe list and elimination table already in the PR description above) Environment: Flagging in case anyone tracking |
Follow-up: pinpointed the architectural change behind the lf-6.18.y regressionDug further into this (comparing
I initially suspected a compatible-string mismatch from this refactor (i.e. that So the regression looks like it's specifically in the driver-unification refactor itself (imx91 clock support folded into |
|
Opened #50 with a working fix for the underlying |
Summary
imx_unregister_hw_clocks()unconditionally callsclk_hw_unregister()forevery entry in the
hws[]array up tocount, including entries that werenever populated because the calling probe function returned early on error
before filling the whole array. Those unfilled entries are still NULL, so
clk_hw_unregister(NULL)dereferences a NULL pointer and crashes.How it was found
Reproduced on FRDM-IMX91 (i.MX91, standalone U-Boot/kernel build,
imx91_11x11_frdm_defconfig+imx91-11x11-frdm.dtb) whenimx93_clocks_probe()(shared clock driver for i.MX91/i.MX93) jumps to theunregister_hwserror path afterdevm_of_iomap()fails on the"fsl,imx93-anatop"node:imx_unregister_hw_clocks(clks, IMX93_CLK_END)walks past the ~10 clocksactually registered before the failure and hits NULL entries, turning a
recoverable probe failure into a full kernel panic.
Fix
Skip entries that are NULL or an error pointer before unregistering.
Test plan
imx93_clocks_probe()failure escalates to a kernel panic (
Attempted to kill init!).After the fix, the probe fails gracefully (
error -22), bootcontinues normally, and the kernel reaches the expected
VFS: Unable to mount root fsstop point (no rootfs attached in thistest setup).
Update: root cause of the underlying
imx93_clocks_probe()failure identifiedAn earlier version of this description speculated the
devm_of_iomap()failure on the anatop node was related to TRDC access configuration in ATF.
That hypothesis has since been disproven by elimination testing and is
retracted so it doesn't mislead anyone investigating further:
lf-6.18.yimx-boot-imx91frdm-sd.bin-flash_singleboot/lf-6.18.ylf-6.18.ylf-6.12.ySwapping SPL and then BL31+OP-TEE for NXP's own known-good binaries (from
their validated FRDM release) did not change the outcome at all — same
crash, same offsets. The only change that fixed it was switching the kernel
branch from
lf-6.18.ytolf-6.12.y. Sinceimx93_clocks_probe()runsentirely in kernel space, well after firmware hand-off, this rules out
SPL/ATF/OP-TEE/TRDC and points to a
lf-6.18.y-specific regression in theimx93-ccmdriver or its interaction with the FRDM-IMX91 DT on that branch.This PR's NULL-check fix remains correct and worth keeping regardless (any
early probe failure elsewhere would hit the same crash), but it does not
address that separate
lf-6.18.yregression, which needs its owninvestigation/issue.