Skip to content

Commit 067a436

Browse files
robertosassumimizohar
authored andcommitted
ima: Directly assign the ima_default_policy pointer to ima_rules
This patch prevents the following oops: [ 10.771813] BUG: kernel NULL pointer dereference, address: 0000000000000 [...] [ 10.779790] RIP: 0010:ima_match_policy+0xf7/0xb80 [...] [ 10.798576] Call Trace: [ 10.798993] ? ima_lsm_policy_change+0x2b0/0x2b0 [ 10.799753] ? inode_init_owner+0x1a0/0x1a0 [ 10.800484] ? _raw_spin_lock+0x7a/0xd0 [ 10.801592] ima_must_appraise.part.0+0xb6/0xf0 [ 10.802313] ? ima_fix_xattr.isra.0+0xd0/0xd0 [ 10.803167] ima_must_appraise+0x4f/0x70 [ 10.804004] ima_post_path_mknod+0x2e/0x80 [ 10.804800] do_mknodat+0x396/0x3c0 It occurs when there is a failure during IMA initialization, and ima_init_policy() is not called. IMA hooks still call ima_match_policy() but ima_rules is NULL. This patch prevents the crash by directly assigning the ima_default_policy pointer to ima_rules when ima_rules is defined. This wouldn't alter the existing behavior, as ima_rules is always set at the end of ima_init_policy(). Cc: [email protected] # 3.7.x Fixes: 07f6a79 ("ima: add appraise action keywords and default rules") Reported-by: Takashi Iwai <[email protected]> Signed-off-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 8eb613c commit 067a436

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

security/integrity/ima/ima_policy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static struct ima_rule_entry *arch_policy_entry __ro_after_init;
204204
static LIST_HEAD(ima_default_rules);
205205
static LIST_HEAD(ima_policy_rules);
206206
static LIST_HEAD(ima_temp_rules);
207-
static struct list_head *ima_rules;
207+
static struct list_head *ima_rules = &ima_default_rules;
208208

209209
/* Pre-allocated buffer used for matching keyrings. */
210210
static char *ima_keyrings;
@@ -768,7 +768,6 @@ void __init ima_init_policy(void)
768768
ARRAY_SIZE(default_appraise_rules),
769769
IMA_DEFAULT_POLICY);
770770

771-
ima_rules = &ima_default_rules;
772771
ima_update_policy_flag();
773772
}
774773

0 commit comments

Comments
 (0)