@@ -54,6 +54,7 @@ struct linux_binprm;
5454#define TOMOYO_KEYWORD_KEEP_DOMAIN "keep_domain "
5555#define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
5656#define TOMOYO_KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "
57+ #define TOMOYO_KEYWORD_PATH_GROUP "path_group "
5758#define TOMOYO_KEYWORD_SELECT "select "
5859#define TOMOYO_KEYWORD_USE_PROFILE "use_profile "
5960#define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "ignore_global_allow_read"
@@ -204,6 +205,27 @@ struct tomoyo_path_info_with_data {
204205 char barrier2 [16 ]; /* Safeguard for overrun. */
205206};
206207
208+ struct tomoyo_name_union {
209+ const struct tomoyo_path_info * filename ;
210+ struct tomoyo_path_group * group ;
211+ u8 is_group ;
212+ };
213+
214+ /* Structure for "path_group" directive. */
215+ struct tomoyo_path_group {
216+ struct list_head list ;
217+ const struct tomoyo_path_info * group_name ;
218+ struct list_head member_list ;
219+ atomic_t users ;
220+ };
221+
222+ /* Structure for "path_group" directive. */
223+ struct tomoyo_path_group_member {
224+ struct list_head list ;
225+ bool is_deleted ;
226+ const struct tomoyo_path_info * member_name ;
227+ };
228+
207229/*
208230 * tomoyo_acl_info is a structure which is used for holding
209231 *
@@ -274,7 +296,7 @@ struct tomoyo_domain_info {
274296 *
275297 * (1) "head" which is a "struct tomoyo_acl_info".
276298 * (2) "perm" which is a bitmask of permitted operations.
277- * (3) "filename " is the pathname.
299+ * (3) "name " is the pathname.
278300 *
279301 * Directives held by this structure are "allow_read/write", "allow_execute",
280302 * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
@@ -287,8 +309,7 @@ struct tomoyo_path_acl {
287309 struct tomoyo_acl_info head ; /* type = TOMOYO_TYPE_PATH_ACL */
288310 u8 perm_high ;
289311 u16 perm ;
290- /* Pointer to single pathname. */
291- const struct tomoyo_path_info * filename ;
312+ struct tomoyo_name_union name ;
292313};
293314
294315/*
@@ -298,19 +319,17 @@ struct tomoyo_path_acl {
298319 *
299320 * (1) "head" which is a "struct tomoyo_acl_info".
300321 * (2) "perm" which is a bitmask of permitted operations.
301- * (3) "filename1 " is the source/old pathname.
302- * (4) "filename2 " is the destination/new pathname.
322+ * (3) "name1 " is the source/old pathname.
323+ * (4) "name2 " is the destination/new pathname.
303324 *
304325 * Directives held by this structure are "allow_rename", "allow_link" and
305326 * "allow_pivot_root".
306327 */
307328struct tomoyo_path2_acl {
308329 struct tomoyo_acl_info head ; /* type = TOMOYO_TYPE_PATH2_ACL */
309330 u8 perm ;
310- /* Pointer to single pathname. */
311- const struct tomoyo_path_info * filename1 ;
312- /* Pointer to single pathname. */
313- const struct tomoyo_path_info * filename2 ;
331+ struct tomoyo_name_union name1 ;
332+ struct tomoyo_name_union name2 ;
314333};
315334
316335/*
@@ -514,6 +533,9 @@ struct tomoyo_policy_manager_entry {
514533
515534/********** Function prototypes. **********/
516535
536+ /* Check whether the given name matches the given name_union. */
537+ bool tomoyo_compare_name_union (const struct tomoyo_path_info * name ,
538+ const struct tomoyo_name_union * ptr );
517539/* Check whether the domain has too many ACL entries to hold. */
518540bool tomoyo_domain_quota_is_ok (struct tomoyo_domain_info * const domain );
519541/* Transactional sprintf() for policy dump. */
@@ -526,6 +548,12 @@ bool tomoyo_is_correct_path(const char *filename, const s8 start_type,
526548 const s8 pattern_type , const s8 end_type );
527549/* Check whether the token can be a domainname. */
528550bool tomoyo_is_domain_def (const unsigned char * buffer );
551+ bool tomoyo_parse_name_union (const char * filename ,
552+ struct tomoyo_name_union * ptr );
553+ /* Check whether the given filename matches the given path_group. */
554+ bool tomoyo_path_matches_group (const struct tomoyo_path_info * pathname ,
555+ const struct tomoyo_path_group * group ,
556+ const bool may_use_pattern );
529557/* Check whether the given filename matches the given pattern. */
530558bool tomoyo_path_matches_pattern (const struct tomoyo_path_info * filename ,
531559 const struct tomoyo_path_info * pattern );
@@ -540,10 +568,14 @@ bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
540568bool tomoyo_read_domain_keeper_policy (struct tomoyo_io_buffer * head );
541569/* Read "file_pattern" entry in exception policy. */
542570bool tomoyo_read_file_pattern (struct tomoyo_io_buffer * head );
571+ /* Read "path_group" entry in exception policy. */
572+ bool tomoyo_read_path_group_policy (struct tomoyo_io_buffer * head );
543573/* Read "allow_read" entry in exception policy. */
544574bool tomoyo_read_globally_readable_policy (struct tomoyo_io_buffer * head );
545575/* Read "deny_rewrite" entry in exception policy. */
546576bool tomoyo_read_no_rewrite_policy (struct tomoyo_io_buffer * head );
577+ /* Tokenize a line. */
578+ bool tomoyo_tokenize (char * buffer , char * w [], size_t size );
547579/* Write domain policy violation warning message to console? */
548580bool tomoyo_verbose_mode (const struct tomoyo_domain_info * domain );
549581/* Convert double path operation to operation name. */
@@ -580,12 +612,18 @@ int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
580612int tomoyo_write_no_rewrite_policy (char * data , const bool is_delete );
581613/* Create "file_pattern" entry in exception policy. */
582614int tomoyo_write_pattern_policy (char * data , const bool is_delete );
615+ /* Create "path_group" entry in exception policy. */
616+ int tomoyo_write_path_group_policy (char * data , const bool is_delete );
583617/* Find a domain by the given name. */
584618struct tomoyo_domain_info * tomoyo_find_domain (const char * domainname );
585619/* Find or create a domain by the given name. */
586620struct tomoyo_domain_info * tomoyo_find_or_assign_new_domain (const char *
587621 domainname ,
588622 const u8 profile );
623+
624+ /* Allocate memory for "struct tomoyo_path_group". */
625+ struct tomoyo_path_group * tomoyo_get_path_group (const char * group_name );
626+
589627/* Check mode for specified functionality. */
590628unsigned int tomoyo_check_flags (const struct tomoyo_domain_info * domain ,
591629 const u8 index );
@@ -642,6 +680,9 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
642680int tomoyo_check_rewrite_permission (struct file * filp );
643681int tomoyo_find_next_domain (struct linux_binprm * bprm );
644682
683+ /* Drop refcount on tomoyo_name_union. */
684+ void tomoyo_put_name_union (struct tomoyo_name_union * ptr );
685+
645686/* Run garbage collector. */
646687void tomoyo_run_gc (void );
647688
@@ -655,6 +696,7 @@ extern struct srcu_struct tomoyo_ss;
655696/* The list for "struct tomoyo_domain_info". */
656697extern struct list_head tomoyo_domain_list ;
657698
699+ extern struct list_head tomoyo_path_group_list ;
658700extern struct list_head tomoyo_domain_initializer_list ;
659701extern struct list_head tomoyo_domain_keeper_list ;
660702extern struct list_head tomoyo_alias_list ;
@@ -725,6 +767,12 @@ static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
725767 }
726768}
727769
770+ static inline void tomoyo_put_path_group (struct tomoyo_path_group * group )
771+ {
772+ if (group )
773+ atomic_dec (& group -> users );
774+ }
775+
728776static inline struct tomoyo_domain_info * tomoyo_domain (void )
729777{
730778 return current_cred ()-> security ;
@@ -736,6 +784,34 @@ static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
736784 return task_cred_xxx (task , security );
737785}
738786
787+ static inline bool tomoyo_is_same_acl_head (const struct tomoyo_acl_info * p1 ,
788+ const struct tomoyo_acl_info * p2 )
789+ {
790+ return p1 -> type == p2 -> type ;
791+ }
792+
793+ static inline bool tomoyo_is_same_name_union
794+ (const struct tomoyo_name_union * p1 , const struct tomoyo_name_union * p2 )
795+ {
796+ return p1 -> filename == p2 -> filename && p1 -> group == p2 -> group &&
797+ p1 -> is_group == p2 -> is_group ;
798+ }
799+
800+ static inline bool tomoyo_is_same_path_acl (const struct tomoyo_path_acl * p1 ,
801+ const struct tomoyo_path_acl * p2 )
802+ {
803+ return tomoyo_is_same_acl_head (& p1 -> head , & p2 -> head ) &&
804+ tomoyo_is_same_name_union (& p1 -> name , & p2 -> name );
805+ }
806+
807+ static inline bool tomoyo_is_same_path2_acl (const struct tomoyo_path2_acl * p1 ,
808+ const struct tomoyo_path2_acl * p2 )
809+ {
810+ return tomoyo_is_same_acl_head (& p1 -> head , & p2 -> head ) &&
811+ tomoyo_is_same_name_union (& p1 -> name1 , & p2 -> name1 ) &&
812+ tomoyo_is_same_name_union (& p1 -> name2 , & p2 -> name2 );
813+ }
814+
739815static inline bool tomoyo_is_same_domain_initializer_entry
740816(const struct tomoyo_domain_initializer_entry * p1 ,
741817 const struct tomoyo_domain_initializer_entry * p2 )
0 commit comments