linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
  • [parent not found: <172300808013.2419749.16446009147309523545.b4-ty@kernel.org>]
  • * Re: [PATCH v3] binfmt_elf: Dump smaller VMAs first in ELF cores
           [not found] <036CD6AE-C560-4FC7-9B02-ADD08E380DC9@juniper.net>
           [not found] ` <CAHk-=wh_P7UR6RiYmgBDQ4L-kgmmLMziGarLsx_0bUn5vYTJUw@mail.gmail.com>
           [not found] ` <172300808013.2419749.16446009147309523545.b4-ty@kernel.org>
    @ 2024-08-10 12:28 ` Eric W. Biederman
      2024-08-12 18:05   ` Kees Cook
      2025-02-18  8:54 ` Michael Stapelberg
      3 siblings, 1 reply; 21+ messages in thread
    From: Eric W. Biederman @ 2024-08-10 12:28 UTC (permalink / raw)
      To: Brian Mak
      Cc: Kees Cook, Alexander Viro, Christian Brauner, Jan Kara,
    	linux-fsdevel, linux-mm, linux-kernel, Oleg Nesterov,
    	Linus Torvalds
    
    Brian Mak <makb@juniper.net> writes:
    
    > Large cores may be truncated in some scenarios, such as with daemons
    > with stop timeouts that are not large enough or lack of disk space. This
    > impacts debuggability with large core dumps since critical information
    > necessary to form a usable backtrace, such as stacks and shared library
    > information, are omitted.
    >
    > We attempted to figure out which VMAs are needed to create a useful
    > backtrace, and it turned out to be a non-trivial problem. Instead, we
    > try simply sorting the VMAs by size, which has the intended effect.
    >
    > By sorting VMAs by dump size and dumping in that order, we have a
    > simple, yet effective heuristic.
    
    To make finding the history easier I would include:
    v1: https://lkml.kernel.org/r/CB8195AE-518D-44C9-9841-B2694A5C4002@juniper.net
    v2: https://lkml.kernel.org/r/C21B229F-D1E6-4E44-B506-A5ED4019A9DE@juniper.net
    
    Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
    
    As Kees has already picked this up this is quite possibly silly.
    But *shrug* that was when I was out.
    
    
    > Signed-off-by: Brian Mak <makb@juniper.net>
    > ---
    >
    > Hi all,
    >
    > Still need to run rr tests on this, per Kees Cook's suggestion, will
    > update back once done. GDB and readelf show that this patch works
    > without issue though.
    >
    > Thanks,
    > Brian Mak
    >
    > v3: Edited commit message to better convey alternative solution as
    >     non-trivial
    >
    >     Moved sorting logic to fs/coredump.c to make it in place
    >
    >     Above edits suggested by Eric Biederman <ebiederm@xmission.com>
    >
    > v2: Edited commit message to include more reasoning for sorting VMAs
    >     
    >     Removed conditional VMA sorting with debugfs knob
    >     
    >     Above edits suggested by Eric Biederman <ebiederm@xmission.com>
    >
    >  fs/coredump.c | 16 ++++++++++++++++
    >  1 file changed, 16 insertions(+)
    >
    > diff --git a/fs/coredump.c b/fs/coredump.c
    > index 7f12ff6ad1d3..33c5ac53ab31 100644
    > --- a/fs/coredump.c
    > +++ b/fs/coredump.c
    > @@ -18,6 +18,7 @@
    >  #include <linux/personality.h>
    >  #include <linux/binfmts.h>
    >  #include <linux/coredump.h>
    > +#include <linux/sort.h>
    >  #include <linux/sched/coredump.h>
    >  #include <linux/sched/signal.h>
    >  #include <linux/sched/task_stack.h>
    > @@ -1191,6 +1192,18 @@ static void free_vma_snapshot(struct coredump_params *cprm)
    >  	}
    >  }
    >  
    > +static int cmp_vma_size(const void *vma_meta_lhs_ptr, const void *vma_meta_rhs_ptr)
    > +{
    > +	const struct core_vma_metadata *vma_meta_lhs = vma_meta_lhs_ptr;
    > +	const struct core_vma_metadata *vma_meta_rhs = vma_meta_rhs_ptr;
    > +
    > +	if (vma_meta_lhs->dump_size < vma_meta_rhs->dump_size)
    > +		return -1;
    > +	if (vma_meta_lhs->dump_size > vma_meta_rhs->dump_size)
    > +		return 1;
    > +	return 0;
    > +}
    > +
    >  /*
    >   * Under the mmap_lock, take a snapshot of relevant information about the task's
    >   * VMAs.
    > @@ -1253,5 +1266,8 @@ static bool dump_vma_snapshot(struct coredump_params *cprm)
    >  		cprm->vma_data_size += m->dump_size;
    >  	}
    >  
    > +	sort(cprm->vma_meta, cprm->vma_count, sizeof(*cprm->vma_meta),
    > +		cmp_vma_size, NULL);
    > +
    >  	return true;
    >  }
    >
    > base-commit: eb5e56d1491297e0881c95824e2050b7c205f0d4
    
    
    ^ permalink raw reply	[flat|nested] 21+ messages in thread
  • * [PATCH v3] binfmt_elf: Dump smaller VMAs first in ELF cores
           [not found] <036CD6AE-C560-4FC7-9B02-ADD08E380DC9@juniper.net>
                       ` (2 preceding siblings ...)
      2024-08-10 12:28 ` Eric W. Biederman
    @ 2025-02-18  8:54 ` Michael Stapelberg
      2025-02-18 19:53   ` Brian Mak
      3 siblings, 1 reply; 21+ messages in thread
    From: Michael Stapelberg @ 2025-02-18  8:54 UTC (permalink / raw)
      To: makb
      Cc: brauner, ebiederm, jack, kees, linux-fsdevel, linux-kernel,
    	linux-mm, oleg, torvalds, viro
    
    Hey Brian and folks
    
    > […]
    > backtrace, and it turned out to be a non-trivial problem. Instead, we
    > try simply sorting the VMAs by size, which has the intended effect.
    > […]
    > Still need to run rr tests on this, per Kees Cook's suggestion, will
    > update back once done. GDB and readelf show that this patch works
    > without issue though.
    
    I think in your testing, you probably did not try the eu-stack tool
    from the elfutils package, because I think I found a bug:
    
    Current elfutils cannot symbolize core dumps created by Linux 6.12+.
    I noticed this because systemd-coredump(8) uses elfutils, and when
    a program crashed on my machine, syslog did not show function names.
    
    I reported this issue with elfutils at:
    https://sourceware.org/bugzilla/show_bug.cgi?id=32713
    …but figured it would be good to give a heads-up here, too.
    
    Is this breakage sufficient reason to revert the commit?
    Or are we saying userspace just needs to be updated to cope?
    
    Thanks
    Best regards
    Michael
    
    
    ^ permalink raw reply	[flat|nested] 21+ messages in thread

  • end of thread, other threads:[~2025-02-22 15:15 UTC | newest]
    
    Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
    -- links below jump to the message on this page --
         [not found] <036CD6AE-C560-4FC7-9B02-ADD08E380DC9@juniper.net>
         [not found] ` <CAHk-=wh_P7UR6RiYmgBDQ4L-kgmmLMziGarLsx_0bUn5vYTJUw@mail.gmail.com>
    2024-08-09 14:39   ` [PATCH v3] binfmt_elf: Dump smaller VMAs first in ELF cores Eric W. Biederman
    2024-08-09 15:13     ` Linus Torvalds
         [not found] ` <172300808013.2419749.16446009147309523545.b4-ty@kernel.org>
    2024-08-10  0:52   ` Brian Mak
    2024-08-10  4:06     ` Kees Cook
    2024-08-10 12:28 ` Eric W. Biederman
    2024-08-12 18:05   ` Kees Cook
    2024-08-12 18:21     ` Brian Mak
    2024-08-12 18:25       ` Kees Cook
    2025-02-18  8:54 ` Michael Stapelberg
    2025-02-18 19:53   ` Brian Mak
    2025-02-19 13:28     ` Sam James
    2025-02-19 16:20     ` Jan Kara
    2025-02-19 19:52       ` Kees Cook
    2025-02-19 20:38         ` Brian Mak
    2025-02-22  2:13           ` Brian Mak
    2025-02-22 14:51             ` Kees Cook
    2025-02-20  0:23         ` Brian Mak
    2025-02-20  0:39         ` Linus Torvalds
    2025-02-20  1:36           ` Kees Cook
    2025-02-20 22:59             ` Brian Mak
    2025-02-22 15:15               ` Kees Cook
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox