public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/27994] New: ASan crash when printing expression involving function call
@ 2021-06-18  4:17 simark at simark dot ca
  2021-06-19 12:34 ` [Bug gdb/27994] " ssbssa at sourceware dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: simark at simark dot ca @ 2021-06-18  4:17 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=27994

            Bug ID: 27994
           Summary: ASan crash when printing expression involving function
                    call
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: simark at simark dot ca
  Target Milestone: ---

I don't have a small reproducer yet, so here's a complex reproducer.  The
program to debug is a patched GDB, but the crashing GDB is from master.

Bisected to commit d182f2797922 ("Convert c-exp.y to use operations").

1) Build GDB at this commit: https://review.lttng.org/c/binutils-gdb/+/6066/12
2) Start debugging something with it
3) Build GDB at current master (7daf500de25c0e93bc70d593a7979657a2d4ceb5)
4) Debug GDB from step 1 using GDB from step 3:

$ ./gdb --data-directory=data-directory -p $(pidof gdb) -ex 'p
current_inferior_.m_obj.thread_list.m_head.next.next' -ex 'p
current_inferior_.m_obj.thread_list.as_value($1)'
<some text>
$1 = (struct intrusive_list_node<thread_info> *) 0x617000014298
=================================================================
==987643==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x6020001df7a0 at pc 0x556f22e2cd84 bp 0x7ffd64b10d90 sp 0x7ffd64b10d80
READ of size 8 at 0x6020001df7a0 thread T0
    #0 0x556f22e2cd83 in typecmp /home/smarchi/src/wt/test/gdb/valops.c:1826
    #1 0x556f22e2f7d0 in search_struct_method
/home/smarchi/src/wt/test/gdb/valops.c:2220
    #2 0x556f22e30716 in value_struct_elt(value**, value**, char const*, int*,
char const*) /home/smarchi/src/wt/test/gdb/valops.c:2379
    #3 0x556f224c546b in expr::structop_base_operation::evaluate_funcall(type*,
expression*, noside, std::vector<std::unique_ptr<expr::operation,
std::default_delete<expr::operation> >,
std::allocator<std::unique_ptr<expr::operation,
std::default_delete<expr::operation> > > > const&)
/home/smarchi/src/wt/test/gdb/eval.c:944
    #4 0x556f22107e4c in expr::funcall_operation::evaluate(type*, expression*,
noside) /home/smarchi/src/wt/test/gdb/expop.h:2178
    #5 0x556f224c01a7 in expression::evaluate(type*, noside)
/home/smarchi/src/wt/test/gdb/eval.c:101
    #6 0x556f224c02f6 in evaluate_expression(expression*, type*)
/home/smarchi/src/wt/test/gdb/eval.c:115
    #7 0x556f228e59c2 in process_print_command_args
/home/smarchi/src/wt/test/gdb/printcmd.c:1305
    #8 0x556f228e5b9a in print_command_1
/home/smarchi/src/wt/test/gdb/printcmd.c:1318
    #9 0x556f228e65c7 in print_command
/home/smarchi/src/wt/test/gdb/printcmd.c:1435
    #10 0x556f2218bc27 in do_const_cfunc
/home/smarchi/src/wt/test/gdb/cli/cli-decode.c:102
    #11 0x556f22196f80 in cmd_func(cmd_list_element*, char const*, int)
/home/smarchi/src/wt/test/gdb/cli/cli-decode.c:2176
    #12 0x556f22cc43cf in execute_command(char const*, int)
/home/smarchi/src/wt/test/gdb/top.c:674
    #13 0x556f22783288 in catch_command_errors
/home/smarchi/src/wt/test/gdb/main.c:523
    #14 0x556f227838af in execute_cmdargs
/home/smarchi/src/wt/test/gdb/main.c:618
    #15 0x556f22786a2d in captured_main_1
/home/smarchi/src/wt/test/gdb/main.c:1322
    #16 0x556f22786fc1 in captured_main
/home/smarchi/src/wt/test/gdb/main.c:1343
    #17 0x556f22787062 in gdb_main(captured_main_args*)
/home/smarchi/src/wt/test/gdb/main.c:1368
    #18 0x556f21e7eb81 in main /home/smarchi/src/wt/test/gdb/gdb.c:32
    #19 0x7f51ce3ba0b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #20 0x556f21e7e95d in _start (/home/smarchi/build/wt/test/gdb/gdb+0x42695d)

0x6020001df7a0 is located 0 bytes to the right of 16-byte region
[0x6020001df790,0x6020001df7a0)
allocated by thread T0 here:
    #0 0x7f51cf18b947 in operator new(unsigned long)
(/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10f947)
    #1 0x556f21f342dc in __gnu_cxx::new_allocator<value*>::allocate(unsigned
long, void const*) /usr/include/c++/9/ext/new_allocator.h:114
    #2 0x556f21f2ee1f in std::allocator_traits<std::allocator<value*>
>::allocate(std::allocator<value*>&, unsigned long)
/usr/include/c++/9/bits/alloc_traits.h:444
    #3 0x556f21f29c11 in std::_Vector_base<value*, std::allocator<value*>
>::_M_allocate(unsigned long) /usr/include/c++/9/bits/stl_vector.h:343
    #4 0x556f21f25736 in std::_Vector_base<value*, std::allocator<value*>
>::_M_create_storage(unsigned long) /usr/include/c++/9/bits/stl_vector.h:358
    #5 0x556f21f1fd9a in std::_Vector_base<value*, std::allocator<value*>
>::_Vector_base(unsigned long, std::allocator<value*> const&)
/usr/include/c++/9/bits/stl_vector.h:302
    #6 0x556f21f18f12 in std::vector<value*, std::allocator<value*>
>::vector(unsigned long, std::allocator<value*> const&)
/usr/include/c++/9/bits/stl_vector.h:508
    #7 0x556f224c4cac in expr::structop_base_operation::evaluate_funcall(type*,
expression*, noside, std::vector<std::unique_ptr<expr::operation,
std::default_delete<expr::operation> >,
std::allocator<std::unique_ptr<expr::operation,
std::default_delete<expr::operation> > > > const&)
/home/smarchi/src/wt/test/gdb/eval.c:875
    #8 0x556f22107e4c in expr::funcall_operation::evaluate(type*, expression*,
noside) /home/smarchi/src/wt/test/gdb/expop.h:2178
    #9 0x556f224c01a7 in expression::evaluate(type*, noside)
/home/smarchi/src/wt/test/gdb/eval.c:101
    #10 0x556f224c02f6 in evaluate_expression(expression*, type*)
/home/smarchi/src/wt/test/gdb/eval.c:115
    #11 0x556f228e59c2 in process_print_command_args
/home/smarchi/src/wt/test/gdb/printcmd.c:1305
    #12 0x556f228e5b9a in print_command_1
/home/smarchi/src/wt/test/gdb/printcmd.c:1318
    #13 0x556f228e65c7 in print_command
/home/smarchi/src/wt/test/gdb/printcmd.c:1435
    #14 0x556f2218bc27 in do_const_cfunc
/home/smarchi/src/wt/test/gdb/cli/cli-decode.c:102
    #15 0x556f22196f80 in cmd_func(cmd_list_element*, char const*, int)
/home/smarchi/src/wt/test/gdb/cli/cli-decode.c:2176
    #16 0x556f22cc43cf in execute_command(char const*, int)
/home/smarchi/src/wt/test/gdb/top.c:674
    #17 0x556f22783288 in catch_command_errors
/home/smarchi/src/wt/test/gdb/main.c:523
    #18 0x556f227838af in execute_cmdargs
/home/smarchi/src/wt/test/gdb/main.c:618
    #19 0x556f22786a2d in captured_main_1
/home/smarchi/src/wt/test/gdb/main.c:1322
    #20 0x556f22786fc1 in captured_main
/home/smarchi/src/wt/test/gdb/main.c:1343
    #21 0x556f22787062 in gdb_main(captured_main_args*)
/home/smarchi/src/wt/test/gdb/main.c:1368
    #22 0x556f21e7eb81 in main /home/smarchi/src/wt/test/gdb/gdb.c:32
    #23 0x7f51ce3ba0b2 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: heap-buffer-overflow
/home/smarchi/src/wt/test/gdb/valops.c:1826 in typecmp


I don't understand what happens yet, but here's what I found:

1) structop_base_operation::evaluate_funcall allocates vals, a vector of 2
elements
2) It calls value_struct_elt to find the "as_value" structure element passing
&vals[1] as args (args points to the vector's 2nd element)
3) It is then passed to search_struct_method and typecmd as argument `t2`.
4) typecmd accesses t2[1], which is out of bounds of the original vector (it
would be equivalent to doing vals[2]).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-06-25 19:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18  4:17 [Bug gdb/27994] New: ASan crash when printing expression involving function call simark at simark dot ca
2021-06-19 12:34 ` [Bug gdb/27994] " ssbssa at sourceware dot org
2021-06-21 16:41 ` simark at simark dot ca
2021-06-21 21:49 ` andrew.burgess at embecosm dot com
2021-06-21 22:40 ` andrew.burgess at embecosm dot com
2021-06-21 23:00 ` andrew.burgess at embecosm dot com
2021-06-21 23:40 ` andrew.burgess at embecosm dot com
2021-06-22  0:13 ` simark at simark dot ca
2021-06-22  8:29 ` andrew.burgess at embecosm dot com
2021-06-22 13:48 ` simark at simark dot ca
2021-06-25 19:51 ` cvs-commit at gcc dot gnu.org
2021-06-25 19:51 ` cvs-commit at gcc dot gnu.org
2021-06-25 19:52 ` andrew.burgess at embecosm dot com

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).