[PATCH v9 08/11] sframe: Add .sframe validation option
From: Dylan Hatch
Date: Mon Nov 16 2026 - 21:07:22 EST
From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Add a debug feature to validate vmlinux and module .sframe sections at
boot and module load time rather than on demand during unwinding.
[ Jens Remus: Add support for SFrame V3. Add support for PC-relative
FDE function start offset. Adjust to rename of struct sframe_fre to
sframe_fre_internal. ]
[ Dylan Hatch: Adapt this patch for in-kernel sframe sections. ]
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Reviewed-by: Indu Bhagat <ibhagatgnu@xxxxxxxxx>
Co-developed-by: Jens Remus <jremus@xxxxxxxxxxxxx>
Signed-off-by: Jens Remus <jremus@xxxxxxxxxxxxx>
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
Co-developed-by: Dylan Hatch <dylanbhatch@xxxxxxxxxx>
Signed-off-by: Dylan Hatch <dylanbhatch@xxxxxxxxxx>
---
Changes since v8:
- (sashiko) Update CONFIG_SFRAME_VALIDATION help text and commit message
for in-kernel vmlinux and module .sframe validation, and move
<asm/unwind_sframe.h> include to "arm64/sframe: Validate IP addresses".
---
arch/Kconfig | 19 +++++++++++
kernel/unwind/sframe.c | 77 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
diff --git a/arch/Kconfig b/arch/Kconfig
index d2fc68e7023db..255f419f3f20e 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -539,6 +539,25 @@ config HAVE_UNWIND_KERNEL_SFRAME
practice, this can provide more reliable stacktrace results than
unwinding with frame pointers alone.
+config SFRAME_VALIDATION
+ bool "Enable .sframe section debugging"
+ depends on UNWIND_SFRAME_LOOKUP
+ depends on DYNAMIC_DEBUG
+ help
+ When initializing the .sframe section for vmlinux or a module,
+ validate the entire section immediately rather than on demand.
+
+ This is a debug feature which is helpful for rooting out .sframe
+ section issues. If the .sframe section is corrupt, SFrame unwinding
+ for that object will be disabled immediately with a warning, and more
+ information provided in dynamic printks.
+
+ This adds overhead at boot and module load time due to validating
+ every FDE and FRE in the .sframe section. Not recommended for
+ general use.
+
+ If unsure, say N.
+
config HAVE_PERF_REGS
bool
help
diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c
index 4d804f2ad9dde..2f491abc9f84c 100644
--- a/kernel/unwind/sframe.c
+++ b/kernel/unwind/sframe.c
@@ -509,6 +509,73 @@ noinstr int sframe_find(unsigned long ip, struct unwind_frame *frame)
}
NOKPROBE_SYMBOL(sframe_find);
+#ifdef CONFIG_SFRAME_VALIDATION
+
+static int sframe_validate_section(struct sframe_section *sec)
+{
+ unsigned long prev_ip = 0;
+ unsigned int i;
+
+ for (i = 0; i < sec->num_fdes; i++) {
+ struct sframe_fre_internal *fre, *prev_fre = NULL;
+ unsigned long ip, fre_addr;
+ struct sframe_fde_internal fde;
+ struct sframe_fre_internal fres[2];
+ bool which = false;
+ unsigned int j;
+ int ret;
+
+ ret = __read_fde(sec, i, &fde);
+ if (ret) {
+ dbg_sec(sec, "__read_fde(%u) failed\n", i);
+ return ret;
+ }
+
+ ip = fde.func_addr;
+ if (ip <= prev_ip) {
+ dbg_sec(sec, "FDE %u not sorted\n", i);
+ return -EFAULT;
+ }
+ prev_ip = ip;
+
+ fre_addr = sec->fres_start + fde.fres_off;
+ for (j = 0; j < fde.fres_num; j++) {
+ int ret;
+
+ fre = which ? fres : fres + 1;
+ which = !which;
+
+ ret = __read_fre(sec, &fde, fre_addr, fre);
+ if (ret) {
+ dbg_sec(sec, "FDE %u: __read_fre(%u) failed\n", i, j);
+ return ret;
+ }
+ ret = __read_fre_datawords(sec, &fde, fre);
+ if (ret) {
+ dbg_sec(sec, "FDE %u: __read_fre_datawords(%u) failed\n", i, j);
+ return ret;
+ }
+
+ fre_addr += fre->size;
+
+ if (prev_fre && fre->ip_off <= prev_fre->ip_off) {
+ dbg_sec(sec, "FDE %u: FRE %u not sorted\n", i, j);
+ return -EFAULT;
+ }
+
+ prev_fre = fre;
+ }
+ }
+
+ return 0;
+}
+
+#else /* !CONFIG_SFRAME_VALIDATION */
+
+static int sframe_validate_section(struct sframe_section *sec) { return 0; }
+
+#endif /* !CONFIG_SFRAME_VALIDATION */
+
static int sframe_read_header(struct sframe_section *sec)
{
unsigned long header_end, fdes_start, fdes_end, fdes_size, fres_start, fres_end;
@@ -569,6 +636,11 @@ void __init init_sframe_table(void)
return;
}
+ if (sframe_validate_section(&kernel_sfsec)) {
+ pr_warn("invalid vmlinux SFrame section\n");
+ return;
+ }
+
sframe_init = true;
dbg_print_header(&kernel_sfsec);
}
@@ -629,6 +701,11 @@ void sframe_module_init(struct module *mod, void *addr, unsigned int size)
}
sframe_sort_fdes(sec);
+ if (sframe_validate_section(sec)) {
+ pr_warn("invalid SFrame section in module %s\n", mod->name);
+ return;
+ }
+
/* Ensure SFrame is initialized when sframe_find() happens */
smp_store_release(&mod->sframe_init, true);
dbg_print_header(sec);
--
2.56.0.679.gc527c65306-goog