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

printf("%d %m %s\n", 10, "label") crashes asan: AddressSanitizer: SEGV on unknown address 0x00000000000a #759

Closed
evverx opened this issue Dec 24, 2016 · 1 comment

Comments

@evverx
Copy link

evverx commented Dec 24, 2016

$ rpm -q clang compiler-rt
clang-3.8.0-2.fc25.x86_64
compiler-rt-3.8.0-2.fc25.x86_64
// test-printf.c
#include <stdio.h>

int main(int argc, char *argv[]) {
        printf("%d %m %s\n", 10, "label");
}
$ clang -o test-printf -fsanitize=address ./test-printf.c
$ ./test-printf
ASAN:DEADLYSIGNAL
=================================================================
==26575==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000000a (pc 0x0000004ccbc2 bp 0x7ffda4cc17f0 sp 0x7ffda4cc0f28 T0)
    #0 0x4ccbc1  (/home/vagrant/asan-crash/test-printf+0x4ccbc1)
    #1 0x48521f  (/home/vagrant/asan-crash/test-printf+0x48521f)
    #2 0x4857ca  (/home/vagrant/asan-crash/test-printf+0x4857ca)
    #3 0x485887  (/home/vagrant/asan-crash/test-printf+0x485887)
    #4 0x4e7a93  (/home/vagrant/asan-crash/test-printf+0x4e7a93)
    #5 0x7f749d010400  (/lib64/libc.so.6+0x20400)
    #6 0x418509  (/home/vagrant/asan-crash/test-printf+0x418509)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/vagrant/asan-crash/test-printf+0x4ccbc1)
==26575==ABORTING
(gdb) thread apply all bt

Thread 1 (Thread 0x7ffff7fe4780 (LWP 26579)):
#0  0x00000000004ccbc2 in __sanitizer::internal_strlen(char const*) ()
#1  0x0000000000485220 in printf_common(void*, char const*, __va_list_tag*) ()
#2  0x00000000004857cb in vprintf ()
#3  0x0000000000485888 in printf ()
#4  0x00000000004e7a94 in main ()
evverx added a commit to evverx/systemd that referenced this issue Dec 24, 2016
"%d (%m) %s\n" crashes asan: google/sanitizers#759
So, let's place %m after %s

Fixes:
```
$ ./libtool --mode=execute ./test-selinux
...
============ test_misc ==========
ASAN:DEADLYSIGNAL
=================================================================
==2981==ERROR: AddressSanitizer: SEGV on unknown address 0x000041b58ab3 (pc 0x7fd9c55a0eb2 bp 0x7fffdc2f9640 sp 0x7fffdc2f8d68 T0)
    #0 0x7fd9c55a0eb1  (/lib64/libasan.so.3+0xdeeb1)
    #1 0x7fd9c5550bbf  (/lib64/libasan.so.3+0x8ebbf)
    #2 0x7fd9c5552cdd in __interceptor_vsnprintf (/lib64/libasan.so.3+0x90cdd)
    #3 0x7fd9c5063715 in log_internalv src/basic/log.c:680
    #4 0x7fd9c506390a in log_internal src/basic/log.c:697
    #5 0x561d398181a2 in test_misc src/test/test-selinux.c:81
    #6 0x561d398185e8 in main src/test/test-selinux.c:117
    #7 0x7fd9c493a400 in __libc_start_main (/lib64/libc.so.6+0x20400)
    #8 0x561d39817859 in _start (/home/vagrant/systemd-asan/.libs/lt-test-selinux+0x1859)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libasan.so.3+0xdeeb1)
==2981==ABORTING
```
poettering pushed a commit to systemd/systemd that referenced this issue Dec 25, 2016
"%d (%m) %s\n" crashes asan: google/sanitizers#759
So, let's place %m after %s

Fixes:
```
$ ./libtool --mode=execute ./test-selinux
...
============ test_misc ==========
ASAN:DEADLYSIGNAL
=================================================================
==2981==ERROR: AddressSanitizer: SEGV on unknown address 0x000041b58ab3 (pc 0x7fd9c55a0eb2 bp 0x7fffdc2f9640 sp 0x7fffdc2f8d68 T0)
    #0 0x7fd9c55a0eb1  (/lib64/libasan.so.3+0xdeeb1)
    #1 0x7fd9c5550bbf  (/lib64/libasan.so.3+0x8ebbf)
    #2 0x7fd9c5552cdd in __interceptor_vsnprintf (/lib64/libasan.so.3+0x90cdd)
    #3 0x7fd9c5063715 in log_internalv src/basic/log.c:680
    #4 0x7fd9c506390a in log_internal src/basic/log.c:697
    #5 0x561d398181a2 in test_misc src/test/test-selinux.c:81
    #6 0x561d398185e8 in main src/test/test-selinux.c:117
    #7 0x7fd9c493a400 in __libc_start_main (/lib64/libc.so.6+0x20400)
    #8 0x561d39817859 in _start (/home/vagrant/systemd-asan/.libs/lt-test-selinux+0x1859)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libasan.so.3+0xdeeb1)
==2981==ABORTING
```
@eugenis
Copy link
Contributor

eugenis commented Dec 27, 2016

Thanks for the report!
Fixed in https://reviews.llvm.org/rL290632

@eugenis eugenis closed this as completed Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants