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

-Zsanitizer=address failing to catch SIGSEGV #69524

Closed
jsgf opened this issue Feb 27, 2020 · 2 comments · Fixed by #69685
Closed

-Zsanitizer=address failing to catch SIGSEGV #69524

jsgf opened this issue Feb 27, 2020 · 2 comments · Fixed by #69685
Labels
A-sanitizers Area: Sanitizers for correctness and code quality. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jsgf
Copy link
Contributor

jsgf commented Feb 27, 2020

I tried this code:

use std::ffi::c_void;

extern "C" {
    fn free(ptr: *mut c_void);
}

fn main() {
    unsafe {
        free(1 as *mut c_void);
    }
}

and compiled it with:

rustc +nightly -Zsanitizer=address --crate-type bin badfree.rs

I expected to see asan report a bad pointer use and give a backtrace.

Instead I just got a raw sigsegv:

$ ./badfree
Segmentation fault (core dumped)

Running with verbose output shows that AddressSanitizer is intercepting the signal.

$ ASAN_OPTIONS=verbosity=2 ./badfree
==1750324==AddressSanitizer: failed to intercept '__isoc99_printf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_sprintf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_snprintf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_fprintf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_vprintf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_vsprintf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_vsnprintf'
'==1750324==AddressSanitizer: failed to intercept '__isoc99_vfprintf'
'==1750324==AddressSanitizer: failed to intercept '__cxa_throw'
'==1750324==AddressSanitizer: failed to intercept '__cxa_rethrow_primary_exception'
'==1750324==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
==1750324==Installed the sigaction for signal 11
==1750324==Installed the sigaction for signal 7
==1750324==Installed the sigaction for signal 8
==1750324==SetCurrentThread: 0x7f3589309000 for thread 0x7f3589301840
==1750324==T0: stack [0x7ffe17920000,0x7ffe18120000) size 0x800000; local=0x7ffe1811e334
==1750324==AddressSanitizer Init done
Segmentation fault (core dumped)

It looks like src/libstd/sys/unix/stack_overflow.rs init() is also installing a signal handler, which is overriding the AddressSanitizer one.

Meta

rustc --version --verbose:

rustc 1.43.0-nightly (abc3073c9 2020-02-26)
binary: rustc
commit-hash: abc3073c92df034636a823c5382ece2186d22b9e
commit-date: 2020-02-26
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

@jsgf jsgf added the C-bug Category: This is a bug. label Feb 27, 2020
@jonas-schievink jonas-schievink added A-sanitizers Area: Sanitizers for correctness and code quality. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 27, 2020
@jsgf
Copy link
Contributor Author

jsgf commented Feb 27, 2020

ASAN_OPTIONS=handle_segv=2 (set handler and prevent override) is a workaround, but I think the Rust runtime shouldn't stomp SIGSEGV in the sanitizer case.

@nagisa
Copy link
Member

nagisa commented Feb 28, 2020

cc #66809 (comment)

Centril added a commit to Centril/rust that referenced this issue Mar 8, 2020
unix: Don't override existing SIGSEGV/BUS handlers

Although `stack_overflow::init` runs very early in the process, even
before `main`, there may already be signal handlers installed for things
like the address sanitizer. In that case, just leave it alone, and don't
bother trying to allocate our own signal stacks either.

Fixes rust-lang#69524.
Centril added a commit to Centril/rust that referenced this issue Mar 9, 2020
unix: Don't override existing SIGSEGV/BUS handlers

Although `stack_overflow::init` runs very early in the process, even
before `main`, there may already be signal handlers installed for things
like the address sanitizer. In that case, just leave it alone, and don't
bother trying to allocate our own signal stacks either.

Fixes rust-lang#69524.
Centril added a commit to Centril/rust that referenced this issue Mar 9, 2020
unix: Don't override existing SIGSEGV/BUS handlers

Although `stack_overflow::init` runs very early in the process, even
before `main`, there may already be signal handlers installed for things
like the address sanitizer. In that case, just leave it alone, and don't
bother trying to allocate our own signal stacks either.

Fixes rust-lang#69524.
Centril added a commit to Centril/rust that referenced this issue Mar 9, 2020
unix: Don't override existing SIGSEGV/BUS handlers

Although `stack_overflow::init` runs very early in the process, even
before `main`, there may already be signal handlers installed for things
like the address sanitizer. In that case, just leave it alone, and don't
bother trying to allocate our own signal stacks either.

Fixes rust-lang#69524.
@bors bors closed this as completed in eaf6905 Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sanitizers Area: Sanitizers for correctness and code quality. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants