3838#define IMA_GID 0x2000
3939#define IMA_EGID 0x4000
4040#define IMA_FGROUP 0x8000
41+ #define IMA_FS_SUBTYPE 0x10000
4142
4243#define UNKNOWN 0
4344#define MEASURE 0x0001 /* same as IMA_MEASURE */
4445#define DONT_MEASURE 0x0002
4546#define APPRAISE 0x0004 /* same as IMA_APPRAISE */
4647#define DONT_APPRAISE 0x0008
4748#define AUDIT 0x0040
49+ #define DONT_AUDIT 0x0080
4850#define HASH 0x0100
4951#define DONT_HASH 0x0200
5052
@@ -119,6 +121,7 @@ struct ima_rule_entry {
119121 int type ; /* audit type */
120122 } lsm [MAX_LSM_RULES ];
121123 char * fsname ;
124+ char * fs_subtype ;
122125 struct ima_rule_opt_list * keyrings ; /* Measure keys added to these keyrings */
123126 struct ima_rule_opt_list * label ; /* Measure data grouped under this label */
124127 struct ima_template_desc * template ;
@@ -241,7 +244,8 @@ static struct ima_rule_entry build_appraise_rules[] __ro_after_init = {
241244
242245static struct ima_rule_entry secure_boot_rules [] __ro_after_init = {
243246 {.action = APPRAISE , .func = MODULE_CHECK ,
244- .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED },
247+ .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED | IMA_MODSIG_ALLOWED |
248+ IMA_CHECK_BLACKLIST },
245249 {.action = APPRAISE , .func = FIRMWARE_CHECK ,
246250 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED },
247251 {.action = APPRAISE , .func = KEXEC_KERNEL_CHECK ,
@@ -397,6 +401,7 @@ static void ima_free_rule(struct ima_rule_entry *entry)
397401 * the defined_templates list and cannot be freed here
398402 */
399403 kfree (entry -> fsname );
404+ kfree (entry -> fs_subtype );
400405 ima_free_rule_opt_list (entry -> keyrings );
401406 ima_lsm_free_rule (entry );
402407 kfree (entry );
@@ -601,6 +606,12 @@ static bool ima_match_rules(struct ima_rule_entry *rule,
601606 if ((rule -> flags & IMA_FSNAME )
602607 && strcmp (rule -> fsname , inode -> i_sb -> s_type -> name ))
603608 return false;
609+ if (rule -> flags & IMA_FS_SUBTYPE ) {
610+ if (!inode -> i_sb -> s_subtype )
611+ return false;
612+ if (strcmp (rule -> fs_subtype , inode -> i_sb -> s_subtype ))
613+ return false;
614+ }
604615 if ((rule -> flags & IMA_FSUUID ) &&
605616 !uuid_equal (& rule -> fsuuid , & inode -> i_sb -> s_uuid ))
606617 return false;
@@ -674,7 +685,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule,
674685 goto retry ;
675686 }
676687 }
677- if (! rc ) {
688+ if (rc <= 0 ) {
678689 result = false;
679690 goto out ;
680691 }
@@ -1064,10 +1075,10 @@ void ima_update_policy(void)
10641075enum policy_opt {
10651076 Opt_measure , Opt_dont_measure ,
10661077 Opt_appraise , Opt_dont_appraise ,
1067- Opt_audit , Opt_hash , Opt_dont_hash ,
1078+ Opt_audit , Opt_dont_audit , Opt_hash , Opt_dont_hash ,
10681079 Opt_obj_user , Opt_obj_role , Opt_obj_type ,
10691080 Opt_subj_user , Opt_subj_role , Opt_subj_type ,
1070- Opt_func , Opt_mask , Opt_fsmagic , Opt_fsname , Opt_fsuuid ,
1081+ Opt_func , Opt_mask , Opt_fsmagic , Opt_fsname , Opt_fs_subtype , Opt_fsuuid ,
10711082 Opt_uid_eq , Opt_euid_eq , Opt_gid_eq , Opt_egid_eq ,
10721083 Opt_fowner_eq , Opt_fgroup_eq ,
10731084 Opt_uid_gt , Opt_euid_gt , Opt_gid_gt , Opt_egid_gt ,
@@ -1086,6 +1097,7 @@ static const match_table_t policy_tokens = {
10861097 {Opt_appraise , "appraise" },
10871098 {Opt_dont_appraise , "dont_appraise" },
10881099 {Opt_audit , "audit" },
1100+ {Opt_dont_audit , "dont_audit" },
10891101 {Opt_hash , "hash" },
10901102 {Opt_dont_hash , "dont_hash" },
10911103 {Opt_obj_user , "obj_user=%s" },
@@ -1098,6 +1110,7 @@ static const match_table_t policy_tokens = {
10981110 {Opt_mask , "mask=%s" },
10991111 {Opt_fsmagic , "fsmagic=%s" },
11001112 {Opt_fsname , "fsname=%s" },
1113+ {Opt_fs_subtype , "fs_subtype=%s" },
11011114 {Opt_fsuuid , "fsuuid=%s" },
11021115 {Opt_uid_eq , "uid=%s" },
11031116 {Opt_euid_eq , "euid=%s" },
@@ -1282,7 +1295,8 @@ static bool ima_validate_rule(struct ima_rule_entry *entry)
12821295 if (entry -> flags & ~(IMA_FUNC | IMA_MASK | IMA_FSMAGIC |
12831296 IMA_UID | IMA_FOWNER | IMA_FSUUID |
12841297 IMA_INMASK | IMA_EUID | IMA_PCR |
1285- IMA_FSNAME | IMA_GID | IMA_EGID |
1298+ IMA_FSNAME | IMA_FS_SUBTYPE |
1299+ IMA_GID | IMA_EGID |
12861300 IMA_FGROUP | IMA_DIGSIG_REQUIRED |
12871301 IMA_PERMIT_DIRECTIO | IMA_VALIDATE_ALGOS |
12881302 IMA_CHECK_BLACKLIST | IMA_VERITY_REQUIRED ))
@@ -1295,7 +1309,8 @@ static bool ima_validate_rule(struct ima_rule_entry *entry)
12951309 if (entry -> flags & ~(IMA_FUNC | IMA_MASK | IMA_FSMAGIC |
12961310 IMA_UID | IMA_FOWNER | IMA_FSUUID |
12971311 IMA_INMASK | IMA_EUID | IMA_PCR |
1298- IMA_FSNAME | IMA_GID | IMA_EGID |
1312+ IMA_FSNAME | IMA_FS_SUBTYPE |
1313+ IMA_GID | IMA_EGID |
12991314 IMA_FGROUP | IMA_DIGSIG_REQUIRED |
13001315 IMA_PERMIT_DIRECTIO | IMA_MODSIG_ALLOWED |
13011316 IMA_CHECK_BLACKLIST | IMA_VALIDATE_ALGOS ))
@@ -1308,7 +1323,8 @@ static bool ima_validate_rule(struct ima_rule_entry *entry)
13081323
13091324 if (entry -> flags & ~(IMA_FUNC | IMA_FSMAGIC | IMA_UID |
13101325 IMA_FOWNER | IMA_FSUUID | IMA_EUID |
1311- IMA_PCR | IMA_FSNAME | IMA_GID | IMA_EGID |
1326+ IMA_PCR | IMA_FSNAME | IMA_FS_SUBTYPE |
1327+ IMA_GID | IMA_EGID |
13121328 IMA_FGROUP ))
13131329 return false;
13141330
@@ -1478,6 +1494,14 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
14781494
14791495 entry -> action = AUDIT ;
14801496 break ;
1497+ case Opt_dont_audit :
1498+ ima_log_string (ab , "action" , "dont_audit" );
1499+
1500+ if (entry -> action != UNKNOWN )
1501+ result = - EINVAL ;
1502+
1503+ entry -> action = DONT_AUDIT ;
1504+ break ;
14811505 case Opt_hash :
14821506 ima_log_string (ab , "action" , "hash" );
14831507
@@ -1587,6 +1611,22 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
15871611 result = 0 ;
15881612 entry -> flags |= IMA_FSNAME ;
15891613 break ;
1614+ case Opt_fs_subtype :
1615+ ima_log_string (ab , "fs_subtype" , args [0 ].from );
1616+
1617+ if (entry -> fs_subtype ) {
1618+ result = - EINVAL ;
1619+ break ;
1620+ }
1621+
1622+ entry -> fs_subtype = kstrdup (args [0 ].from , GFP_KERNEL );
1623+ if (!entry -> fs_subtype ) {
1624+ result = - ENOMEM ;
1625+ break ;
1626+ }
1627+ result = 0 ;
1628+ entry -> flags |= IMA_FS_SUBTYPE ;
1629+ break ;
15901630 case Opt_keyrings :
15911631 ima_log_string (ab , "keyrings" , args [0 ].from );
15921632
@@ -2097,6 +2137,8 @@ int ima_policy_show(struct seq_file *m, void *v)
20972137 seq_puts (m , pt (Opt_dont_appraise ));
20982138 if (entry -> action & AUDIT )
20992139 seq_puts (m , pt (Opt_audit ));
2140+ if (entry -> action & DONT_AUDIT )
2141+ seq_puts (m , pt (Opt_dont_audit ));
21002142 if (entry -> action & HASH )
21012143 seq_puts (m , pt (Opt_hash ));
21022144 if (entry -> action & DONT_HASH )
@@ -2133,6 +2175,12 @@ int ima_policy_show(struct seq_file *m, void *v)
21332175 seq_puts (m , " " );
21342176 }
21352177
2178+ if (entry -> flags & IMA_FS_SUBTYPE ) {
2179+ snprintf (tbuf , sizeof (tbuf ), "%s" , entry -> fs_subtype );
2180+ seq_printf (m , pt (Opt_fs_subtype ), tbuf );
2181+ seq_puts (m , " " );
2182+ }
2183+
21362184 if (entry -> flags & IMA_KEYRINGS ) {
21372185 seq_puts (m , "keyrings=" );
21382186 ima_show_rule_opt_list (m , entry -> keyrings );
0 commit comments