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

Use ASAN without proc access in system init process #1358

Open
hauke opened this issue Dec 15, 2020 · 4 comments
Open

Use ASAN without proc access in system init process #1358

hauke opened this issue Dec 15, 2020 · 4 comments

Comments

@hauke
Copy link

hauke commented Dec 15, 2020

I want to activate ASAN and also other sanitizers for the complete OpenWrt user space. It is pretty easy to compile the complete user space with ASAN activated, but I have a problem with the init daemon.

The init process is started by the kernel and takes care of mounting /proc /sys and other things. When the process itself is compiled with ASAN, ASAN tries to access /proc before the application is started and mounted it, this fails, the init daemon fails and the kernel panics.

I could try to statically link and not activate ASAN for the init process or try to load different shared libraries which are not instrumented with ASAN.

Is there a better approach? I do not need ASAN support for the init process, if I can use ASAN with the rest it would be fine for me.
Currently it loads multiple shared libraries which I would like to instrument when they are used with other processes.

Is it possible to build some stump for ASAN which just forwards the function calls to the normal glibc and does nothing else?

I am using x86_64 with Linux 5.4, GCC 8.4 (will update to 10.2 today), glibc 2.32 and binutils 2.34.

I am getting this error message:

....
[    1.793298] Write protecting the kernel read-only data: 18432k
[    1.803971] Freeing unused kernel image memory: 2016K
[    1.809863] Freeing unused kernel image memory: 1220K
[    1.814077] Run /sbin/init as init process
[    1.885330] tsc: Refined TSC clocksource calibration: 1800.006 MHz
[    1.889233] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x19f22f68897, max_idle_ns: 440795282550 ns
[    1.900140] clocksource: Switched to clocksource tsc
==1==WARNING: reading executable name failed with errno 2, some stack frames may not be symbolized
==1==WARNING: reading executable name failed with errno 2, some stack frames may not be symbolized
==1==AddressSanitizer: failed to intercept '__isoc99_printf'
==1==AddressSanitizer: failed to intercept '__isoc99_sprintf'
==1==AddressSanitizer: failed to intercept '__isoc99_snprintf'
==1==AddressSanitizer: failed to intercept '__isoc99_fprintf'
==1==AddressSanitizer: failed to intercept '__isoc99_vprintf'
==1==AddressSanitizer: failed to intercept '__isoc99_vsprintf'
==1==AddressSanitizer: failed to intercept '__isoc99_vsnprintf'
==1==AddressSanitizer: failed to intercept '__isoc99_vfprintf'
[    1.958722] random: fast init done
==1==AddressSanitizer: failed to intercept 'xdr_quad_t'
==1==AddressSanitizer: failed to intercept 'xdr_u_quad_t'
==1==AddressSanitizer: libc interceptors initialized
==1==AddressSanitizer CHECK failed: /home/hauke/openwrt/openwrt/build_dir/toolchain-x86_64_gcc-8.4.0_glibc/gcc-8.4.0/libsanitizer/sanitizer_common/sanitizer_procmaps_common.cc:75 "((data_.proc_self_maps
.len)) > ((0))" (0x0, 0x0)
    <empty stack>

[    1.981225] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100
[    1.985470] Kernel Offset: disabled
[    1.989352] Rebooting in 5 seconds..
[    7.019703] ACPI MEMORY or I/O RESET_REG.
....

Hauke

@hauke
Copy link
Author

hauke commented Dec 15, 2020

It looks like it is working with GCC 10.2:

[    1.658330] Freeing unused kernel image memory: 2016K
[    1.662738] Freeing unused kernel image memory: 1248K
[    1.666034] Run /sbin/init as init process
==1==WARNING: reading executable name failed with errno 2, some stack frames may not be symbolized
==1==WARNING: reading executable name failed with errno 2, some stack frames may not be symbolized
==1==AddressSanitizer: failed to intercept '__isoc99_printf'
'==1==AddressSanitizer: failed to intercept '__isoc99_sprintf'
'==1==AddressSanitizer: failed to intercept '__isoc99_snprintf'
'==1==AddressSanitizer: failed to intercept '__isoc99_fprintf'
'==1==AddressSanitizer: failed to intercept '__isoc99_vprintf'
'==1==AddressSanitizer: failed to intercept '__isoc99_vsprintf'
'==1==AddressSanitizer: failed to intercept '__isoc99_vsnprintf'
'==1==AddressSanitizer: failed to intercept '__isoc99_vfprintf'
'==1==AddressSanitizer: failed to intercept 'xdr_quad_t'
[    1.787564] random: fast init done
'==1==AddressSanitizer: failed to intercept 'xdr_u_quad_t'
'==1==AddressSanitizer: failed to intercept 'crypt'
'==1==AddressSanitizer: failed to intercept 'crypt_r'
'==1==AddressSanitizer: libc interceptors initialized
|| `[0x10007fff8000, 0x7fffffffffff]` || HighMem    ||
|| `[0x02008fff7000, 0x10007fff7fff]` || HighShadow ||
|| `[0x00008fff7000, 0x02008fff6fff]` || ShadowGap  ||
|| `[0x00007fff8000, 0x00008fff6fff]` || LowShadow  ||
|| `[0x000000000000, 0x00007fff7fff]` || LowMem     ||
MemToShadow(shadow): 0x00008fff7000 0x000091ff6dff 0x004091ff6e00 0x02008fff6fff
redzone=16
max_redzone=2048
quarantine_size_mb=256M
thread_local_quarantine_size_kb=1024K
malloc_context_size=30
SHADOW_SCALE: 3
SHADOW_GRANULARITY: 8
SHADOW_OFFSET: 0x7fff8000
==1==Installed the sigaction for signal 11
==1==Installed the sigaction for signal 7
==1==Installed the sigaction for signal 8
==1==T0: stack [0x000000000000,0x000000000000) size 0x0; local=0x7fff6c8cb0ec
==1==AddressSanitizer Init done
[    1.877074] tsc: Refined TSC clocksource calibration: 1799.999 MHz
[    1.884175] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x19f228ab7a2, max_idle_ns: 440795289252 ns
[    1.917634] clocksource: Switched to clocksource tsc
[    1.932398] init: Console is alive
....

I think this fixed the problem: google/llvm-propeller@15b71ea

@eugenis
Copy link
Contributor

eugenis commented Dec 15, 2020 via email

@manscrober
Copy link

@eugenis Do you know if this will also successfully sanitize /init without affecting any features? i.e. does not having /proc/ access initially break anything further down the line? Does ASan strictly need /proc/ access to work without issues, and if so does it automatically start working once /proc/ is available/mounted?

@eugenis
Copy link
Contributor

eugenis commented Jun 23, 2021 via email

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

3 participants