Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] use-after-free and data races and more #1042

Open
ItsMeSamey opened this issue Feb 19, 2025 · 3 comments
Open

[BUG] use-after-free and data races and more #1042

ItsMeSamey opened this issue Feb 19, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@ItsMeSamey
Copy link

Describe the bug
trying to investigate what causes #1012, i stumbled upon this

btop crashes on startup, dumping the following info

=================================================================
==1876597==ERROR: AddressSanitizer: heap-use-after-free on address 0x52d0000e6473 at pc 0x73835206cbd0 bp 0x7fffbd1a8280 sp 0x7fffbd1a79f8
READ of size 11 at 0x52d0000e6473 thread T0
    #0 0x73835206cbcf in printf_common /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:563
    #1 0x738352086d6e in vsnprintf /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1652
    #2 0x738352089139 in snprintf /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1723
    #3 0x62576d9d4640 in find_intel_gpu_dir (/home/a/Downloads/btop-1.4.0/bin/btop+0x141640) (BuildId: bf958397f3aa09f16b08bbff90b0d8b1961772cd)
    #4 0x62576d97c365 in Gpu::Intel::init() src/linux/btop_collect.cpp:1604
    #5 0x62576d97c365 in Shared::init() src/linux/btop_collect.cpp:300
    #6 0x62576d8c6753 in main src/btop.cpp:1071
    #7 0x738351a35487  (/usr/lib/libc.so.6+0x27487) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #8 0x738351a3554b in __libc_start_main (/usr/lib/libc.so.6+0x2754b) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #9 0x62576d8d8ae4 in _start (/home/a/Downloads/btop-1.4.0/bin/btop+0x45ae4) (BuildId: bf958397f3aa09f16b08bbff90b0d8b1961772cd)

0x52d0000e6473 is located 115 bytes inside of 32816-byte region [0x52d0000e6400,0x52d0000ee430)
freed by thread T0 here:
    #0 0x7383520fc102 in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:52
    #1 0x738351af1349 in closedir (/usr/lib/libc.so.6+0xe3349) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #2 0x62576d9d4605 in find_intel_gpu_dir (/home/a/Downloads/btop-1.4.0/bin/btop+0x141605) (BuildId: bf958397f3aa09f16b08bbff90b0d8b1961772cd)
    #3 0x62576d97c365 in Gpu::Intel::init() src/linux/btop_collect.cpp:1604
    #4 0x62576d97c365 in Shared::init() src/linux/btop_collect.cpp:300

previously allocated by thread T0 here:
    #0 0x7383520fd721 in malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x738351af1555  (/usr/lib/libc.so.6+0xe3555) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #2 0x738351af15d8  (/usr/lib/libc.so.6+0xe35d8) (BuildId: 0b707b217b15b106c25fe51df3724b25848310c0)
    #3 0x62576d9d44cd in find_intel_gpu_dir (/home/a/Downloads/btop-1.4.0/bin/btop+0x1414cd) (BuildId: bf958397f3aa09f16b08bbff90b0d8b1961772cd)
    #4 0x62576d97c365 in Gpu::Intel::init() src/linux/btop_collect.cpp:1604
    #5 0x62576d97c365 in Shared::init() src/linux/btop_collect.cpp:300

SUMMARY: AddressSanitizer: heap-use-after-free /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:563 in printf_common
Shadow bytes around the buggy address:
  0x52d0000e6180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x52d0000e6200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x52d0000e6280: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x52d0000e6300: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x52d0000e6380: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x52d0000e6400: fd fd fd fd fd fd fd fd fd fd fd fd fd fd[fd]fd
  0x52d0000e6480: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x52d0000e6500: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x52d0000e6580: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x52d0000e6600: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x52d0000e6680: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==1876597==ABORTING

To Reproduce

download sources of btop-1.4.0 form releases page
compile with CXXFLAGS='-g -O0 -ggdb -fsanitize=address' LDFLAGS='-lasan' make
run with ./bin/btop 2>&1 > cat
2>&1 > cat is there just so that the terminal remains usable after crash, same output is given with ./bin/btop

Expected behavior

btop starts up normally

Info (please complete the following information):

  • btop++ version: btop version: 1.4.0+4422277
  • Binary: self compiled using CXXFLAGS='-g -O0 -ggdb -fsanitize=address' LDFLAGS='-lasan' make
  • Architecture: x86_64
  • Platform: Linux
  • (Linux) Kernel: 6.13.2-zen1-1-zen
  • Terminal used: `ghostty
@ItsMeSamey ItsMeSamey added the bug Something isn't working label Feb 19, 2025
@ItsMeSamey
Copy link
Author

ItsMeSamey commented Feb 19, 2025

This issue is specific to intel gpu support, after compiling without gpu_support, there are no errors

@ItsMeSamey
Copy link
Author

ItsMeSamey commented Feb 19, 2025

i also found a some data races when running with tsan tsan.zip, these were in non-gpu_support version

@ItsMeSamey ItsMeSamey changed the title [BUG] btop crashes due to use-after-free on startup with asan [BUG] use-after-free and data races Feb 19, 2025
@ItsMeSamey
Copy link
Author

ItsMeSamey commented Feb 19, 2025

ok, btop might be a bit more broken than i hoped, here is another crash (use-after-return) on startup (without gpu support again)
build command CXXFLAGS='-g -O0 -ggdb -fsanitize=address,leak,undefined -fno-omit-frame-pointer' LDFLAGS='-fsanitize=address,leak,undefined' make
run command ASAN_OPTIONS="log_path=asan_output.log" ./bin/btop
asan_output.log

@ItsMeSamey ItsMeSamey changed the title [BUG] use-after-free and data races [BUG] use-after-free and data races and more Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants