From: Steven Rostedt <rostedt@kernel.org>
To: Jens Remus <jremus@linux.ibm.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
Indu Bhagat <ibhagatgnu@gmail.com>,
bpf@vger.kernel.org, sashiko@lists.linux.dev,
"Jose E. Marchesi" <jemarch@gnu.org>
Subject: Re: [PATCH v14 06/19] unwind_user/sframe: Detect .sframe sections in executables
Date: Wed, 6 May 2026 11:36:05 -0400 [thread overview]
Message-ID: <20260506113605.5df32968@fedora> (raw)
In-Reply-To: <29d28c6e-2909-444e-b22a-7429464056dd@linux.ibm.com>
On Wed, 6 May 2026 16:56:01 +0200
Jens Remus <jremus@linux.ibm.com> wrote:
> >> --- a/fs/binfmt_elf.c
> >> +++ b/fs/binfmt_elf.c
> > [ ... ]
> >> @@ -637,6 +638,21 @@ static inline int make_prot(u32 p_flags, struct arch_elf_state *arch_state,
> >> return arch_elf_adjust_prot(prot, arch_state, has_interp, is_interp);
> >> }
> >>
> >> +static void elf_add_sframe(struct elf_phdr *text, struct elf_phdr *sframe,
> >> + unsigned long base_addr)
> >> +{
> >> + unsigned long sframe_start, sframe_end, text_start, text_end;
> >> +
> >> + sframe_start = base_addr + sframe->p_vaddr;
> >> + sframe_end = sframe_start + sframe->p_memsz;
> >> +
> >> + text_start = base_addr + text->p_vaddr;
> >> + text_end = text_start + text->p_memsz;
> >
> > Should text_end be calculated as text_start + text->p_memsz - 1?
> >
> > Since the maple tree API strictly expects inclusive ranges [first, last] for
> > insertions, passing the exclusive text_end would cause the inserted range
> > to cover one byte beyond the actual segment.
>
> Shall we keep the text_end and sframe_end is pointing past the
> respective section end semantic and just adjust the value passed on the
> call to mtree_insert_range()?
Let's keep the end exclusive, and add the "- 1" to text_end before
passing it to the mtree_insert_range(). I did that to get it working for
me.
>
> >
> > If an ELF binary has adjacent executable PT_LOAD segments, could the first
> > segment's inclusive end overlap with the next segment's start and fail
> > subsequent insertions?
> >
> >> +
> >> + /* Ignore return value, sframe section isn't critical */
> >> + sframe_add_section(sframe_start, sframe_end, text_start, text_end);
> >> +}
> >> +
> > [ ... ]
> >> @@ -712,6 +729,19 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
> >> error = -ENOMEM;
> >> goto out;
> >> }
> >> + break;
> >> + }
> >> + case PT_GNU_SFRAME:
> >> + sframe_phdr = eppnt;
> >> + break;
> >> + }
> >> + }
> >> +
> >> + if (sframe_phdr) {
> >> + eppnt = interp_elf_phdata;
> >> + for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
> >> + if (eppnt->p_flags & PF_X)
>
> if (eppnt->p_flags & PF_X && eppnt->p_type == PT_LOAD)
>
> >> + elf_add_sframe(eppnt, sframe_phdr, load_addr);
> >
> > Does this need to verify the segment is loadable (eppnt->p_type == PT_LOAD)?
> >
> > If non-loadable segments like PT_GNU_STACK have the PF_X flag set, they
> > typically have p_vaddr and p_memsz as 0. Processing these segments would
> > compute bogus text boundaries and bypass VMA validation. If a legitimate
> > PT_LOAD segment overlaps with these bogus ranges, could its insertion fail
> > silently and break stack unwinding for the executable?
>
> Do you agree?
Indu or Jose?
-- Steve
>
> >
> >> }
> >> }
> >>
> > [ ... ]
> >> @@ -1242,6 +1276,14 @@ static int load_elf_binary(struct linux_binprm *bprm)
> >> elf_brk = k;
> >> }
> >>
> >> + if (sframe_phdr) {
> >> + for (i = 0, elf_ppnt = elf_phdata;
> >> + i < elf_ex->e_phnum; i++, elf_ppnt++) {
> >> + if ((elf_ppnt->p_flags & PF_X))
>
> if (elf_ppnt->p_flags & PF_X && elf_ppnt->p_type == PT_LOAD)
>
> >> + elf_add_sframe(elf_ppnt, sframe_phdr, load_bias);
> >
> > Similarly, should this also check if the segment is a PT_LOAD segment before
> > adding it to the sframe sections?
>
> Likewise.
>
> Regards,
> Jens
next prev parent reply other threads:[~2026-05-06 15:36 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 12:16 [PATCH v14 00/19] unwind_deferred: Implement sframe handling Jens Remus
2026-05-05 12:17 ` [PATCH v14 01/19] unwind_user: Add generic and arch-specific headers to MAINTAINERS Jens Remus
2026-05-05 12:17 ` [PATCH v14 02/19] unwind_user/sframe: Add support for reading .sframe headers Jens Remus
2026-05-05 12:49 ` sashiko-bot
2026-05-06 13:42 ` Jens Remus
2026-05-07 14:55 ` Jens Remus
2026-05-08 23:02 ` Indu Bhagat
2026-05-11 10:05 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 03/19] unwind_user/sframe: Store .sframe section data in per-mm maple tree Jens Remus
2026-05-05 18:51 ` sashiko-bot
2026-05-06 13:50 ` Jens Remus
2026-05-06 15:21 ` Steven Rostedt
2026-05-12 15:52 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 04/19] x86/uaccess: Add unsafe_copy_from_user() implementation Jens Remus
2026-05-05 18:22 ` sashiko-bot
2026-05-06 14:13 ` Jens Remus
2026-05-06 15:05 ` Steven Rostedt
2026-05-06 14:09 ` Jens Remus
2026-05-06 15:03 ` Steven Rostedt
2026-05-06 21:13 ` David Laight
2026-05-06 21:17 ` David Laight
2026-05-05 12:17 ` [PATCH v14 05/19] unwind_user/sframe: Add support for reading .sframe contents Jens Remus
2026-05-05 18:59 ` sashiko-bot
2026-05-06 14:34 ` Jens Remus
2026-05-06 15:01 ` Steven Rostedt
2026-05-06 15:29 ` Jens Remus
2026-05-08 9:49 ` Jens Remus
2026-05-08 23:04 ` Indu Bhagat
2026-05-12 13:35 ` Jens Remus
2026-05-13 12:22 ` Steven Rostedt
2026-05-08 23:03 ` Indu Bhagat
2026-05-08 10:50 ` Jens Remus
2026-05-11 16:16 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 06/19] unwind_user/sframe: Detect .sframe sections in executables Jens Remus
2026-05-05 12:53 ` sashiko-bot
2026-05-06 14:56 ` Jens Remus
2026-05-06 15:36 ` Steven Rostedt [this message]
2026-05-08 23:05 ` Indu Bhagat
2026-05-05 12:17 ` [PATCH v14 07/19] unwind_user/sframe: Wire up unwind_user to sframe Jens Remus
2026-05-05 18:55 ` sashiko-bot
2026-05-07 16:18 ` Jens Remus
2026-05-08 23:07 ` Indu Bhagat
2026-05-11 16:46 ` Steven Rostedt
2026-05-05 12:17 ` [PATCH v14 08/19] unwind_user: Stop when reaching an outermost frame Jens Remus
2026-05-05 12:40 ` sashiko-bot
2026-05-06 15:01 ` Jens Remus
2026-05-06 15:40 ` Steven Rostedt
2026-05-05 12:17 ` [PATCH v14 09/19] unwind_user/sframe: Add support for outermost frame indication Jens Remus
2026-05-05 12:17 ` [PATCH v14 10/19] unwind_user/sframe: Remove .sframe section on detected corruption Jens Remus
2026-05-05 20:39 ` sashiko-bot
2026-05-07 16:23 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 11/19] unwind_user/sframe: Show file name in debug output Jens Remus
2026-05-05 18:46 ` sashiko-bot
2026-05-12 14:52 ` Jens Remus
2026-05-13 9:20 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 12/19] unwind_user/sframe: Add .sframe validation option Jens Remus
2026-05-05 18:32 ` sashiko-bot
2026-05-12 14:23 ` Jens Remus
2026-05-13 12:30 ` Steven Rostedt
2026-05-08 10:51 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 13/19] unwind_user: Enable archs that pass RA in a register Jens Remus
2026-05-05 18:35 ` sashiko-bot
2026-05-05 12:17 ` [PATCH v14 14/19] unwind_user: Flexible FP/RA recovery rules Jens Remus
2026-05-05 18:34 ` sashiko-bot
2026-05-05 12:17 ` [PATCH v14 15/19] unwind_user: Flexible CFA " Jens Remus
2026-05-05 12:17 ` [PATCH v14 16/19] unwind_user/sframe: Add support for SFrame V3 flexible FDEs Jens Remus
2026-05-05 18:55 ` sashiko-bot
2026-05-07 15:30 ` Jens Remus
2026-05-13 6:26 ` Indu Bhagat
2026-05-13 13:50 ` Jens Remus
2026-05-13 15:16 ` Steven Rostedt
2026-05-05 12:17 ` [PATCH v14 17/19] unwind_user/sframe: Separate reading of FRE from reading of FRE data words Jens Remus
2026-05-05 19:05 ` sashiko-bot
2026-05-07 16:01 ` Jens Remus
2026-05-05 12:17 ` [PATCH v14 18/19] unwind_user/sframe/x86: Enable sframe unwinding on x86 Jens Remus
2026-05-05 19:07 ` sashiko-bot
2026-05-05 12:17 ` [PATCH v14 19/19] unwind_user/sframe: Add prctl() interface for registering .sframe sections Jens Remus
2026-05-05 18:45 ` sashiko-bot
2026-05-07 14:14 ` Jens Remus
2026-05-05 12:25 ` [PATCH v14 00/19] unwind_deferred: Implement sframe handling Jens Remus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260506113605.5df32968@fedora \
--to=rostedt@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=ibhagatgnu@gmail.com \
--cc=jemarch@gnu.org \
--cc=jpoimboe@kernel.org \
--cc=jremus@linux.ibm.com \
--cc=sashiko@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox