Skip to content

Commit

Permalink
chore: ebpf toolchain upgrade (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
qjerome authored Jan 17, 2025
1 parent 29e3bb1 commit caa35ce
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 497 deletions.
29 changes: 10 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kunai-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default = []
user = ["aya", "dns-parser", "uuid", "thiserror", "serde"]

[build-dependencies]
bindgen = "0.69"
bindgen = "0.71"

[dependencies]
# optional deps (only for userland)
Expand Down
56 changes: 36 additions & 20 deletions kunai-common/src/buffer/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,27 @@ impl<const N: usize> Buffer<N> {
return Err(Error::BufferFull);
}

if check_bounds_signed(len, 0, N as i64) && check_bounds_signed(size, 1, N as i64) {
if gen::bpf_probe_read_user(
self.buf[len as usize..N].as_mut_ptr() as *mut _,
size as u32,
iov_base as *const _,
) < 0
{
return Err(Error::FailedToReadIovec);
}
// we check map access is not OOB
if !check_bounds_signed(len, 0, N as i64) {
return Ok(());
}

self.len += size as usize;
// we check we will not write OOB
if !check_bounds_signed(size, 0, N as i64) {
return Ok(());
}

if gen::bpf_probe_read_user(
self.buf[len as usize..N].as_mut_ptr() as *mut _,
(size as u32).clamp(0, N as u32),
iov_base as *const _,
) < 0
{
return Err(Error::FailedToReadIovec);
}

self.len += size as usize;

Ok(())
}

Expand All @@ -105,19 +113,27 @@ impl<const N: usize> Buffer<N> {
return Err(Error::BufferFull);
}

if check_bounds_signed(len, 0, N as i64) && check_bounds_signed(size, 1, N as i64) {
if gen::bpf_probe_read_kernel(
self.buf[len as usize..N].as_mut_ptr() as *mut _,
size as u32,
bvec_base as *const _,
) < 0
{
return Err(Error::FailedToReadBioVec);
}
// we check map access is not OOB
if !check_bounds_signed(len, 0, N as i64) {
return Ok(());
}

self.len += size as usize;
// we check we will not write OOB
if !check_bounds_signed(size, 0, N as i64) {
return Ok(());
}

if gen::bpf_probe_read_kernel(
self.buf[len as usize..N].as_mut_ptr() as *mut _,
(size as u32).clamp(0, N as u32),
bvec_base as *const _,
) < 0
{
return Err(Error::FailedToReadBioVec);
}

self.len += size as usize;

Ok(())
}

Expand Down
Loading

0 comments on commit caa35ce

Please sign in to comment.