Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 347095
b: refs/heads/master
c: fdf9072
h: refs/heads/master
i:
  347093: c33c1cd
  347091: 382d300
  347087: 6b42f1b
v: v3
  • Loading branch information
Mimi Zohar authored and Rusty Russell committed Dec 14, 2012
1 parent acc2cab commit 7beba75
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1625cee56f8e6193b5a0809a414dfa395bd9cf1e
refs/heads/master: fdf90729e57812cb12d7938e2dee7c71e875fb08
3 changes: 2 additions & 1 deletion trunk/Documentation/ABI/testing/ima_policy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Description:
lsm: [[subj_user=] [subj_role=] [subj_type=]
[obj_user=] [obj_role=] [obj_type=]]

base: func:= [BPRM_CHECK][FILE_MMAP][FILE_CHECK]
base: func:= [BPRM_CHECK][FILE_MMAP][FILE_CHECK][MODULE_CHECK]
mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]
fsmagic:= hex value
uid:= decimal value
Expand Down Expand Up @@ -53,6 +53,7 @@ Description:
measure func=BPRM_CHECK
measure func=FILE_MMAP mask=MAY_EXEC
measure func=FILE_CHECK mask=MAY_READ uid=0
measure func=MODULE_CHECK uid=0
appraise fowner=0

The default policy measures all executables in bprm_check,
Expand Down
6 changes: 6 additions & 0 deletions trunk/include/linux/ima.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern int ima_bprm_check(struct linux_binprm *bprm);
extern int ima_file_check(struct file *file, int mask);
extern void ima_file_free(struct file *file);
extern int ima_file_mmap(struct file *file, unsigned long prot);
extern int ima_module_check(struct file *file);

#else
static inline int ima_bprm_check(struct linux_binprm *bprm)
Expand All @@ -40,6 +41,11 @@ static inline int ima_file_mmap(struct file *file, unsigned long prot)
return 0;
}

static inline int ima_module_check(struct file *file)
{
return 0;
}

#endif /* CONFIG_IMA_H */

#ifdef CONFIG_IMA_APPRAISE
Expand Down
2 changes: 1 addition & 1 deletion trunk/security/integrity/ima/ima.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct integrity_iint_cache *integrity_iint_insert(struct inode *inode);
struct integrity_iint_cache *integrity_iint_find(struct inode *inode);

/* IMA policy related functions */
enum ima_hooks { FILE_CHECK = 1, FILE_MMAP, BPRM_CHECK, POST_SETATTR };
enum ima_hooks { FILE_CHECK = 1, FILE_MMAP, BPRM_CHECK, MODULE_CHECK, POST_SETATTR };

int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
int flags);
Expand Down
4 changes: 2 additions & 2 deletions trunk/security/integrity/ima/ima_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
* ima_get_action - appraise & measure decision based on policy.
* @inode: pointer to inode to measure
* @mask: contains the permission mask (MAY_READ, MAY_WRITE, MAY_EXECUTE)
* @function: calling function (FILE_CHECK, BPRM_CHECK, FILE_MMAP)
* @function: calling function (FILE_CHECK, BPRM_CHECK, FILE_MMAP, MODULE_CHECK)
*
* The policy is defined in terms of keypairs:
* subj=, obj=, type=, func=, mask=, fsmagic=
* subj,obj, and type: are LSM specific.
* func: FILE_CHECK | BPRM_CHECK | FILE_MMAP
* func: FILE_CHECK | BPRM_CHECK | FILE_MMAP | MODULE_CHECK
* mask: contains the permission mask
* fsmagic: hex value
*
Expand Down
21 changes: 21 additions & 0 deletions trunk/security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,27 @@ int ima_file_check(struct file *file, int mask)
}
EXPORT_SYMBOL_GPL(ima_file_check);

/**
* ima_module_check - based on policy, collect/store/appraise measurement.
* @file: pointer to the file to be measured/appraised
*
* Measure/appraise kernel modules based on policy.
*
* Always return 0 and audit dentry_open failures.
* Return code is based upon measurement appraisal.
*/
int ima_module_check(struct file *file)
{
int rc;

if (!file)
rc = INTEGRITY_UNKNOWN;
else
rc = process_measurement(file, file->f_dentry->d_name.name,
MAY_EXEC, MODULE_CHECK);
return (ima_appraise & IMA_APPRAISE_ENFORCE) ? rc : 0;
}

static int __init init_ima(void)
{
int error;
Expand Down
3 changes: 3 additions & 0 deletions trunk/security/integrity/ima/ima_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static struct ima_rule_entry default_rules[] = {
.flags = IMA_FUNC | IMA_MASK},
{.action = MEASURE,.func = FILE_CHECK,.mask = MAY_READ,.uid = GLOBAL_ROOT_UID,
.flags = IMA_FUNC | IMA_MASK | IMA_UID},
{.action = MEASURE,.func = MODULE_CHECK, .flags = IMA_FUNC},
};

static struct ima_rule_entry default_appraise_rules[] = {
Expand Down Expand Up @@ -401,6 +402,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
/* PATH_CHECK is for backwards compat */
else if (strcmp(args[0].from, "PATH_CHECK") == 0)
entry->func = FILE_CHECK;
else if (strcmp(args[0].from, "MODULE_CHECK") == 0)
entry->func = MODULE_CHECK;
else if (strcmp(args[0].from, "FILE_MMAP") == 0)
entry->func = FILE_MMAP;
else if (strcmp(args[0].from, "BPRM_CHECK") == 0)
Expand Down
7 changes: 6 additions & 1 deletion trunk/security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,12 @@ int security_kernel_module_request(char *kmod_name)

int security_kernel_module_from_file(struct file *file)
{
return security_ops->kernel_module_from_file(file);
int ret;

ret = security_ops->kernel_module_from_file(file);
if (ret)
return ret;
return ima_module_check(file);
}

int security_task_fix_setuid(struct cred *new, const struct cred *old,
Expand Down

0 comments on commit 7beba75

Please sign in to comment.