Skip to content

Commit 0e5a247

Browse files
Dmitry KasatkinMimi Zohar
authored andcommitted
ima: added policy support for 'security.ima' type
The 'security.ima' extended attribute may contain either the file data's hash or a digital signature. This patch adds support for requiring a specific extended attribute type. It extends the IMA policy with a new keyword 'appraise_type=imasig'. (Default is hash.) Changelog v2: - Fixed Documentation/ABI/testing/ima_policy option syntax Changelog v1: - Differentiate between 'required' vs. 'actual' extended attribute Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
1 parent a175b8b commit 0e5a247

5 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎Documentation/ABI/testing/ima_policy‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ Description:
1818
rule format: action [condition ...]
1919

2020
action: measure | dont_measure | appraise | dont_appraise | audit
21-
condition:= base | lsm
21+
condition:= base | lsm [option]
2222
base: [[func=] [mask=] [fsmagic=] [uid=] [fowner]]
2323
lsm: [[subj_user=] [subj_role=] [subj_type=]
2424
[obj_user=] [obj_role=] [obj_type=]]
25+
option: [[appraise_type=]]
2526

2627
base: func:= [BPRM_CHECK][MMAP_CHECK][FILE_CHECK][MODULE_CHECK]
2728
mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]
2829
fsmagic:= hex value
2930
uid:= decimal value
3031
fowner:=decimal value
3132
lsm: are LSM specific
33+
option: appraise_type:= [imasig]
3234

3335
default policy:
3436
# PROC_SUPER_MAGIC

‎security/integrity/ima/ima_appraise.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ int ima_appraise_measurement(struct integrity_iint_cache *iint,
102102

103103
switch (xattr_value->type) {
104104
case IMA_XATTR_DIGEST:
105+
if (iint->flags & IMA_DIGSIG_REQUIRED) {
106+
cause = "IMA signature required";
107+
status = INTEGRITY_FAIL;
108+
break;
109+
}
105110
rc = memcmp(xattr_value->digest, iint->ima_xattr.digest,
106111
IMA_DIGEST_SIZE);
107112
if (rc) {

‎security/integrity/ima/ima_main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static int process_measurement(struct file *file, const char *filename,
169169
* (IMA_MEASURE, IMA_MEASURED, IMA_APPRAISE, IMA_APPRAISED,
170170
* IMA_AUDIT, IMA_AUDITED) */
171171
iint->flags |= action;
172+
action &= IMA_DO_MASK;
172173
action &= ~((iint->flags & IMA_DONE_MASK) >> 1);
173174

174175
/* Nothing to do, just return existing appraised status */

‎security/integrity/ima/ima_policy.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
245245
if (!ima_match_rules(entry, inode, func, mask))
246246
continue;
247247

248+
action |= entry->flags & IMA_ACTION_FLAGS;
249+
248250
action |= entry->action & IMA_DO_MASK;
249251
if (entry->action & IMA_DO_MASK)
250252
actmask &= ~(entry->action | entry->action << 1);
@@ -318,7 +320,8 @@ enum {
318320
Opt_audit,
319321
Opt_obj_user, Opt_obj_role, Opt_obj_type,
320322
Opt_subj_user, Opt_subj_role, Opt_subj_type,
321-
Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner
323+
Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner,
324+
Opt_appraise_type
322325
};
323326

324327
static match_table_t policy_tokens = {
@@ -338,6 +341,7 @@ static match_table_t policy_tokens = {
338341
{Opt_fsmagic, "fsmagic=%s"},
339342
{Opt_uid, "uid=%s"},
340343
{Opt_fowner, "fowner=%s"},
344+
{Opt_appraise_type, "appraise_type=%s"},
341345
{Opt_err, NULL}
342346
};
343347

@@ -560,6 +564,18 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
560564
LSM_SUBJ_TYPE,
561565
AUDIT_SUBJ_TYPE);
562566
break;
567+
case Opt_appraise_type:
568+
if (entry->action != APPRAISE) {
569+
result = -EINVAL;
570+
break;
571+
}
572+
573+
ima_log_string(ab, "appraise_type", args[0].from);
574+
if ((strcmp(args[0].from, "imasig")) == 0)
575+
entry->flags |= IMA_DIGSIG_REQUIRED;
576+
else
577+
result = -EINVAL;
578+
break;
563579
case Opt_err:
564580
ima_log_string(ab, "UNKNOWN", p);
565581
result = -EINVAL;

‎security/integrity/integrity.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
#define IMA_AUDITED 0x0080
2727

2828
/* iint cache flags */
29+
#define IMA_ACTION_FLAGS 0xff00
2930
#define IMA_DIGSIG 0x0100
31+
#define IMA_DIGSIG_REQUIRED 0x0200
3032

3133
#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT)
3234
#define IMA_DONE_MASK (IMA_MEASURED | IMA_APPRAISED | IMA_AUDITED \

0 commit comments

Comments
 (0)