public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: builder@sourceware.org
Cc: Di Chen <dichen@redhat.com>, elfutils-devel@sourceware.org
Subject: Re: ☠ Buildbot (GNU Toolchain): elfutils - failed test (failure) (master)
Date: Tue, 19 Apr 2022 11:28:52 +0200	[thread overview]
Message-ID: <Yl6A1OgZmsT3j44D@wildebeest.org> (raw)
In-Reply-To: <20220419090522.CA79A385780D@sourceware.org>

[-- Attachment #1: Type: text/plain, Size: 4214 bytes --]

Hi,

On Tue, Apr 19, 2022 at 09:05:22AM +0000, builder--- via Elfutils-devel wrote:
> A new failure has been detected on builder elfutils-debian-armhf while building elfutils.
> 
> Full details are available at:
>     https://builder.sourceware.org/buildbot/#builders/6/builds/3
> 
> Build state: failed test (failure)
> Revision: 5b497d8da4920bf7b63a4aa3752cf580b3ad654c
> Worker: debian-armhf
> Build Reason: (unknown)
> Blamelist: Di Chen <dichen@redhat.com>
> [...]
> - 7: make check ( failure )
>     Logs:
>         - stdio: https://builder.sourceware.org/buildbot/#builders/6/builds/3/steps/7/logs/stdio
>         - test-suite.log: https://builder.sourceware.org/buildbot/#builders/6/builds/3/steps/7/logs/test-suite_log
> [...]
> A new failure has been detected on builder elfutils-debian-i386 while building elfutils.
> 
> Full details are available at:
>     https://builder.sourceware.org/buildbot/#builders/17/builds/2
> 
> Build state: failed test (failure)
> Revision: 5b497d8da4920bf7b63a4aa3752cf580b3ad654c
> Worker: debian-i386
> Build Reason: (unknown)
> Blamelist: Di Chen <dichen@redhat.com>
> [...]
> - 7: make check ( failure )
>     Logs:
>         - stdio: https://builder.sourceware.org/buildbot/#builders/17/builds/2/steps/7/logs/stdio
>         - test-suite.log: https://builder.sourceware.org/buildbot/#builders/17/builds/2/steps/7/logs/test-suite_log

These are interesting failures:

==28027==ERROR: AddressSanitizer: stack-use-after-scope on address 0xbef24d60 at pc 0x004d9a6f bp 0xbef24c38 sp 0xbef24c3c
READ of size 8 at 0xbef24d60 thread T0
    #0 0x4d9a6d in get_dyn_ents /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:1787
    #1 0x4d9a6d in handle_dynamic /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:1810
    #2 0x4fcc75 in print_dynamic /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:1946
    #3 0x4fcc75 in process_elf_file /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:1008
    #4 0x5001c1 in process_dwflmod /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:792
    #5 0xb67fd7ad in dwfl_getmodules /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/libdwfl/dwfl_getmodules.c:86
    #6 0x4e352f in process_file /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:900
    #7 0x4d3c2b in main /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:372
    #8 0xb5fde523 in __libc_start_main /build/glibc-RK4xiD/glibc-2.28/csu/libc-start.c:308
Address 0xbef24d60 is located in stack of thread T0 at offset 160 in frame
    #0 0x4d8f83 in handle_dynamic /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:1795
  This frame has 5 object(s):
    [32, 36) 'shstrndx'
    [96, 112) 'dynmem'
    [160, 176) 'dyn_mem' <== Memory access at offset 160 is inside this variable
    [224, 288) 'glink_mem'
    [320, 384) 'buf'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-scope /var/lib/buildbot/workers/wildebeest/elfutils-debian-armhf/build/src/readelf.c:1787 in get_dyn_ents

I think they are not real bugs, or the valgrind builders would have
picked them up. But the are theoretically issues since a compiler
could optimize its stack usage to make this an issue.

static size_t 
get_dyn_ents (Elf_Data * dyn_data)
{
  GElf_Dyn *dyn;
  GElf_Dyn dyn_mem;
  size_t dyn_idx = 0;
  do
    {
      GElf_Dyn dyn_mem;
      dyn = gelf_getdyn(dyn_data, dyn_idx, &dyn_mem);
      if (dyn != NULL)
        ++dyn_idx;
    }
  while (dyn != NULL && dyn->d_tag != DT_NULL);

  return dyn_idx;
}

The issue is dyn pointing to dyn_mem, but dyn_mem being defined inside
the do while loop, while dyn is accessed "outside" it (or more
correctly, in the condition of the do while loop). Technically it
means at that point dyn_mem could have been purged from the
stack. Although unlikely moving the dyn_mem definition outside the
loop should fix it.

I'll push the attached fix.

Cheers,

Mark

[-- Attachment #2: 0001-readelf-Define-dyn_mem-outside-the-while-loop.patch --]
[-- Type: text/x-diff, Size: 1201 bytes --]

From 21fa92319657ca479ae108967fd41ac523a2f876 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Tue, 19 Apr 2022 11:25:42 +0200
Subject: [PATCH] readelf: Define dyn_mem outside the while loop.

The GCC address sanitizer might complain otherwise:
stack-use-after-scope src/readelf.c:1787 in get_dyn_ents

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 4 ++++
 src/readelf.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index f563e993..6ef81862 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2022-04-19  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (get_dyn_ents): Define dyn_mem outside the while loop.
+
 2022-03-01  Di Chen  <dichen@redhat.com>
 
 	* readelf.c (get_dyn_ents): New function.
diff --git a/src/readelf.c b/src/readelf.c
index 4b275ece..4b6aab2b 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1776,10 +1776,10 @@ static size_t
 get_dyn_ents (Elf_Data * dyn_data)
 {
   GElf_Dyn *dyn;
+  GElf_Dyn dyn_mem;
   size_t dyn_idx = 0;
   do
     {
-      GElf_Dyn dyn_mem;
       dyn = gelf_getdyn(dyn_data, dyn_idx, &dyn_mem);
       if (dyn != NULL)
 	++dyn_idx;
-- 
2.30.2


  reply	other threads:[~2022-04-19  9:28 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19  9:05 builder
2022-04-19  9:28 ` Mark Wielaard [this message]
2022-04-23  1:19 builder
2022-04-23  1:31 ` Mark Wielaard
2022-04-23 13:19 builder
2022-05-04 15:34 builder
2022-05-04 17:44 ` Mark Wielaard
2022-05-14 14:42 builder
2022-05-14 15:34 builder
2022-05-14 16:40 ` Mark Wielaard
2022-05-27 16:02 builder
2022-05-27 22:30 ` Mark Wielaard
2022-05-28  2:34   ` Frank Ch. Eigler
2022-05-28  9:04     ` Mark Wielaard
2022-05-28  9:15 builder
2022-05-28  9:35 ` Mark Wielaard
2022-05-28  9:43   ` Mark Wielaard
2022-06-02 15:44     ` Mark Wielaard
2022-07-31 23:54 builder
2022-08-01  0:09 ` Mark Wielaard
2022-08-01  9:13   ` Mark Wielaard
2022-09-14 19:36 builder
2022-10-13 16:51 builder
2022-10-16 15:47 builder
2022-10-16 16:26 ` Mark Wielaard
2022-10-16 21:02 builder
2022-10-17  9:08 builder
2022-10-17 10:26 ` Mark Wielaard
2022-10-17 11:02   ` Frank Ch. Eigler
2022-10-17 14:09     ` Frank Ch. Eigler
2022-10-17 14:59 builder
2022-10-27 19:25 builder
2022-10-31 13:51 builder
2022-11-01 21:28 builder
2022-11-02  1:15 builder
2022-11-02 12:06 ` Mark Wielaard
2022-11-02 13:39 builder
2022-11-02 14:19 ` Mark Wielaard
2022-11-03 15:27 builder
2022-11-04 22:29 builder
2022-11-28 13:30 builder
2022-12-12 14:31 builder
2022-12-19 23:56 builder
2022-12-21 18:22 builder
2023-01-14  2:51 builder

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=Yl6A1OgZmsT3j44D@wildebeest.org \
    --to=mark@klomp.org \
    --cc=builder@sourceware.org \
    --cc=dichen@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).