[PATCH AUTOSEL 6.19-6.12] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale() trace event
From: Sasha Levin
Date: Sun Feb 15 2026 - 10:04:03 EST
From: Keita Morisaki <keita.morisaki@xxxxxxxx>
[ Upstream commit 9672ed3de7d772ceddd713c769c05e832fc69bae ]
The ufs_mtk_clk_scale() trace event currently stores the address of the
name string directly via __field(const char *, name). This pointer may
become invalid after the module is unloaded, causing page faults when the
trace buffer is subsequently accessed.
This can occur because the MediaTek UFS driver can be configured as a
loadable module (tristate in Kconfig), meaning the name string passed to
the trace event may reside in module memory that becomes invalid after
module unload.
Fix this by using __string() and __assign_str() to copy the string contents
into the ring buffer instead of storing the pointer. This ensures the trace
data remains valid regardless of module state.
This change increases the memory usage for each ftrace entry by a few bytes
(clock names are typically 7-15 characters like "ufs_sel" or
"ufs_sel_max_src") compared to storing an 8-byte pointer.
Note that this change does not affect anything unless all of the following
conditions are met:
- CONFIG_SCSI_UFS_MEDIATEK is enabled
- ftrace tracing is enabled
- The ufs_mtk_clk_scale event is enabled in ftrace
Signed-off-by: Keita Morisaki <keita.morisaki@xxxxxxxx>
Reviewed-by: Peter Wang <peter.wang@xxxxxxxxxxxx>
Link: https://patch.msgid.link/20260202024526.122515-1-keita.morisaki@xxxxxxxx
Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
LLM Generated explanations, may be completely bogus:
The `ufs_mtk_clk_scale` trace event was introduced in August 2022
(kernel 6.1 era), so this buggy code exists in multiple stable trees
(6.1.y, 6.6.y, and later).
### 8. CONCLUSION
This is a textbook stable backport candidate:
- **Fixes a real crash** (page fault / use-after-free on dangling
pointer)
- **Extremely small and contained** (4-line change in one file)
- **Uses well-established patterns**
(`__string()/__assign_str()/__get_str()`) that are the correct and
standard approach
- **Zero risk of regression** — this is strictly more correct than the
original code
- **Affected code exists in stable trees** dating back to at least 6.1
- **Reviewed and accepted** by the relevant maintainers
- **Self-contained** — no dependencies on other patches
The fix is small, surgical, and meets all stable kernel criteria.
**YES**
drivers/ufs/host/ufs-mediatek-trace.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/ufs/host/ufs-mediatek-trace.h b/drivers/ufs/host/ufs-mediatek-trace.h
index b5f2ec3140748..0df8ac843379a 100644
--- a/drivers/ufs/host/ufs-mediatek-trace.h
+++ b/drivers/ufs/host/ufs-mediatek-trace.h
@@ -33,19 +33,19 @@ TRACE_EVENT(ufs_mtk_clk_scale,
TP_ARGS(name, scale_up, clk_rate),
TP_STRUCT__entry(
- __field(const char*, name)
+ __string(name, name)
__field(bool, scale_up)
__field(unsigned long, clk_rate)
),
TP_fast_assign(
- __entry->name = name;
+ __assign_str(name);
__entry->scale_up = scale_up;
__entry->clk_rate = clk_rate;
),
TP_printk("ufs: clk (%s) scaled %s @ %lu",
- __entry->name,
+ __get_str(name),
__entry->scale_up ? "up" : "down",
__entry->clk_rate)
);
--
2.51.0