Skip to content

Commit c52623a

Browse files
d-e-s-odanielocfb
authored andcommitted
Properly zero initialize uprobe opts sz member
This change fixes the sz member initialization of bpf_uprobe_opts objects that we use in the uprobe attach code. The previously incorrect size could lead to libbpf failing the attachment on optimized builds, where the size of Program objects was different to dev ones. Fixes: #447 Signed-off-by: Daniel Müller <[email protected]>
1 parent 450c37d commit c52623a

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

libbpf-rs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Unreleased
66
capabilities
77
- Fixed issue where instances of `Map` created or opened without going through
88
`Object` would leak file descriptors
9+
- Fixed potential Uprobe attachment failures on optimized builds caused by
10+
improper `libbpf_sys::bpf_object_open_opts` object initialization
911
- Adjusted various methods to work with `BorrowedFd` instead of raw file
1012
descriptors
1113
- Made `RingBufferBuilder::add` enforce that `self` cannot outlive the maps

libbpf-rs/src/program.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::os::unix::io::AsFd;
55
use std::os::unix::io::AsRawFd;
66
use std::os::unix::io::BorrowedFd;
77
use std::path::Path;
8+
use std::ptr;
89
use std::ptr::NonNull;
9-
use std::ptr::{self};
1010

1111
use libbpf_sys::bpf_func_id;
1212
use num_enum::TryFromPrimitive;
@@ -545,7 +545,7 @@ impl Program {
545545

546546
let func_name = util::str_to_cstring(&func_name)?;
547547
let opts = libbpf_sys::bpf_uprobe_opts {
548-
sz: mem::size_of::<Self>() as u64,
548+
sz: mem::size_of::<libbpf_sys::bpf_uprobe_opts>() as _,
549549
ref_ctr_offset: ref_ctr_offset as libbpf_sys::size_t,
550550
bpf_cookie: cookie,
551551
retprobe,

libbpf-rs/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn create_bpf_entity_checked<B: 'static, F: FnOnce() -> *mut B>(f: F) -> Res
8080
//
8181
// One way to fix the bug might be to change to calling
8282
// create_bpf_entity_checked_opt and handling Ok(None)
83-
// as a meaningfull value.
83+
// as a meaningful value.
8484
))
8585
})
8686
})

0 commit comments

Comments
 (0)