All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v5 02/11] perf tools: Check ELF section type with name
Date: Tue, 13 Oct 2026 13:49:38 -0700	[thread overview]
Message-ID: <as6ZYu8YcVjKB1YQ@google.com> (raw)
In-Reply-To: <sashiko-outbox-170233@kernel.org>

On Tue, Oct 13, 2026 at 05:31:14PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] perf symbol-elf: uninitialized memory read on gelf_getshdr failure
> --
> 
> commit f2750bf0f2a1c49778b5a9d0173f02f48eb9e193
> Author: Namhyung Kim <namhyung@kernel.org>
> 
> perf tools: Check ELF section type with name
> 
> This commit updates filename__has_section() to verify that a section
> has the SHT_PROGBITS type instead of just checking its name. This prevents
> empty sections with SHT_NOBITS from being incorrectly identified as present.
> 
> > diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> > --- a/tools/perf/util/symbol-elf.c
> > +++ b/tools/perf/util/symbol-elf.c
> > @@ -228,7 +228,8 @@ bool filename__has_section(const char *filename, const char *sec)
> >  	if (gelf_getehdr(elf, &ehdr) == NULL)
> >  		goto elf_out;
> >  
> > -	found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL);
> > +	found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL) &&
> > +		shdr.sh_type == SHT_PROGBITS;
> 
> [Severity: Medium]
> Can this lead to an uninitialized memory read of shdr.sh_type if the ELF
> file is malformed?
> 
> Looking at elf_section_by_name(), it does not check the return value of
> gelf_getshdr():
> 
> tools/perf/util/symbol-elf.c:elf_section_by_name() {
>     ...
>     gelf_getshdr(sec, shp);
>     str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
>     ...
> }
> 
> If gelf_getshdr() fails, it returns NULL and leaves the shp struct unmodified.
> Because shp points to the stack-allocated shdr in filename__has_section(),
> a failure in gelf_getshdr() leaves shdr potentially uninitialized.
> 
> Since this patch adds a direct read of shdr.sh_type after elf_section_by_name()
> returns, does this new check risk reading uninitialized stack memory?

Well.. it's already checked shp->sh_name is valid so I think it's ok.

But probably safer to check the return value.  It's also a separate
change though.

Thanks,
Namhyung

  reply	other threads:[~2026-10-13 20:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 17:21 [PATCH v5 00/11] perf symbol: Properly seto DSO binary/symtab types Namhyung Kim
2026-10-13 17:21 ` [PATCH v5 01/11] perf tools: Remove redundant dso data init Namhyung Kim
2026-10-13 17:25   ` sashiko-bot
2026-10-13 17:21 ` [PATCH v5 02/11] perf tools: Check ELF section type with name Namhyung Kim
2026-10-13 17:31   ` sashiko-bot
2026-10-13 20:49     ` Namhyung Kim [this message]
2026-10-13 17:21 ` [PATCH v5 03/11] perf tools: Try linked debug files for DSO debug info Namhyung Kim
2026-10-13 17:34   ` sashiko-bot
2026-10-13 20:59     ` Namhyung Kim
2026-10-13 17:21 ` [PATCH v5 04/11] perf symbol: Update symtab type of vmlinux from build-id cache Namhyung Kim
2026-10-13 17:32   ` sashiko-bot
2026-10-13 17:21 ` [PATCH v5 05/11] perf symbol: Set binary/symtab type for split kallsyms Namhyung Kim
2026-10-13 17:30   ` sashiko-bot
2026-10-13 17:21 ` [PATCH v5 06/11] perf symbol: Get rid of machine_or_dso_e_machine() Namhyung Kim
2026-10-13 17:37   ` sashiko-bot
2026-10-13 20:57     ` Namhyung Kim
2026-10-13 17:21 ` [PATCH v5 07/11] perf tools: Factor out dso__find_binary_type() Namhyung Kim
2026-10-13 17:30   ` sashiko-bot
2026-10-13 17:21 ` [PATCH v5 08/11] perf symbol: Set binary type for JIT map DSOs Namhyung Kim
2026-10-13 17:33   ` sashiko-bot
2026-10-13 17:21 ` [PATCH v5 09/11] perf symbol: Do not set binary type from symtab type Namhyung Kim
2026-10-13 17:35   ` sashiko-bot
2026-10-13 20:54     ` Namhyung Kim
2026-10-13 17:21 ` [PATCH v5 10/11] perf annotate: Simplify symbol__disassemble() with dso binary_type Namhyung Kim
2026-10-13 17:29   ` sashiko-bot
2026-10-13 17:21 ` [PATCH v5 11/11] perf test: Fix dso data tests Namhyung Kim
2026-10-13 17:30   ` sashiko-bot

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=as6ZYu8YcVjKB1YQ@google.com \
    --to=namhyung@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.