[PATCH v2 00/10] Undefined Behavior Sanitizer, this time with docs

John Baldwin jhb@FreeBSD.org
Mon Oct 8 19:14:00 GMT 2018


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

                                                                            



More information about the Gdb-patches mailing list