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

Add memory sanitizer (msan) support for rand::getrandom_uninit (and io::read) #1071

Open
briansmith opened this issue Jun 7, 2024 · 3 comments

Comments

@briansmith
Copy link

briansmith commented Jun 7, 2024

In order to use create a rustix backend for the getrandom crate that would pass its tests using memory sanitizer, these functions nedd to __msan_unpoison their output buffer only when they succeed, when #[cfg(sanitize = "memory")] (only available on Nightly):

  • rand::getrandom_uninit
  • ,io::read

rand::getrandom_uninit is the most urgent, as people probably won't be running memory sanitizer on a kernel so old that getrandom would fall back to reading from /dev/urandom.

See rust-random/getrandom#463 for my attempt to do this directly within getrandom.

@notgull
Copy link
Contributor

notgull commented Jun 7, 2024

Do you have an example of this intrinsic being used? I'm not familiar enough with memory sanitizers to know what to do here.

It may also be a good idea to set up MSAN for this crate.

@briansmith
Copy link
Author

Do you have an example of this intrinsic being used? I'm not familiar enough with memory sanitizers to know what to do here.

I documented what LLVM libc does in src/util_syscall_linux.rs in rust-random/getrandom#463, and that PR also shows in src/linux_android.rshow to wraplibc::syscal` with it. It's not an intrinsic, but a function that is provided by memory sanitizer, and memory sanitizer itself is provided by libstd/libcore normally, but I don't know for sure if it just picks up what's in libc or whether it separately links memory sanitizer even when libc isn't available.

@briansmith
Copy link
Author

See rust-lang/rust#123619, which seems relevant to figuring out a strategy for linking in the msan runtime.

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