-
Notifications
You must be signed in to change notification settings - Fork 67
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
Macro expansion #102
Comments
Hi! I think this would 100% take care of the plutonium issue. #[safe]
unsafe fn real_safe(x: f32) -> i32 {
std::mem::transmute::<f32, i32>(x)
}
#[safe]
fn deref_null() {
let p = &mut 0 as *mut i32;
println!("{}", *p);
} If you call expand, you get something like this: fn real_safe(x: f32) -> i32 {
#[allow(unused_unsafe)]
unsafe {
std::mem::transmute::<f32, i32>(x)
}
}
fn deref_null() {
#[allow(unused_unsafe)]
unsafe {
let p = &mut 0 as *mut i32;
// etc ....
}
} So I think the regular function visitor can handle it after expansion. |
Turns out there is a way to leverage rustc to detect all uses of unsafe code without requiring nightly: https://www.reddit.com/r/rust/comments/g9mw57/oneliner_to_correctly_list_all_uses_ofunsafe_in/ My quick tests show that it does in fact detect unsafe code in macros. |
Looks promising! Anyone who reads this and want to add it or something similar to cargo-geiger, please go ahead :) EDIT: As in go ahead and send a PR ;) |
As a quick explanation, the pieces are:
|
I well may be misunderstanding something, but it occurs to me that expanding a proc macro means executing arbitrary code, potentially allowing an adversarial proc macro to hide (The state of |
The adversarial proc-macro can already hide unsafe code currently though, so we're no better off, and I given that some proc macros do legitimately use unsafe code that should be audited, I think the benefits are worth it. |
Yeah, a more straightforward scenario is a proc macro that detects it's being run under |
It occurs to me to speculate (idly) that cargo-geiger itself could try to hide from proc-macros, maybe by changing its process name to (e.g.) "cargo-make" and (where available) using bind-mount trickery to hide |
Then we would be engaging in an arms race with attackers, except attackers know our single exact set of behaviors and we know nothing about the attackers. This is doomed from the start. |
I was mainly addressing macro expansion for things like the old proposal for cxx or stuff wrapping unsafe operations like |
Add macro expansion of some kind. Perhaps directly using
cargo expand
or doing something similar.The text was updated successfully, but these errors were encountered: