@@ -192,7 +192,7 @@ fn fill_ai_agent_root_pid(event: &mut BoxedProcEvents) {
192192#[ cfg( feature = "enterprise" ) ]
193193#[ allow( static_mut_refs) ]
194194fn emit_ai_agent_enforcement_audit_event ( event : & BoxedProcEvents ) {
195- use enterprise_utils:: ai_agent_enforcement:: EnforcementMode ;
195+ use enterprise_utils:: ai_agent_enforcement:: { EnforcementMode , KernelEventSource } ;
196196
197197 if event. 0 . ai_agent_root_pid == 0 {
198198 return ;
@@ -214,6 +214,17 @@ fn emit_ai_agent_enforcement_audit_event(event: &BoxedProcEvents) {
214214 if hit. mode != EnforcementMode :: AuditOnly {
215215 return ;
216216 }
217+ match hit. kernel_event_source {
218+ KernelEventSource :: Lsm if AI_AGENT_EXEC_LSM_EVENTS_ACTIVE . load ( Ordering :: Relaxed ) => {
219+ return ;
220+ }
221+ KernelEventSource :: KprobeOverride
222+ if AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE . load ( Ordering :: Relaxed ) =>
223+ {
224+ return ;
225+ }
226+ _ => { }
227+ }
217228 let Some ( audit_event) = event
218229 . 0
219230 . new_proc_block_event_for_audit ( & hit. rule_id , policy. epoch )
@@ -690,6 +701,10 @@ static AI_AGENT_SYSCALL_RULES_MAP_FD: AtomicI32 = AtomicI32::new(-1);
690701#[ cfg( feature = "enterprise" ) ]
691702static AI_AGENT_POLICY_EPOCH_MAP_FD : AtomicI32 = AtomicI32 :: new ( -1 ) ;
692703#[ cfg( feature = "enterprise" ) ]
704+ static AI_AGENT_EXEC_LSM_EVENTS_ACTIVE : AtomicBool = AtomicBool :: new ( false ) ;
705+ #[ cfg( feature = "enterprise" ) ]
706+ static AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE : AtomicBool = AtomicBool :: new ( false ) ;
707+ #[ cfg( feature = "enterprise" ) ]
693708const AI_AGENT_EXEC_RULES_BPF_MAX : usize = 256 ;
694709#[ cfg( feature = "enterprise" ) ]
695710const AI_AGENT_SYSCALL_RULES_BPF_MAX : usize = 32 ;
@@ -1716,6 +1731,8 @@ impl EbpfCollector {
17161731 let max_syscall_records = config. max_rules . min ( AI_AGENT_SYSCALL_RULES_BPF_MAX ) ;
17171732 if !config. enabled {
17181733 set_global_exec_policy ( None ) ;
1734+ AI_AGENT_EXEC_LSM_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
1735+ AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
17191736 Self :: clear_ai_agent_exec_enforcement_bpf_maps ( max_exec_records) ;
17201737 Self :: clear_ai_agent_syscall_enforcement_bpf_maps ( max_syscall_records) ;
17211738 return ;
@@ -1750,6 +1767,8 @@ impl EbpfCollector {
17501767 Err ( e) => {
17511768 warn ! ( "AI Agent enforcement: failed to compile policy: {}" , e) ;
17521769 set_global_exec_policy ( None ) ;
1770+ AI_AGENT_EXEC_LSM_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
1771+ AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
17531772 Self :: clear_ai_agent_exec_enforcement_bpf_maps ( max_exec_records) ;
17541773 return ;
17551774 }
@@ -1775,10 +1794,16 @@ impl EbpfCollector {
17751794 set_global_exec_policy ( None ) ;
17761795 }
17771796 }
1797+ AI_AGENT_EXEC_LSM_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
1798+ AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
17781799 Self :: clear_ai_agent_exec_enforcement_bpf_maps ( max_exec_records) ;
17791800 return ;
17801801 }
1802+ AI_AGENT_EXEC_LSM_EVENTS_ACTIVE . store ( lsm_allowed, Ordering :: Relaxed ) ;
1803+ AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE . store ( kprobe_override_allowed, Ordering :: Relaxed ) ;
17811804 } else {
1805+ AI_AGENT_EXEC_LSM_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
1806+ AI_AGENT_EXEC_KPROBE_EVENTS_ACTIVE . store ( false , Ordering :: Relaxed ) ;
17821807 Self :: clear_ai_agent_exec_enforcement_bpf_maps ( max_exec_records) ;
17831808 }
17841809
0 commit comments