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

Memory sanitizer : false positive regression in nightly-2023-01-18 #107149

Closed
catenacyber opened this issue Jan 21, 2023 · 11 comments
Closed

Memory sanitizer : false positive regression in nightly-2023-01-18 #107149

catenacyber opened this issue Jan 21, 2023 · 11 comments
Labels
A-sanitizers Area: Sanitizers for correctness and code quality C-bug Category: This is a bug. P-high High priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@catenacyber
Copy link

catenacyber commented Jan 21, 2023

Code

This comes from oss-fuzz cf https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55286&q=label%3AProj-suricata

This is with RUSTFLAGS='--cfg fuzzing -Zsanitizer=memory -Cdebuginfo=1 -Cforce-frame-pointers -Zsanitizer-memory-track-origins'

It happens with C code calling a rust function which returns std::ptr::null_mut(), and then C code checks the pointer for NULL

Basically, it reports use of uninitialized value at
https://github.com/OISF/suricata/blob/a24d7dc45c818054f97448ce42ca9ba270b3b8e4/src/detect-dce-iface.c#L151

    void *did = rs_dcerpc_iface_parse(arg);
    if (did == NULL) {

And rs_dcerpc_iface_parse is returning std::ptr::null_mut()
cf https://github.com/OISF/suricata/blob/a24d7dc45c818054f97448ce42ca9ba270b3b8e4/rust/src/dcerpc/detect.rs#L243

I expected to see this happen: no report from Memory sanitizer

Instead, this happened:

==13==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0xe25448 in DetectDceIfaceSetup /src/suricata/src/detect-dce-iface.c:151:9

Version it worked on

It most recently worked on: nightly-2023-01-17

Version with regression

rustc --version --verbose:

Sorry it is nightly-2023-01-18

rustc --version --verbose
rustc 1.68.0-nightly (3984bc583 2023-01-17)
binary: rustc
commit-hash: 3984bc5833db8bfb0acc522c9775383e4171f3de
commit-date: 2023-01-17
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
@catenacyber catenacyber added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jan 21, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 21, 2023
@catenacyber
Copy link
Author

And it worked on rustup default nightly-2023-01-17

rustc 1.68.0-nightly (4781233a7 2023-01-16)
binary: rustc
commit-hash: 4781233a77e879e49cb5ce3c98d2abba6a6ade7a
commit-date: 2023-01-16
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
``

@tmiasko
Copy link
Contributor

tmiasko commented Jan 21, 2023

That looks like noundef mismatch between C and Rust on return value due to #106294. Building Rust with -Cllvm-args=-msan-eager-checks=0 might help (and -fnosanitize-memory-param-retval in clang), but ultimately this probably requires clang with llvm/llvm-project@166c8cc.

@Noratrieb Noratrieb added the A-sanitizers Area: Sanitizers for correctness and code quality label Jan 21, 2023
catenacyber added a commit to catenacyber/oss-fuzz that referenced this issue Jan 21, 2023
Rust MSAN produces false positives when C clang version is not
up to the latest version.
See rust-lang/rust#107149
@catenacyber
Copy link
Author

Thank you very much @tmiasko
-Cllvm-args=-msan-eager-checks=0 does the trick cf google/oss-fuzz#9478

C is compiled with

clang version 15.0.0 (https://github.com/llvm/llvm-project.git bf7f8d6fa6f460bf0a16ffec319cd71592216bf4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

DavidKorczynski pushed a commit to google/oss-fuzz that referenced this issue Jan 21, 2023
Rust MSAN produces false positives when C clang version is not up to the
latest version.
See rust-lang/rust#107149

Will fix
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55239&q=label%3AProj-suricata
and such

Should the fix be generic for other projects ?
@elichai
Copy link
Contributor

elichai commented Jan 22, 2023

We encountered this in: rust-bitcoin/rust-secp256k1#573

And was just about to open an issue with this Minimal Reproducible Example: (a few lines of code) https://github.com/elichai/msan_c_rust_bug

but it sounds like this is a bug coming from mismatching llvm definitions?

tcharding added a commit to tcharding/rust-secp256k1 that referenced this issue Jan 22, 2023
The Memory Sanitizer is giving a false positive at the moment in
`nightly`. Adding compiler flags resolves the issue. I didn't grok the
exact root cause but this fixes it (cut'n'pasta from the issue [0]).

[0] rust-lang/rust#107149
tcharding added a commit to tcharding/rust-secp256k1 that referenced this issue Jan 22, 2023
The Memory Sanitizer is giving a false positive at the moment in
`nightly`. Adding compiler flags resolves the issue. I didn't grok the
exact root cause but this fixes it (cut'n'pasta from the issue [0]).

[0] rust-lang/rust#107149
tcharding added a commit to tcharding/rust-secp256k1 that referenced this issue Jan 22, 2023
The Memory Sanitizer is giving a false positive at the moment in
`nightly`. Adding compiler flags resolves the issue. I didn't grok the
exact root cause but this fixes it (cut'n'pasta from the issue [0]).

[0] rust-lang/rust#107149
apoelstra added a commit to rust-bitcoin/rust-secp256k1 that referenced this issue Jan 23, 2023
5a3f13e Overcome ASAN false positive regression (Tobin C. Harding)

Pull request description:

  The Memory Sanitizer is giving a false positive at the moment in `nightly`. Adding compiler flags resolves the issue. I didn't grok the exact root cause but this fixes it (cut'n'pasta from the issue [0]).

  Props to elichai for working this out: #573 (comment)

  [0] rust-lang/rust#107149

ACKs for top commit:
  apoelstra:
    ACK 5a3f13e

Tree-SHA512: 873145b732f7574c93ecc1bbabd9d82a1e501a39d1e2184770f71a07ffb72468783ab1b3fbfef8ef377c7e7a4b8c45253da1fce11660152d3369902136f1c049
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 25, 2023
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 25, 2023
@RalfJung
Copy link
Member

RalfJung commented Jan 27, 2023

Having noundef on the definition but not the declaration (or vice versa) should be totally fine if the return value is indeed always noundef. So I am surprised that the sanitizer complains here, how would the presence of the attribute (without a change in behavior) make any difference?

eamonnmcmanus pushed a commit to eamonnmcmanus/oss-fuzz that referenced this issue Mar 15, 2023
Rust MSAN produces false positives when C clang version is not up to the
latest version.
See rust-lang/rust#107149

Will fix
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55239&q=label%3AProj-suricata
and such

Should the fix be generic for other projects ?
@catenacyber
Copy link
Author

Looks like there was another regression between rustc 1.70.0-nightly (8be3c2bda 2023-03-24) and rustc 1.70.0-nightly (0c61c7a97 2023-03-25)
I now see

/usr/bin/ld: ../rust/target/x86_64-unknown-linux-gnu/release/libsuricata_rust.a(suricata-47b7dd5053e4a0cf.suricata.f4469a01-cgu.1.rcgu.o): in function `<(FnA,FnB,FnC) as nom::sequence::Tuple<Input,(A,B,C),Error>>::parse':
 /rust/registry/src/index.crates.io-6f17d22bba15001f/nom-7.1.3/src/sequence/mod.rs:227: undefined reference to `__msan_set_alloca_origin_with_descr'

Is this the same issue or another one ?

@tmiasko
Copy link
Contributor

tmiasko commented Mar 31, 2023

Mismatch in LLVM version between clang and rustc? Rust was upgraded to LLVM 16 in #109474. Also, clang 16 enabled sanitize-memory-param-retval, which matches rustc defaults now.

@catenacyber
Copy link
Author

Thanks @tmiasko :-)

DavidKorczynski pushed a commit to google/oss-fuzz that referenced this issue Apr 4, 2023
@pnkfelix
Copy link
Member

Having noundef on the definition but not the declaration (or vice versa) should be totally fine if the return value is indeed always noundef. So I am surprised that the sanitizer complains here, how would the presence of the attribute (without a change in behavior) make any difference?

Do any of the other participants have a response to @RalfJung 's point here? It definitely seems odd.

@wesleywiser
Copy link
Member

If I'm reading this issue correctly, we have a msan instrumented C program compiled with clang 15 and a msan instrumented Rust binary compiled with Rust/LLVM 16. I believe in order for sanitizers in general to work correctly, all of the instrumented objects in your program need to be compiled against the same version of the sanitizer runtime.

Since this is somewhat expected as the sanitizer versions do not match, I'm going to close this issue.

@wesleywiser wesleywiser closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
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. P-high High priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants