Add bounds check on sk_buff.rs

reviewable/pr1187/r1
Darius Jahandarie 2 months ago committed by GitHub
parent 39e40ba5c7
commit 1fd4f0a5fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -10,7 +10,7 @@ use aya_ebpf_bindings::helpers::{
};
use aya_ebpf_cty::c_long;
use crate::{bindings::__sk_buff, EbpfContext};
use crate::{bindings::__sk_buff, check_bounds_signed, EbpfContext};
pub struct SkBuff {
pub skb: *mut __sk_buff,
@ -90,6 +90,10 @@ impl SkBuff {
let len = usize::try_from(self.len()).map_err(|core::num::TryFromIntError { .. }| -1)?;
let len = len.checked_sub(offset).ok_or(-1)?;
let len = len.min(dst.len());
let in_bounds = check_bounds_signed(len as c_long, 0, dst.len() as c_long + 1);
if !in_bounds {
return Err(-1);
}
let len_u32 = u32::try_from(len).map_err(|core::num::TryFromIntError { .. }| -1)?;
let ret = unsafe {
bpf_skb_load_bytes(

Loading…
Cancel
Save