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

Detect and report #[no_mangle] #104

Closed
Nemo157 opened this issue May 14, 2020 · 3 comments · Fixed by #173
Closed

Detect and report #[no_mangle] #104

Nemo157 opened this issue May 14, 2020 · 3 comments · Fixed by #173
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Nemo157
Copy link

Nemo157 commented May 14, 2020

Running this program results in a segfault, because using #[no_mangle] to override C functions can be UB (see also rust-lang/rust#28179)

#![forbid(unsafe_code)]

#[no_mangle]
fn write() {
    panic!("wat");
}

fn main() {
    println!("Hello, world!");
}
11:12 → RUST_BACKTRACE=short cargo run
   Compiling foo v0.1.0 (/tmp/tmp.kxF5z55SRc/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s
     Running `target/debug/foo`
[1]    1501355 segmentation fault (core dumped)  RUST_BACKTRACE=short cargo run

But cargo-geiger marks this crate as being unsafe free

0/0        0/0          0/0    0/0     0/0      :) foo 0.1.0
@anderejd
Copy link
Contributor

Thanks for opening this issue. The linked github issue was an interesting read and I agree that cargo-geiger should probably try to find #[no_mangle].

@anderejd anderejd added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels May 14, 2020
@kornelski
Copy link

kornelski commented Sep 14, 2020

I'd like to voice my support for this.

cargo-crev uses cargo-geiger to flag crates that use unsafe features (unsafe in a broad sense, not by Rust's own strict definition), and #[no_mangle] is an undetected loophole.

@anderejd
Copy link
Contributor

This should be relatively easy to add support for. The main work will be in https://github.com/rust-secure-code/cargo-geiger/blob/master/geiger/src/lib.rs

It will still be easy to intentionally hide usage of no_mangle (and unsafe), since we don't have #102 yet, resulting in shenanigans like #101.

This task is a great first issue, so anyone who's feeling tempted to contribute, feel free to jump right in! :) I'm currently in minimal effort mode when it comes to open source projects and will probably be doing release and dependency upgrades but not much else for the foreseeable future.

qrilka added a commit to qrilka/cargo-geiger that referenced this issue Jan 14, 2021
qrilka added a commit to qrilka/cargo-geiger that referenced this issue Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants