ima: fix add LSM rule bug
authorMimi Zohar <>
Mon, 3 Jan 2011 22:59:10 +0000 (14:59 -0800)
committerLinus Torvalds <>
Tue, 4 Jan 2011 00:36:33 +0000 (16:36 -0800)
If security_filter_rule_init() doesn't return a rule, then not everything
is as fine as the return code implies.

This bug only occurs when the LSM (eg. SELinux) is disabled at runtime.

Adding an empty LSM rule causes ima_match_rules() to always succeed,
ignoring any remaining rules.

 default IMA TCB policy:
  dont_measure fsmagic=0x9fa0
  dont_measure fsmagic=0x62656572
  dont_measure fsmagic=0x64626720
  dont_measure fsmagic=0x01021994
  dont_measure fsmagic=0x73636673

  < LSM specific rule >
  dont_measure obj_type=var_log_t

  measure func=BPRM_CHECK
  measure func=FILE_MMAP mask=MAY_EXEC
  measure func=FILE_CHECK mask=MAY_READ uid=0

Thus without the patch, with the boot parameters 'tcb selinux=0', adding
the above 'dont_measure obj_type=var_log_t' rule to the default IMA TCB
measurement policy, would result in nothing being measured.  The patch
prevents the default TCB policy from being replaced.

Signed-off-by: Mimi Zohar <>
Cc: James Morris <>
Acked-by: Serge Hallyn <>
Cc: David Safford <>
Cc: <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>

index aef8c0a923ab8e2276f97e1fe2aa61b7748e25e4..d661afbe474c2fce8f74907869be0a644c5789c9 100644 (file)
@@ -253,6 +253,8 @@ static int ima_lsm_rule_init(struct ima_measure_rule_entry *entry,
        result = security_filter_rule_init(entry->lsm[lsm_rule].type,
                                           Audit_equal, args,
        result = security_filter_rule_init(entry->lsm[lsm_rule].type,
                                           Audit_equal, args,
+       if (!entry->lsm[lsm_rule].rule)
+               return -EINVAL;
        return result;
        return result;