13 #include <linux/module.h>
14 #include <linux/list.h>
16 #include <linux/magic.h>
18 #include <linux/slab.h>
23 #define IMA_FUNC 0x0001
24 #define IMA_MASK 0x0002
25 #define IMA_FSMAGIC 0x0004
26 #define IMA_UID 0x0008
27 #define IMA_FOWNER 0x0010
30 #define MEASURE 0x0001
31 #define DONT_MEASURE 0x0002
32 #define APPRAISE 0x0004
33 #define DONT_APPRAISE 0x0008
36 #define MAX_LSM_RULES 6
106 static int __init default_measure_policy_setup(
char *
str)
111 __setup(
"ima_tcb", default_measure_policy_setup);
114 static int __init default_appraise_policy_setup(
char *
str)
116 ima_use_appraise_tcb = 1;
119 __setup(
"ima_appraise_tcb", default_appraise_policy_setup);
152 if (!rule->
lsm[i].rule)
160 rc = security_filter_rule_match(osid,
170 rc = security_filter_rule_match(sid,
201 int action = 0, actmask = flags | (flags << 1);
205 if (!(entry->
action & actmask))
208 if (!ima_match_rules(entry, inode, func, mask))
232 int i, measure_entries, appraise_entries;
235 measure_entries = ima_use_tcb ?
ARRAY_SIZE(default_rules) : 0;
236 appraise_entries = ima_use_appraise_tcb ?
239 for (i = 0; i < measure_entries + appraise_entries; i++) {
240 if (i < measure_entries)
244 int j = i - measure_entries;
251 ima_rules = &ima_default_rules;
263 const char *
op =
"policy_update";
264 const char *
cause =
"already exists";
268 if (ima_rules == &ima_default_rules) {
269 ima_rules = &ima_policy_rules;
274 NULL, op, cause, result, audit_info);
312 if (entry->
lsm[lsm_rule].rule)
316 result = security_filter_rule_init(entry->
lsm[lsm_rule].type,
318 &entry->
lsm[lsm_rule].rule);
319 if (!entry->
lsm[lsm_rule].rule)
331 static int ima_parse_rule(
char *rule,
struct ima_rule_entry *entry)
349 if ((*p ==
'\0') || (*p ==
' ') || (*p ==
'\t'))
354 ima_log_string(ab,
"action",
"measure");
362 ima_log_string(ab,
"action",
"dont_measure");
370 ima_log_string(ab,
"action",
"appraise");
378 ima_log_string(ab,
"action",
"dont_appraise");
386 ima_log_string(ab,
"action",
"audit");
394 ima_log_string(ab,
"func", args[0].
from);
402 else if (
strcmp(args[0].from,
"PATH_CHECK") == 0)
404 else if (
strcmp(args[0].from,
"FILE_MMAP") == 0)
406 else if (
strcmp(args[0].from,
"BPRM_CHECK") == 0)
414 ima_log_string(ab,
"mask", args[0].from);
419 if ((
strcmp(args[0].from,
"MAY_EXEC")) == 0)
421 else if (
strcmp(args[0].from,
"MAY_WRITE") == 0)
423 else if (
strcmp(args[0].from,
"MAY_READ") == 0)
425 else if (
strcmp(args[0].from,
"MAY_APPEND") == 0)
433 ima_log_string(ab,
"fsmagic", args[0].from);
446 ima_log_string(ab,
"uid", args[0].from);
448 if (uid_valid(entry->
uid)) {
456 if (!uid_valid(entry->
uid) || (((
uid_t)lnum) != lnum))
463 ima_log_string(ab,
"fowner", args[0].from);
465 if (uid_valid(entry->
fowner)) {
473 if (!uid_valid(entry->
fowner) || (((
uid_t)lnum) != lnum))
480 ima_log_string(ab,
"obj_user", args[0].from);
481 result = ima_lsm_rule_init(entry, args[0].from,
486 ima_log_string(ab,
"obj_role", args[0].from);
487 result = ima_lsm_rule_init(entry, args[0].from,
492 ima_log_string(ab,
"obj_type", args[0].from);
493 result = ima_lsm_rule_init(entry, args[0].from,
498 ima_log_string(ab,
"subj_user", args[0].from);
499 result = ima_lsm_rule_init(entry, args[0].from,
504 ima_log_string(ab,
"subj_role", args[0].from);
505 result = ima_lsm_rule_init(entry, args[0].from,
510 ima_log_string(ab,
"subj_type", args[0].from);
511 result = ima_lsm_rule_init(entry, args[0].from,
516 ima_log_string(ab,
"UNKNOWN", p);
538 const char *
op =
"update_policy";
545 if (ima_rules != &ima_default_rules) {
547 NULL, op,
"already exists",
559 INIT_LIST_HEAD(&entry->
list);
569 result = ima_parse_rule(p, entry);
573 NULL, op,
"invalid policy", result,