Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Table::new() should be private or unsafe #192

Closed
LegionMammal978 opened this issue Jul 8, 2022 · 1 comment · Fixed by #194
Closed

Table::new() should be private or unsafe #192

LegionMammal978 opened this issue Jul 8, 2022 · 1 comment · Fixed by #194

Comments

@LegionMammal978
Copy link

LegionMammal978 commented Jul 8, 2022

Table::new() can cause a segfault in safe code from dereferencing an arbitrary pointer. To illustrate:

/*
[dependencies]
bcc = "=0.0.32"
*/

use bcc::table::Table;
use std::os::raw::c_void;

fn main() {
    let p = &mut 0usize as *mut _ as *mut c_void;
    let mut table = Table::new(0, p);
    println!("{}", table.key_size());
}

The function should probably be marked unsafe, since the other methods in Table depend on p being a valid BPF module pointer. Alternatively, it should be private (or pub(crate)), since it's really only useful in BPF::table().

@brayniac
Copy link
Collaborator

brayniac commented Jul 8, 2022

Good find. I do believe the constructor should be restricted to crate level visibility.

brayniac added a commit to brayniac/rust-bcc that referenced this issue Sep 6, 2022
Fixes rust-bpf#192 by making the `Table` constructor only public within
the crate.
@brayniac brayniac mentioned this issue Sep 6, 2022
brayniac added a commit that referenced this issue Sep 6, 2022
Fixes #192 by changing `Table::new()` to be crate public only. Addresses various issues that prevented CI from passing.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants