From 74b546827cdde13872e141e9e5b6cc9ac39efe1e Mon Sep 17 00:00:00 2001 From: Mary Date: Fri, 14 Jul 2023 09:42:51 +0200 Subject: [PATCH] aya: Ignore embedded BTF error if not truely required This allows fallback to BTF manual relocation when BTF loading fail when not truely required. --- aya/src/bpf.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 6e9dcdac..90e33488 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -389,9 +389,51 @@ impl<'a> BpfLoader<'a> { let btf_fd = if let Some(features) = &FEATURES.btf() { if let Some(btf) = obj.fixup_and_sanitize_btf(features)? { - // load btf to the kernel - let btf = load_btf(btf.to_bytes(), *verifier_log_level)?; - Some(btf) + match load_btf(btf.to_bytes(), *verifier_log_level) { + Ok(btf_fd) => Some(btf_fd), + // Only report an error here if the BTF is truely needed, otherwise proceed without. + Err(err) => { + for program in obj.programs.values() { + match program.section { + ProgramSection::Extension { .. } + | ProgramSection::FEntry { .. } + | ProgramSection::FExit { .. } + | ProgramSection::Lsm { .. } + | ProgramSection::BtfTracePoint { .. } => { + return Err(BpfError::BtfError(err)) + } + ProgramSection::KRetProbe { .. } + | ProgramSection::KProbe { .. } + | ProgramSection::UProbe { .. } + | ProgramSection::URetProbe { .. } + | ProgramSection::TracePoint { .. } + | ProgramSection::SocketFilter { .. } + | ProgramSection::Xdp { .. } + | ProgramSection::SkMsg { .. } + | ProgramSection::SkSkbStreamParser { .. } + | ProgramSection::SkSkbStreamVerdict { .. } + | ProgramSection::SockOps { .. } + | ProgramSection::SchedClassifier { .. } + | ProgramSection::CgroupSkb { .. } + | ProgramSection::CgroupSkbIngress { .. } + | ProgramSection::CgroupSkbEgress { .. } + | ProgramSection::CgroupSockAddr { .. } + | ProgramSection::CgroupSysctl { .. } + | ProgramSection::CgroupSockopt { .. } + | ProgramSection::LircMode2 { .. } + | ProgramSection::PerfEvent { .. } + | ProgramSection::RawTracePoint { .. } + | ProgramSection::SkLookup { .. } + | ProgramSection::CgroupSock { .. } + | ProgramSection::CgroupDevice { .. } => {} + } + } + + warn!("Object BTF couldn't be loaded in the kernel: {err}"); + + None + } + } } else { None }