palves at redhat dot com
2018-10-07 16:45:51 UTC
https://sourceware.org/bugzilla/show_bug.cgi?id=23743
Bug ID: 23743
Summary: GDB index file mmapping broken, ubsan => runtime
error: load of misaligned address
Product: gdb
Version: unknown
Status: NEW
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: palves at redhat dot com
Target Milestone: ---
UBSAN-by-default is now tripping on a bug that was latent on x86 and other
archs that can do unaligned loads.
Debugging today's (8.2.50.20181007-git) GDB under itself I'm seeing this:
(top-gdb) start
Temporary breakpoint 3 at 0x464926: main. (24 locations)
Starting program: build/gdb/gdb
....
src/gdb/dwarf2read.c:3443:15: runtime error: load of misaligned address
0x7f8beafcc5f7 for type 'offset_type', which requires 4 byte alignment
0x7f8beafcc5f7: note: pointer points here
00 00 00 00 08 00 00 00 18 00 00 00 98 09 00 00 98 09 00 00 1c 12 00 00 1c
52 00 00 00 00 00 00
^
The code in question is this:
/* Version check. */
offset_type version = MAYBE_SWAP (*(offset_type *) addr);
'addr' above is a pointer to the start of the .gdb_index section, which
contains a v8 index:
(top-gdb) p addr
$1 = (const gdb_byte *) 0x7ffff7fc45f7 "\b"
(top-gdb) x/4b addr
0x7ffff7fc45f7: 8 0 0 0
The problem is that the gdb index reading code throughout is assuming that the
section contents buffer starts at a sufficiently aligned address. That is
evident from the fact that MAYBE_SWAP takes an offset_type as argument.
But, in this case the buffer's start isn't aligned, because the buffer wasn't
heap-allocated -- instead the section was mmapped in place with
gdb_bfd_map_section, and the .gdb_index section at an unaligned address in the
file. From objdump -h:
31 .gdb_index 00007bd8 0000000000000000 0000000000000000 000955f7 2**0
CONTENTS, READONLY, DEBUGGING
^^^^^^^^
The mmapping is here:
(top-gdb) bt
#0 0x00000000009418a0 in gdb_bfd_map_section(bfd_section*, unsigned long*)
(sectp=0x5a1e7a0, size=0x59f9820)
at ....src/gdb/gdb_bfd.c:682
#1 0x0000000000817b64 in dwarf2_read_section(objfile*, dwarf2_section_info*)
(objfile=0x381f630, info=0x59f9810)
at ....src/gdb/dwarf2read.c:2508
#2 0x000000000082dc86 in
get_gdb_index_contents_from_section<dwarf2_per_objfile>(objfile*,
dwarf2_per_objfile*) (obj=0x381f630, section_owner=0x59f95e0) at
....src/gdb/dwarf2read.c:6188
#3 0x00000000008b5a6f in void gdb::function_view<gdb::array_view<unsigned char
const> (objfile*, dwarf2_per_objfile*)>::bind<gdb::array_view<unsigned char
const>, objfile*, dwarf2_per_objfile*>(gdb::array_view<unsigned char const>
(*)(objfile*, dwarf2_per_objfile*))::{lambda(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*)#1}::operator()(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*) const (__closure=0x0, ecall=...,
args#0=0x381f630, args#1=0x59f95e0) at ....src/gdb/common/function-view.h:284
#4 0x00000000008b5aa3 in void gdb::function_view<gdb::array_view<unsigned char
const> (objfile*, dwarf2_per_objfile*)>::bind<gdb::array_view<unsigned char
const>, objfile*, dwarf2_per_objfile*>(gdb::array_view<unsigned char const>
(*)(objfile*, dwarf2_per_objfile*))::{lambda(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*)#1}::_FUN(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*) () at ....src/gdb/common/function-view.h:278
#5 0x00000000008a727b in gdb::function_view<gdb::array_view<unsigned char
const> (objfile*, dwarf2_per_objfile*)>::operator()(objfile*,
dwarf2_per_objfile*) const (this=0x7fffffffc760, args#0=0x381f630,
args#1=0x59f95e0) at ....src/gdb/common/function-view.h:247
During symbol reading, cannot get low and high bounds for subprogram DIE at
16490919.
#6 0x000000000081d752 in dwarf2_read_gdb_index(dwarf2_per_objfile*,
get_gdb_index_contents_ftype, get_gdb_index_contents_dwz_ftype)
(dwarf2_per_objfile=0x59f95e0, get_gdb_index_contents=...,
get_gdb_index_contents_dwz=...) at ....src/gdb/dwarf2read.c:3553
#7 0x000000000082e139 in dwarf2_initialize_objfile(objfile*, dw_index_kind*)
(objfile=0x381f630, index_kind=0x7fffffffc994)
at ....src/gdb/dwarf2read.c:6262
#8 0x00000000008e9540 in elf_symfile_read(objfile*, symfile_add_flags)
(objfile=0x381f630, symfile_flags=...)
at ....src/gdb/elfread.c:1255
#9 0x0000000000dca21d in read_symbols(objfile*, symfile_add_flags)
(objfile=0x381f630, add_flags=...)
at ....src/gdb/symfile.c:794
The objfile in question is
/usr/lib/debug/usr/lib64/libncursesw.so.6.0-6.0-14.20170722.fc27.x86_64.debug
on Fedora 27.
Bug ID: 23743
Summary: GDB index file mmapping broken, ubsan => runtime
error: load of misaligned address
Product: gdb
Version: unknown
Status: NEW
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: palves at redhat dot com
Target Milestone: ---
UBSAN-by-default is now tripping on a bug that was latent on x86 and other
archs that can do unaligned loads.
Debugging today's (8.2.50.20181007-git) GDB under itself I'm seeing this:
(top-gdb) start
Temporary breakpoint 3 at 0x464926: main. (24 locations)
Starting program: build/gdb/gdb
....
src/gdb/dwarf2read.c:3443:15: runtime error: load of misaligned address
0x7f8beafcc5f7 for type 'offset_type', which requires 4 byte alignment
0x7f8beafcc5f7: note: pointer points here
00 00 00 00 08 00 00 00 18 00 00 00 98 09 00 00 98 09 00 00 1c 12 00 00 1c
52 00 00 00 00 00 00
^
The code in question is this:
/* Version check. */
offset_type version = MAYBE_SWAP (*(offset_type *) addr);
'addr' above is a pointer to the start of the .gdb_index section, which
contains a v8 index:
(top-gdb) p addr
$1 = (const gdb_byte *) 0x7ffff7fc45f7 "\b"
(top-gdb) x/4b addr
0x7ffff7fc45f7: 8 0 0 0
The problem is that the gdb index reading code throughout is assuming that the
section contents buffer starts at a sufficiently aligned address. That is
evident from the fact that MAYBE_SWAP takes an offset_type as argument.
But, in this case the buffer's start isn't aligned, because the buffer wasn't
heap-allocated -- instead the section was mmapped in place with
gdb_bfd_map_section, and the .gdb_index section at an unaligned address in the
file. From objdump -h:
31 .gdb_index 00007bd8 0000000000000000 0000000000000000 000955f7 2**0
CONTENTS, READONLY, DEBUGGING
^^^^^^^^
The mmapping is here:
(top-gdb) bt
#0 0x00000000009418a0 in gdb_bfd_map_section(bfd_section*, unsigned long*)
(sectp=0x5a1e7a0, size=0x59f9820)
at ....src/gdb/gdb_bfd.c:682
#1 0x0000000000817b64 in dwarf2_read_section(objfile*, dwarf2_section_info*)
(objfile=0x381f630, info=0x59f9810)
at ....src/gdb/dwarf2read.c:2508
#2 0x000000000082dc86 in
get_gdb_index_contents_from_section<dwarf2_per_objfile>(objfile*,
dwarf2_per_objfile*) (obj=0x381f630, section_owner=0x59f95e0) at
....src/gdb/dwarf2read.c:6188
#3 0x00000000008b5a6f in void gdb::function_view<gdb::array_view<unsigned char
const> (objfile*, dwarf2_per_objfile*)>::bind<gdb::array_view<unsigned char
const>, objfile*, dwarf2_per_objfile*>(gdb::array_view<unsigned char const>
(*)(objfile*, dwarf2_per_objfile*))::{lambda(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*)#1}::operator()(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*) const (__closure=0x0, ecall=...,
args#0=0x381f630, args#1=0x59f95e0) at ....src/gdb/common/function-view.h:284
#4 0x00000000008b5aa3 in void gdb::function_view<gdb::array_view<unsigned char
const> (objfile*, dwarf2_per_objfile*)>::bind<gdb::array_view<unsigned char
const>, objfile*, dwarf2_per_objfile*>(gdb::array_view<unsigned char const>
(*)(objfile*, dwarf2_per_objfile*))::{lambda(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*)#1}::_FUN(gdb::fv_detail::erased_callable,
objfile*, dwarf2_per_objfile*) () at ....src/gdb/common/function-view.h:278
#5 0x00000000008a727b in gdb::function_view<gdb::array_view<unsigned char
const> (objfile*, dwarf2_per_objfile*)>::operator()(objfile*,
dwarf2_per_objfile*) const (this=0x7fffffffc760, args#0=0x381f630,
args#1=0x59f95e0) at ....src/gdb/common/function-view.h:247
During symbol reading, cannot get low and high bounds for subprogram DIE at
16490919.
#6 0x000000000081d752 in dwarf2_read_gdb_index(dwarf2_per_objfile*,
get_gdb_index_contents_ftype, get_gdb_index_contents_dwz_ftype)
(dwarf2_per_objfile=0x59f95e0, get_gdb_index_contents=...,
get_gdb_index_contents_dwz=...) at ....src/gdb/dwarf2read.c:3553
#7 0x000000000082e139 in dwarf2_initialize_objfile(objfile*, dw_index_kind*)
(objfile=0x381f630, index_kind=0x7fffffffc994)
at ....src/gdb/dwarf2read.c:6262
#8 0x00000000008e9540 in elf_symfile_read(objfile*, symfile_add_flags)
(objfile=0x381f630, symfile_flags=...)
at ....src/gdb/elfread.c:1255
#9 0x0000000000dca21d in read_symbols(objfile*, symfile_add_flags)
(objfile=0x381f630, add_flags=...)
at ....src/gdb/symfile.c:794
The objfile in question is
/usr/lib/debug/usr/lib64/libncursesw.so.6.0-6.0-14.20170722.fc27.x86_64.debug
on Fedora 27.
--
You are receiving this mail because:
You are on the CC list for the bug.
You are receiving this mail because:
You are on the CC list for the bug.