Ver código fonte

Merge pull request #6 from vadorovsky/buffer-bounds

ebpf: Ensure the bounds of log buffer
Alessandro Decina 2 anos atrás
pai
commit
edc8395fb2

+ 1 - 1
aya-log-common/src/lib.rs

@@ -1,6 +1,6 @@
 #![no_std]
 
-pub const LOG_BUF_CAPACITY: usize = 1024;
+pub const LOG_BUF_CAPACITY: usize = 8192;
 
 pub const LOG_FIELDS: usize = 7;
 

+ 3 - 0
ebpf/aya-log-ebpf-macros/src/expand.rs

@@ -92,6 +92,9 @@ pub(crate) fn log(args: LogArgs, level: Option<TokenStream>) -> Result<TokenStre
             let write_args = quote! {{
                 use ::aya_log_ebpf::WriteToBuf;
                 Ok::<_, ()>(record_len) #( .and_then(|record_len| {
+                    if record_len >= buf.buf.len() {
+                        return Err(());
+                    }
                     { #formatting_exprs }.write(&mut buf.buf[record_len..]).map(|len| record_len + len)
                 }) )*
             }};