linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Svetlana Parfenova <svetlana.parfenova@syntacore.com>
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	brauner@kernel.org, jack@suse.cz, akpm@linux-foundation.org,
	david@redhat.com, lorenzo.stoakes@oracle.com,
	Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org,
	surenb@google.com, mhocko@suse.com
Subject: Re: [RFC RESEND] binfmt_elf: preserve original ELF e_flags in core dumps
Date: Fri, 08 Aug 2025 14:54:32 -0700	[thread overview]
Message-ID: <86553D38-36C1-4EBB-9732-A2C593A76260@kernel.org> (raw)
In-Reply-To: <2c196c3f-4d49-494c-898e-8a1f6249ce24@syntacore.com>



On August 8, 2025 8:54:30 AM PDT, Svetlana Parfenova <svetlana.parfenova@syntacore.com> wrote:
>On 08/08/2025 03.14, Kees Cook wrote:
>> On Thu, Aug 07, 2025 at 07:13:50PM +0600, Svetlana Parfenova wrote:
>>> On 07/08/2025 00.57, Kees Cook wrote:
>>>> On Wed, Aug 06, 2025 at 10:18:14PM +0600, Svetlana Parfenova
>>>> wrote:
>>>>> Preserve the original ELF e_flags from the executable in the
>>>>> core dump header instead of relying on compile-time defaults
>>>>> (ELF_CORE_EFLAGS or value from the regset view). This ensures
>>>>> that ABI-specific flags in the dump file match the actual
>>>>> binary being executed.
>>>>> 
>>>>> Save the e_flags field during ELF binary loading (in
>>>>> load_elf_binary()) into the mm_struct, and later retrieve it
>>>>> during core dump generation (in fill_note_info()). Use this
>>>>> saved value to populate the e_flags in the core dump ELF
>>>>> header.
>>>>> 
>>>>> Add a new Kconfig option, CONFIG_CORE_DUMP_USE_PROCESS_EFLAGS,
>>>>> to guard this behavior. Although motivated by a RISC-V use
>>>>> case, the mechanism is generic and can be applied to all
>>>>> architectures.
>>>> 
>>>> In the general case, is e_flags mismatched? i.e. why hide this
>>>> behind a Kconfig? Put another way, if I enabled this Kconfig and
>>>> dumped core from some regular x86_64 process, will e_flags be
>>>> different?
>>>> 
>>> 
>>> The Kconfig option is currently restricted to the RISC-V
>>> architecture because it's not clear to me whether other
>>> architectures need actual e_flags value from ELF header. If this
>>> option is disabled, the core dump will always use a compile time
>>> value for e_flags, regardless of which method is selected:
>>> ELF_CORE_EFLAGS or CORE_DUMP_USE_REGSET. And this constant does not necessarily reflect the actual e_flags of the running process
>>> (at least on RISC-V), which can vary depending on how the binary
>>> was compiled. Thus, I made a third method to obtain e_flags that
>>> reflects the real value. And it is gated behind a Kconfig option,
>>> as not all users may need it.
>> 
>> Can you check if the ELF e_flags and the hard-coded e_flags actually differ on other architectures? I'd rather avoid using the Kconfig so
>> we can have a common execution path for all architectures.
>> 
>
>I checked various architectures, and most don’t use e_flags in core
>dumps - just zero value. For x86 this is valid since it doesn’t define
>values for e_flags. However, architectures like ARM do have meaningful
>e_flags, yet still they are set to zero in core dumps. I guess the real
>question isn't about core dump correctness, but whether tools like GDB
>actually rely on e_flags to provide debug information. Seems like most
>architectures either don’t use it or can operate without it. RISC-V
>looks like black sheep here ... GDB relies on e_flags to determine the
>ABI and interpret the core dump correctly.
>
>What if I rework my patch the following way:
>- remove Kconfig option;
>- add function/macro that would override e_flags with value taken from
>process, but it would only be applied if architecture specifies that.
>
>Would that be a better approach?

Yeah! Let's see what that looks like. :)


-- 
Kees Cook


  reply	other threads:[~2025-08-08 21:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-06 16:18 Svetlana Parfenova
2025-08-06 18:57 ` Kees Cook
2025-08-07 13:13   ` Svetlana Parfenova
2025-08-07 21:14     ` Kees Cook
2025-08-08 15:54       ` Svetlana Parfenova
2025-08-08 21:54         ` Kees Cook [this message]
2025-08-11  9:53 ` [RFC RESEND v2] binfmt_elf: preserve original ELF e_flags for " Svetlana Parfenova
2025-08-25 17:17   ` Kees Cook
2025-09-01 13:58     ` Svetlana Parfenova
2025-09-01 13:53 ` [RFC RESEND v3] " Svetlana Parfenova
2025-09-04  3:52   ` Kees Cook
2025-09-04  3:52   ` Kees Cook

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=86553D38-36C1-4EBB-9732-A2C593A76260@kernel.org \
    --to=kees@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=david@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=svetlana.parfenova@syntacore.com \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    /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