SFrame may represent an undefined return address (RA) as SFrame FRE without any offsets as indication for an outermost frame. Cc: Steven Rostedt Cc: Josh Poimboeuf Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Namhyung Kim Cc: Thomas Gleixner Cc: Andrii Nakryiko Cc: Indu Bhagat Cc: "Jose E. Marchesi" Cc: Beau Belgrave Cc: Jens Remus Cc: Linus Torvalds Cc: Andrew Morton Cc: Florian Weimer Cc: Sam James Cc: Kees Cook Cc: "Carlos O'Donell" Signed-off-by: Jens Remus --- Notes (jremus): Changes in v11: - New patch. (Jens) kernel/unwind/sframe.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c index 5536374e2a22..bc3e2eb00325 100644 --- a/kernel/unwind/sframe.c +++ b/kernel/unwind/sframe.c @@ -24,6 +24,7 @@ struct sframe_fre { s32 ra_off; s32 fp_off; u8 info; + bool ra_undefined; }; DEFINE_STATIC_SRCU(sframe_srcu); @@ -173,6 +174,7 @@ static __always_inline int __read_fre(struct sframe_section *sec, unsigned char offset_count, offset_size; s32 cfa_off, ra_off, fp_off; unsigned long cur = fre_addr; + bool ra_undefined = false; unsigned char addr_size; u32 ip_off; u8 info; @@ -191,7 +193,7 @@ static __always_inline int __read_fre(struct sframe_section *sec, UNSAFE_GET_USER_INC(info, cur, 1, Efault); offset_count = SFRAME_FRE_OFFSET_COUNT(info); offset_size = offset_size_enum_to_size(SFRAME_FRE_OFFSET_SIZE(info)); - if (!offset_count || !offset_size) + if (!offset_size) return -EFAULT; if (cur + (offset_count * offset_size) > sec->fres_end) @@ -199,6 +201,14 @@ static __always_inline int __read_fre(struct sframe_section *sec, fre->size = addr_size + 1 + (offset_count * offset_size); + if (!offset_count) { + cfa_off = 0; + ra_off = 0; + fp_off = 0; + ra_undefined = true; + goto done; + } + UNSAFE_GET_USER_INC(cfa_off, cur, offset_size, Efault); offset_count--; @@ -219,11 +229,13 @@ static __always_inline int __read_fre(struct sframe_section *sec, if (offset_count) return -EFAULT; +done: fre->ip_off = ip_off; fre->cfa_off = cfa_off; fre->ra_off = ra_off; fre->fp_off = fp_off; fre->info = info; + fre->ra_undefined = ra_undefined; return 0; @@ -285,6 +297,7 @@ static __always_inline int __find_fre(struct sframe_section *sec, frame->ra_off = fre->ra_off; frame->fp_off = fre->fp_off; frame->use_fp = SFRAME_FRE_CFA_BASE_REG_ID(fre->info) == SFRAME_BASE_REG_FP; + frame->outermost = fre->ra_undefined; return 0; } -- 2.48.1