@@ -49,7 +49,7 @@ int BPF_PROG(trace_file_open, struct file* file) {
4949 }
5050
5151 struct dentry * d = BPF_CORE_READ (file , f_path .dentry );
52- submit_event (& m -> file_open , event_type , path -> path , d );
52+ submit_event (& m -> file_open , event_type , path -> path , d , NULL );
5353
5454 return 0 ;
5555
@@ -96,10 +96,46 @@ int BPF_PROG(trace_path_unlink, struct path* dir, struct dentry* dentry) {
9696 return 0 ;
9797 }
9898
99- submit_event (& m -> path_unlink , FILE_ACTIVITY_UNLINK , path -> path , dentry );
99+ submit_event (& m -> path_unlink , FILE_ACTIVITY_UNLINK , path -> path , dentry , NULL );
100100 return 0 ;
101101
102102error :
103103 m -> path_unlink .error ++ ;
104104 return 0 ;
105105}
106+
107+ SEC ("lsm/path_chown" )
108+ int BPF_PROG (trace_path_chown , struct path * path , unsigned long long uid , unsigned long long gid ) {
109+ struct metrics_t * m = get_metrics ();
110+ union event_type_specific specific = { 0 };
111+ struct dentry * dentry ;
112+
113+ m -> path_chown .total ++ ;
114+
115+ struct bound_path_t * bound_path = path_read (path );
116+ if (bound_path == NULL ) {
117+ bpf_printk ("Failed to read path" );
118+ goto error ;
119+ }
120+
121+ if (!is_monitored (bound_path )) {
122+ m -> path_chown .ignored ++ ;
123+ return 0 ;
124+ }
125+
126+ dentry = BPF_CORE_READ (path , dentry );
127+
128+ specific .chown .new_ovner .uid = uid ;
129+ specific .chown .new_ovner .gid = gid ;
130+ if (get_owner_uid_gid (dentry , & specific .chown .prev_owner .uid , & specific .chown .prev_owner .uid )) {
131+ bpf_printk ("Failed to get owner uid/gid" );
132+ goto error ;
133+ }
134+
135+ submit_event (& m -> path_chown , FILE_ACTIVITY_CHOWN , bound_path -> path , dentry , & specific );
136+ return 0 ;
137+
138+ error :
139+ m -> path_chown .error ++ ;
140+ return 0 ;
141+ }
0 commit comments