Skip to content

Commit e2bf359

Browse files
committed
Bump libbpf-rs dependency to 0.24
Signed-off-by: Daiki Ueno <[email protected]>
1 parent 71233ff commit e2bf359

File tree

10 files changed

+351
-471
lines changed

10 files changed

+351
-471
lines changed

Cargo.lock

Lines changed: 298 additions & 422 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ crypto-auditing = { version = "=0.2.2", path = "crypto-auditing" }
2424
futures = "0.3"
2525
hex = "0.4"
2626
inotify = "0.10.2"
27-
libbpf-rs = { version = "0.21", features = ["novendor"] }
28-
libbpf-cargo = { version = "0.21", features = ["novendor"] }
27+
libbpf-rs = { version = "0.24.4", default-features = false }
28+
libbpf-cargo = { version = "0.24.4", default-features = false }
2929
libc = "0.2"
3030
nix = "0.26"
3131
openssl = "0.10"

agent/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use libbpf_cargo::SkeletonBuilder;
55
use std::{
66
env,
7+
ffi::OsStr,
78
fs::{self, File},
89
path::PathBuf,
910
process::Command,
@@ -35,7 +36,7 @@ fn main() {
3536
let src = srcdir.join("src").join("bpf").join("audit.bpf.c");
3637
SkeletonBuilder::new()
3738
.source(&src)
38-
.clang_args(&format!("-I{}", builddir.display()))
39+
.clang_args([OsStr::new("-I"), builddir.as_os_str()])
3940
.build_and_generate(&builddir.join("audit.skel.rs"))
4041
.unwrap();
4142
println!("cargo:rerun-if-changed={}", src.display());

agent/src/main.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use openssl::{
1111
symm::{Cipher, Crypter, Mode},
1212
};
1313
use std::io::prelude::*;
14+
use std::mem::MaybeUninit;
1415
use std::path::Path;
1516
use tokio::io::AsyncReadExt;
1617
use tokio::time::{timeout, Duration};
@@ -103,60 +104,53 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
103104
bump_memlock_rlimit()?;
104105

105106
let skel_builder = AuditSkelBuilder::default();
106-
let open_skel = skel_builder.open()?;
107+
let mut storage = MaybeUninit::uninit();
108+
let open_skel = skel_builder.open(&mut storage)?;
107109
let mut skel = open_skel.load()?;
108110

109-
let mut progs = skel.progs_mut();
110-
111111
let mut links = Vec::new();
112112
for library in &config.library {
113-
let prog = progs.new_context();
114-
if let Ok(link) = prog.attach_usdt(
113+
if let Ok(link) = skel.progs.new_context.attach_usdt(
115114
-1, // any process
116115
library,
117116
"crypto_auditing",
118117
"new_context",
119118
) {
120119
links.push(link);
121120
}
122-
let prog = progs.word_data();
123-
if let Ok(link) = prog.attach_usdt(
121+
if let Ok(link) = skel.progs.word_data.attach_usdt(
124122
-1, // any process
125123
library,
126124
"crypto_auditing",
127125
"word_data",
128126
) {
129127
links.push(link);
130128
}
131-
let prog = progs.string_data();
132-
if let Ok(link) = prog.attach_usdt(
129+
if let Ok(link) = skel.progs.string_data.attach_usdt(
133130
-1, // any process
134131
library,
135132
"crypto_auditing",
136133
"string_data",
137134
) {
138135
links.push(link);
139136
}
140-
let prog = progs.blob_data();
141-
if let Ok(link) = prog.attach_usdt(
137+
if let Ok(link) = skel.progs.blob_data.attach_usdt(
142138
-1, // any process
143139
library,
144140
"crypto_auditing",
145141
"blob_data",
146142
) {
147143
links.push(link);
148144
}
149-
let prog = progs.data();
150-
if let Ok(link) = prog.attach_usdt(
145+
if let Ok(link) = skel.progs.data.attach_usdt(
151146
-1, // any process
152147
library,
153148
"crypto_auditing",
154149
"data",
155150
) {
156151
links.push(link);
157152
}
158-
let prog = progs.new_context_with_data();
159-
if let Ok(link) = prog.attach_usdt(
153+
if let Ok(link) = skel.progs.new_context_with_data.attach_usdt(
160154
-1, // any process
161155
library,
162156
"crypto_auditing",
@@ -171,7 +165,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
171165
rand_bytes(&mut encryption_key)?;
172166

173167
start(async {
174-
let mut rb = ringbuf::RingBuffer::new(skel.obj.map_mut("ringbuf").unwrap());
168+
let mut rb = ringbuf::RingBuffer::new(&skel.maps.ringbuf);
175169

176170
if let Some((ref user, ref group)) = config.user {
177171
permissions::run_as(user, group)?;

agent/src/ringbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under LGPL-2.1 or BSD-2-Clause.
44

55
use core::task::{Context, Poll};
6-
use libbpf_rs::{query::MapInfoIter, Map};
6+
use libbpf_rs::{query::MapInfoIter, Map, MapCore};
77
use std::io::Result;
88
use std::num::NonZeroUsize;
99
use std::os::fd::{AsFd, AsRawFd, RawFd};
@@ -26,7 +26,7 @@ impl RingBuffer {
2626
pub fn new(map: &Map) -> Self {
2727
let mut max_entries = 0;
2828
for m in MapInfoIter::default() {
29-
if m.name == map.name() {
29+
if m.name.as_bytes() == map.info().unwrap().name().unwrap().as_bytes() {
3030
max_entries = m.max_entries;
3131
}
3232
}

agent/tests/agenttest/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use libbpf_cargo::SkeletonBuilder;
55
use std::{
66
env,
7+
ffi::OsStr,
78
fs::{self, File},
89
path::PathBuf,
910
process::Command,
@@ -35,7 +36,7 @@ fn main() {
3536
let src = srcdir.join("src").join("bpf").join("agent.bpf.c");
3637
SkeletonBuilder::new()
3738
.source(&src)
38-
.clang_args(&format!("-I{}", builddir.display()))
39+
.clang_args([OsStr::new("-I"), builddir.as_os_str()])
3940
.build_and_generate(&builddir.join("agent.skel.rs"))
4041
.unwrap();
4142
println!("cargo:rerun-if-changed={}", src.display());

agent/tests/agenttest/src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use anyhow::{bail, Result};
55
use libbpf_rs::{
66
skel::{OpenSkel, SkelBuilder},
7-
Link, Map, Object, RingBufferBuilder,
7+
Link, Map, OpenObject, RingBufferBuilder,
88
};
9+
use std::mem::MaybeUninit;
910
use std::path::Path;
1011
use std::process::Child;
1112
use std::time::Duration;
@@ -28,15 +29,19 @@ pub fn bump_memlock_rlimit() -> Result<()> {
2829
Ok(())
2930
}
3031

31-
pub fn attach_bpf(process: &Child, path: impl AsRef<Path>) -> Result<(Link, Object)> {
32+
pub fn attach_bpf<'obj>(
33+
process: &'obj Child,
34+
path: impl AsRef<Path>,
35+
storage: &'obj mut MaybeUninit<OpenObject>,
36+
) -> Result<(Link, AgentSkel<'obj>)> {
3237
let skel_builder = AgentSkelBuilder::default();
33-
let open_skel = skel_builder.open()?;
34-
let mut skel = open_skel.load()?;
3538

36-
let mut progs = skel.progs_mut();
37-
let prog = progs.event_group();
39+
let open_skel = skel_builder.open(storage)?;
40+
let mut skel = open_skel.load()?;
3841

39-
let link = prog
42+
let link = skel
43+
.progs
44+
.event_group
4045
.attach_usdt(
4146
process.id() as i32,
4247
path.as_ref(),
@@ -45,7 +50,7 @@ pub fn attach_bpf(process: &Child, path: impl AsRef<Path>) -> Result<(Link, Obje
4550
)
4651
.expect("unable to attach prog");
4752

48-
Ok((link, skel.obj))
53+
Ok((link, skel))
4954
}
5055

5156
// Copied from libbpf-rs/libbpf-rs/tests/test.rs

agent/tests/coalesce.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crypto_auditing::types::EventGroup;
88
use probe::probe;
99
use serde_cbor::de::Deserializer;
1010
use std::env;
11+
use std::mem::MaybeUninit;
1112
use std::path::PathBuf;
1213
use std::process::{Child, Command};
1314
use std::thread;
@@ -77,14 +78,14 @@ fn test_probe_coalesce() {
7778
let bar = String::from("bar\0");
7879
let baz = String::from("baz\0");
7980

80-
let (_link, object) =
81-
attach_bpf(&process.0, &agent_path).expect("unable to attach agent.bpf.o");
82-
let map = object.map("ringbuf").expect("unable to get ringbuf map");
81+
let mut storage = MaybeUninit::uninit();
82+
let (_link, skel) =
83+
attach_bpf(&process.0, &agent_path, &mut storage).expect("unable to attach agent.bpf.o");
8384

8485
let timeout = Duration::from_secs(10);
8586

8687
let result = with_ringbuffer(
87-
map,
88+
&skel.maps.ringbuf,
8889
|| {
8990
probe!(crypto_auditing, new_context, 1, 2);
9091
probe!(crypto_auditing, word_data, 1, foo.as_ptr(), 3);
@@ -103,7 +104,7 @@ fn test_probe_coalesce() {
103104
.expect("unable to exercise probe points");
104105
assert_eq!(result, 4);
105106
let result = with_ringbuffer(
106-
map,
107+
&skel.maps.ringbuf,
107108
|| {
108109
probe!(crypto_auditing, new_context, 4, 5);
109110
},

agent/tests/composite.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use libc::{c_long, c_uchar, c_void};
99
use probe::probe;
1010
use serde_cbor::de::Deserializer;
1111
use std::env;
12+
use std::mem::MaybeUninit;
1213
use std::path::PathBuf;
1314
use std::process::{Child, Command};
1415
use std::thread;
@@ -100,14 +101,14 @@ fn test_probe_composite() {
100101
},
101102
];
102103

103-
let (_link, object) =
104-
attach_bpf(&process.0, &agent_path).expect("unable to attach agent.bpf.o");
105-
let map = object.map("ringbuf").expect("unable to get ringbuf map");
104+
let mut storage = MaybeUninit::uninit();
105+
let (_link, skel) =
106+
attach_bpf(&process.0, &agent_path, &mut storage).expect("unable to attach agent.bpf.o");
106107

107108
let timeout = Duration::from_secs(10);
108109

109110
let result = with_ringbuffer(
110-
map,
111+
&skel.maps.ringbuf,
111112
|| {
112113
probe!(crypto_auditing, new_context, 1, 2);
113114
},
@@ -117,7 +118,7 @@ fn test_probe_composite() {
117118
assert_eq!(result, 1);
118119

119120
let result = with_ringbuffer(
120-
map,
121+
&skel.maps.ringbuf,
121122
|| {
122123
probe!(crypto_auditing, data, 1, events.as_ptr(), events.len());
123124
},
@@ -127,7 +128,7 @@ fn test_probe_composite() {
127128
assert_eq!(result, 1);
128129

129130
let result = with_ringbuffer(
130-
map,
131+
&skel.maps.ringbuf,
131132
|| {
132133
probe!(crypto_auditing, new_context, 4, 5);
133134
},

agent/tests/no_coalesce.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crypto_auditing::types::EventGroup;
88
use probe::probe;
99
use serde_cbor::de::Deserializer;
1010
use std::env;
11+
use std::mem::MaybeUninit;
1112
use std::path::PathBuf;
1213
use std::process::{Child, Command};
1314
use std::thread;
@@ -75,14 +76,14 @@ fn test_probe_no_coalesce() {
7576
let bar = String::from("bar\0");
7677
let baz = String::from("baz\0");
7778

78-
let (_link, object) =
79-
attach_bpf(&process.0, &agent_path).expect("unable to attach agent.bpf.o");
80-
let map = object.map("ringbuf").expect("unable to get ringbuf map");
79+
let mut storage = MaybeUninit::uninit();
80+
let (_link, skel) =
81+
attach_bpf(&process.0, &agent_path, &mut storage).expect("unable to attach agent.bpf.o");
8182

8283
let timeout = Duration::from_secs(10);
8384

8485
let result = with_ringbuffer(
85-
map,
86+
&skel.maps.ringbuf,
8687
|| {
8788
probe!(crypto_auditing, new_context, 1, 2);
8889
},
@@ -91,7 +92,7 @@ fn test_probe_no_coalesce() {
9192
.expect("unable to exercise probe points");
9293
assert_eq!(result, 1);
9394
let result = with_ringbuffer(
94-
map,
95+
&skel.maps.ringbuf,
9596
|| {
9697
probe!(crypto_auditing, word_data, 1, foo.as_ptr(), 3);
9798
},
@@ -100,7 +101,7 @@ fn test_probe_no_coalesce() {
100101
.expect("unable to exercise probe points");
101102
assert_eq!(result, 1);
102103
let result = with_ringbuffer(
103-
map,
104+
&skel.maps.ringbuf,
104105
|| {
105106
probe!(crypto_auditing, string_data, 1, bar.as_ptr(), bar.as_ptr());
106107
},
@@ -109,7 +110,7 @@ fn test_probe_no_coalesce() {
109110
.expect("unable to exercise probe points");
110111
assert_eq!(result, 1);
111112
let result = with_ringbuffer(
112-
map,
113+
&skel.maps.ringbuf,
113114
|| {
114115
probe!(
115116
crypto_auditing,
@@ -125,7 +126,7 @@ fn test_probe_no_coalesce() {
125126
.expect("unable to exercise probe points");
126127
assert_eq!(result, 1);
127128
let result = with_ringbuffer(
128-
map,
129+
&skel.maps.ringbuf,
129130
|| {
130131
probe!(crypto_auditing, new_context, 4, 5);
131132
},

0 commit comments

Comments
 (0)