Skip to content

Commit

Permalink
fstack: Fix a heap buffer overflow
Browse files Browse the repository at this point in the history
This patch is to fix the following heap buffer overflow problem.

  $ uftrace record --force gcc hello.c
  $ uftrace replay --no-pager
      ...
  =================================================================
  ==79233==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62e00003c3e8 at
                                    pc 0x00000047e08e bp 0x7ffec89b7cd0 sp 0x7ffec89b7cc0
  READ of size 8 at 0x62e00003c3e8 thread T0
      #0 0x47e08d in fstack_check_skip /home/honggyu/uftrace/utils/fstack.c:683
      #1 0x47e9af in fstack_skip /home/honggyu/uftrace/utils/fstack.c:780
      #2 0x43e24e in print_graph_rstack /home/honggyu/uftrace/cmds/replay.c:987
      #3 0x43f49b in command_replay /home/honggyu/uftrace/cmds/replay.c:1172
      #4 0x40b7f1 in main /home/honggyu/uftrace/uftrace.c:1184
      #5 0x7f8ecb67e82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
      #6 0x405bf8 in _start (/home/honggyu/usr/bin/uftrace+0x405bf8)

  0x62e00003c3e8 is located 24 bytes to the left of 40960-byte region [0x62e00003c400,0x62e000046400)
  allocated by thread T0 here:
      #0 0x7f8eccd2e7fa in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x987fa)
      #1 0x479eca in setup_task_handle /home/honggyu/uftrace/utils/fstack.c:61
      #2 0x47b0e2 in fstack_setup_task /home/honggyu/uftrace/utils/fstack.c:211
      #3 0x47c23b in fstack_setup_filters /home/honggyu/uftrace/utils/fstack.c:443
      #4 0x43f266 in command_replay /home/honggyu/uftrace/cmds/replay.c:1144
      #5 0x40b7f1 in main /home/honggyu/uftrace/uftrace.c:1184
      #6 0x7f8ecb67e82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

  SUMMARY: AddressSanitizer: heap-buffer-overflow /home/honggyu/uftrace/utils/fstack.c:683 fstack_check_skip

Fixed: namhyung#803

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim committed Nov 28, 2019
1 parent 91c330e commit fafa557
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions utils/fstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ static int fstack_check_skip(struct uftrace_task_reader *task,
return -1;

if (rstack->type == UFTRACE_EXIT) {
if (task->stack_count < 1)
return 0;

/* fstack_consume() is not called yet */
fstack = &task->func_stack[task->stack_count - 1];

Expand Down

0 comments on commit fafa557

Please sign in to comment.