Blame SOURCES/fapolicyd-falcon-sensor.patch

b0079f
From 2b13715219bbb6a84a73e007cea84f0d5d1d39ab Mon Sep 17 00:00:00 2001
b0079f
From: Radovan Sroka <rsroka@redhat.com>
b0079f
Date: Tue, 6 Dec 2022 15:09:44 +0100
b0079f
Subject: [PATCH] Extend new_event state machine
b0079f
b0079f
- allow other opens before dynamic linker execution
b0079f
- split original STATE_REOPEN to the new STATE_REOPEN and STATE_DEFAULT_REOPEN
b0079f
b0079f
- STATE_REOPEN now behaves as loop state for new opens (from the same subject),
b0079f
  uses skip_path
b0079f
- STATE_DEFAULT_REOPEN is needed when dynamic linker is directly executed
b0079f
  in such scenario we need to be sure that non of the following opens will
b0079f
  skip the path
b0079f
b0079f
Signed-off-by: Radovan Sroka <rsroka@redhat.com>
b0079f
---
b0079f
 src/library/event.c   | 16 ++++++++++++++++
b0079f
 src/library/process.h |  3 ++-
b0079f
 2 files changed, 18 insertions(+), 1 deletion(-)
b0079f
b0079f
diff --git a/src/library/event.c b/src/library/event.c
b0079f
index 4d79eb98..649cb9d6 100644
b0079f
--- a/src/library/event.c
b0079f
+++ b/src/library/event.c
b0079f
@@ -133,6 +133,12 @@ int new_event(const struct fanotify_event_metadata *m, event_t *e)
b0079f
 			(e->type & FAN_OPEN_PERM) && !rc) {
b0079f
 			skip_path = 1;
b0079f
 			s->info->state = STATE_REOPEN;
b0079f
+
b0079f
+			// special branch after ld_so exec
b0079f
+			// next opens will go fall trough
b0079f
+			if (s->info->path1 &&
b0079f
+				(strcmp(s->info->path1, SYSTEM_LD_SO) == 0))
b0079f
+				s->info->state = STATE_DEFAULT_REOPEN;
b0079f
 		}
b0079f
 
b0079f
 		// If not same proc or we detect execution, evict
b0079f
@@ -164,6 +170,7 @@ int new_event(const struct fanotify_event_metadata *m, event_t *e)
b0079f
 			skip_path = 1;
b0079f
 		}
b0079f
 
b0079f
+
b0079f
 		// If we've seen the reopen and its an execute and process
b0079f
 		// has an interpreter and we're the same process, don't evict
b0079f
 		// and don't collect the path since reopen interp will. The
b0079f
@@ -172,10 +179,19 @@ int new_event(const struct fanotify_event_metadata *m, event_t *e)
b0079f
 		if ((s->info->state == STATE_REOPEN) && !skip_path &&
b0079f
 				(e->type & FAN_OPEN_EXEC_PERM) &&
b0079f
 				(s->info->elf_info & HAS_INTERP) && !rc) {
b0079f
+			s->info->state = STATE_DEFAULT_REOPEN;
b0079f
 			evict = 0;
b0079f
 			skip_path = 1;
b0079f
 		}
b0079f
 
b0079f
+		// this is how STATE_REOPEN and
b0079f
+		// STATE_DEFAULT_REOPEN differs
b0079f
+		// in STATE_REOPEN path is always skipped
b0079f
+		if ((s->info->state == STATE_REOPEN) && !skip_path &&
b0079f
+				(e->type & FAN_OPEN_PERM) && !rc) {
b0079f
+			skip_path = 1;
b0079f
+		}
b0079f
+
b0079f
 		if (evict) {
b0079f
 			lru_evict(subj_cache, key);
b0079f
 			q_node = check_lru_cache(subj_cache, key);
b0079f
diff --git a/src/library/process.h b/src/library/process.h
b0079f
index daa9d0d0..a741d1ac 100644
b0079f
--- a/src/library/process.h
b0079f
+++ b/src/library/process.h
b0079f
@@ -31,7 +31,8 @@
b0079f
 #include "gcc-attributes.h"
b0079f
 
b0079f
 typedef enum {	STATE_COLLECTING=0,	// initial state - execute
b0079f
-		STATE_REOPEN,		// anticipating open perm next
b0079f
+		STATE_REOPEN,		// anticipating open perm next, always skips the path
b0079f
+		STATE_DEFAULT_REOPEN,  // reopen after dyn. linker exec, never skips the path
b0079f
 		STATE_STATIC_REOPEN,	// static app aniticipating
b0079f
 		STATE_PARTIAL,		// second path collected
b0079f
 		STATE_STATIC_PARTIAL,	// second path collected