8000 function `set_thread_affinity()` has a potential index out of bounds issue without pre-checking · Issue #11 · elast0ny/affinity · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

function set_thread_affinity() has a potential index out of bounds issue without pre-checking #11

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

Open
cicilzx opened this issue Oct 17, 2024 · 0 comments

Comments

@cicilzx
Copy link
cicilzx commented Oct 17, 2024

Hi, I'm developing a fuzzer to test the safe abstraction, and I found a index out of bounds panic in function set_thread_affinity(). Bellow is a test case:

#[allow(warnings, unused, non_snake_case)]
#[test]
fn test_set_thread_affinity_Ms02H() {
    let core_ids: [usize; 5] = [6204201335507100450, 4992124196634415534, 7401057722669613811, 17862441050300482797, 16130232371561991009];
    let _ = set_thread_affinity(&core_ids);
}

Output:

thread 'linux::test_set_thread_affinity_Ms02H' panicked at /local/home/zixliu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.159/src/unix/linux_like/linux/mod.rs:4721:9:
index out of bounds: the len is 16 but the index is 96940645867298444
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_bounds_check
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/panicking.rs:274:5
   3: libc::unix::linux_like::linux::CPU_SET
             at /local/home/zixliu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.159/src/unix/linux_like/linux/mod.rs:4721:9
   4: affinity::linux::set_thread_affinity
             at ./src/linux.rs:9:13
   5: affinity::linux::test_set_thread_affinity_Ms02H
             at ./src/linux.rs:83:13
   6: affinity::linux::test_set_thread_affinity_Ms02H::{{closure}}
             at ./src/linux.rs:70:36
   7: core::ops::function::FnOnce::call_once
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I think checking the scope of core_ids before unsafe block would make the external API more robust.

let mut set: cpu_set_t = unsafe { zeroed() };

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

1 participant
0