public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2 00/10] Undefined Behavior Sanitizer, this time with docs
Date: Mon, 08 Oct 2018 19:14:00 -0000	[thread overview]
Message-ID: <8df7a2b9-800a-5a70-1075-e687145c9394@FreeBSD.org> (raw)
In-Reply-To: <20181002044420.17628-1-tom@tromey.com>

On 10/1/18 9:44 PM, Tom Tromey wrote:
> This is a new version of the series to add -fsanitize=undefined to the
> build.
> 
> It's only added to gdb, though it occurred to me later that it would
> probably be better to add it to all the libraries as well.
> 
> This version addresses the review comments, and in particular adds
> documentation in patch #10 about performance.  It also fixes a bug
> observed on the S390 builds in patch #2.
> 
> Regression tested by the buildbot.

FWIW, I built GDB master today and ubsan (from LLVM, not GCC) flagged a
use of obstack_blank_fast() in minsyms.c with a negative offset (used to
shrink an obstack) when trying to do 'start' on /bin/ls:

(gdb) start
Temporary breakpoint 1 at 0x402674: file /usr/src/bin/ls/ls.c, line 161.
Starting program: /bin/ls 
../../gdb/minsyms.c:1378:7: runtime error: addition of unsigned offset to 0x00080907cd10 overflowed to 0x00080907cc38

This corresponds to the invocation of obstack_blank_fast here:

      /* Compact out any duplicates, and free up whatever space we are
         no longer using.  */

      mcount = compact_minimal_symbols (msymbols, mcount, m_objfile);

      obstack_blank_fast (&m_objfile->per_bfd->storage_obstack,
	       (mcount + 1 - alloc_count) * sizeof (struct minimal_symbol));

The case that triggered the failure for me had these values that resulted
in a negative offset:

(top-gdb) p mcount
$23 = 5740
(top-gdb) p alloc_count
$24 = 5744
...
(top-gdb) p mcount + 1 - alloc_count
$26 = -3

I guess since sizeof's return type is size_t, then the promotion rules on
LP64 mean that the resulting value is unsigned?  Anyway, we might consider
making ubsan only default to on for GCC for now?

-- 
John Baldwin

                                                                            

  parent reply	other threads:[~2018-10-08 19:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  4:44 Tom Tromey
2018-10-02  4:44 ` [PATCH v2 10/10] Add --enable-ubsan Tom Tromey
2018-10-02 13:53   ` Eli Zaretskii
2018-10-02 21:26     ` Tom Tromey
2018-10-02 21:28       ` Tom Tromey
2018-10-03 17:31         ` Eli Zaretskii
2018-10-03 17:54   ` Pedro Alves
2018-10-03 21:09     ` Tom Tromey
2018-10-02  4:44 ` [PATCH v2 09/10] Avoid undefined behavior in expression dumping Tom Tromey
2018-10-03 17:48   ` Pedro Alves
2018-10-02  4:44 ` [PATCH v2 04/10] Avoid undefined behavior in extract_integer Tom Tromey
2018-10-02  4:44 ` [PATCH v2 08/10] Avoid undefined behavior in ada_operator_length Tom Tromey
2018-10-02  4:44 ` [PATCH v2 07/10] Avoid undefined behavior in read_signed_leb128 Tom Tromey
2018-10-02  4:44 ` [PATCH v2 02/10] Change dwarf2_frame_state_reg_info::reg to be std::vector Tom Tromey
2018-10-03 17:28   ` Pedro Alves
2018-10-03 21:05     ` Tom Tromey
2018-10-02  4:44 ` [PATCH v2 06/10] Avoid undefined behavior in parse_number Tom Tromey
2018-10-02  4:44 ` [PATCH v2 03/10] Use unsigned as base type for some enums Tom Tromey
2018-10-03 17:33   ` Pedro Alves
2018-10-03 21:07     ` Tom Tromey
2018-10-02  4:44 ` [PATCH v2 01/10] Do not pass NULL to memcpy Tom Tromey
2018-10-02  4:44 ` [PATCH v2 05/10] Avoid undefined behavior in read_subrange_type Tom Tromey
2018-10-03 17:57 ` [PATCH v2 00/10] Undefined Behavior Sanitizer, this time with docs Pedro Alves
2018-10-03 21:09   ` Tom Tromey
2018-10-08 19:14 ` John Baldwin [this message]
2018-10-08 20:22   ` Joel Brobecker
2018-10-09 10:44     ` Pedro Alves
2018-10-12 21:07       ` Joel Brobecker

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=8df7a2b9-800a-5a70-1075-e687145c9394@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).