@@ -152,6 +152,39 @@ int aa_audit_file(struct aa_profile *profile, struct aa_perms *perms,
152152 return aa_audit (type , profile , & sa , file_audit_cb );
153153}
154154
155+ /**
156+ * is_deleted - test if a file has been completely unlinked
157+ * @dentry: dentry of file to test for deletion (NOT NULL)
158+ *
159+ * Returns: %1 if deleted else %0
160+ */
161+ static inline bool is_deleted (struct dentry * dentry )
162+ {
163+ if (d_unlinked (dentry ) && d_backing_inode (dentry )-> i_nlink == 0 )
164+ return 1 ;
165+ return 0 ;
166+ }
167+
168+ static int path_name (const char * op , struct aa_label * label ,
169+ const struct path * path , int flags , char * buffer ,
170+ const char * * name , struct path_cond * cond , u32 request )
171+ {
172+ struct aa_profile * profile ;
173+ const char * info = NULL ;
174+ int error ;
175+
176+ error = aa_path_name (path , flags , buffer , name , & info ,
177+ labels_profile (label )-> disconnected );
178+ if (error ) {
179+ fn_for_each_confined (label , profile ,
180+ aa_audit_file (profile , & nullperms , op , request , * name ,
181+ NULL , NULL , cond -> uid , info , error ));
182+ return error ;
183+ }
184+
185+ return 0 ;
186+ }
187+
155188/**
156189 * map_old_perms - map old file perms layout to the new layout
157190 * @old: permission set in old mapping
@@ -249,60 +282,69 @@ unsigned int aa_str_perms(struct aa_dfa *dfa, unsigned int start,
249282 return state ;
250283}
251284
252- /**
253- * is_deleted - test if a file has been completely unlinked
254- * @dentry: dentry of file to test for deletion (NOT NULL)
255- *
256- * Returns: %1 if deleted else %0
257- */
258- static inline bool is_deleted (struct dentry * dentry )
285+ int __aa_path_perm (const char * op , struct aa_profile * profile , const char * name ,
286+ u32 request , struct path_cond * cond , int flags ,
287+ struct aa_perms * perms )
259288{
260- if (d_unlinked (dentry ) && d_backing_inode (dentry )-> i_nlink == 0 )
261- return 1 ;
262- return 0 ;
289+ int e = 0 ;
290+
291+ if (profile_unconfined (profile ))
292+ return 0 ;
293+ aa_str_perms (profile -> file .dfa , profile -> file .start , name , cond , perms );
294+ if (request & ~perms -> allow )
295+ e = - EACCES ;
296+ return aa_audit_file (profile , perms , op , request , name , NULL , NULL ,
297+ cond -> uid , NULL , e );
298+ }
299+
300+
301+ static int profile_path_perm (const char * op , struct aa_profile * profile ,
302+ const struct path * path , char * buffer , u32 request ,
303+ struct path_cond * cond , int flags ,
304+ struct aa_perms * perms )
305+ {
306+ const char * name ;
307+ int error ;
308+
309+ if (profile_unconfined (profile ))
310+ return 0 ;
311+
312+ error = path_name (op , & profile -> label , path ,
313+ flags | profile -> path_flags , buffer , & name , cond ,
314+ request );
315+ if (error )
316+ return error ;
317+ return __aa_path_perm (op , profile , name , request , cond , flags ,
318+ perms );
263319}
264320
265321/**
266322 * aa_path_perm - do permissions check & audit for @path
267323 * @op: operation being checked
268- * @profile : profile being enforced (NOT NULL)
324+ * @label : profile being enforced (NOT NULL)
269325 * @path: path to check permissions of (NOT NULL)
270326 * @flags: any additional path flags beyond what the profile specifies
271327 * @request: requested permissions
272328 * @cond: conditional info for this request (NOT NULL)
273329 *
274330 * Returns: %0 else error if access denied or other error
275331 */
276- int aa_path_perm (const char * op , struct aa_profile * profile ,
332+ int aa_path_perm (const char * op , struct aa_label * label ,
277333 const struct path * path , int flags , u32 request ,
278334 struct path_cond * cond )
279335{
280- char * buffer = NULL ;
281336 struct aa_perms perms = {};
282- const char * name , * info = NULL ;
337+ struct aa_profile * profile ;
338+ char * buffer = NULL ;
283339 int error ;
284340
285- flags |= profile -> path_flags | (S_ISDIR (cond -> mode ) ? PATH_IS_DIR : 0 );
341+ flags |= PATH_DELEGATE_DELETED | (S_ISDIR (cond -> mode ) ? PATH_IS_DIR :
342+ 0 );
286343 get_buffers (buffer );
287- error = aa_path_name (path , flags , buffer , & name , & info ,
288- profile -> disconnected );
289- if (error ) {
290- if (error == - ENOENT && is_deleted (path -> dentry )) {
291- /* Access to open files that are deleted are
292- * give a pass (implicit delegation)
293- */
294- error = 0 ;
295- info = NULL ;
296- perms .allow = request ;
297- }
298- } else {
299- aa_str_perms (profile -> file .dfa , profile -> file .start , name , cond ,
300- & perms );
301- if (request & ~perms .allow )
302- error = - EACCES ;
303- }
304- error = aa_audit_file (profile , & perms , op , request , name , NULL , NULL ,
305- cond -> uid , info , error );
344+ error = fn_for_each_confined (label , profile ,
345+ profile_path_perm (op , profile , path , buffer , request ,
346+ cond , flags , & perms ));
347+
306348 put_buffers (buffer );
307349
308350 return error ;
@@ -482,7 +524,7 @@ int aa_file_perm(const char *op, struct aa_label *label, struct file *file,
482524 /* TODO: label cross check */
483525
484526 if (file -> f_path .mnt && path_mediated_fs (file -> f_path .dentry ))
485- error = aa_path_perm (op , labels_profile ( label ) , & file -> f_path ,
527+ error = aa_path_perm (op , label , & file -> f_path ,
486528 PATH_DELEGATE_DELETED , request , & cond );
487529
488530done :
0 commit comments