diff options
author | Ahmed S. Darwish <darwish.07@gmail.com> | 2008-03-01 15:00:05 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2008-04-18 19:52:36 -0400 |
commit | 03d37d25e0f91b28c4b6d002be6221f1af4b19d8 (patch) | |
tree | de56538f7b6e7623d7cee2b0fcdc8f9764957252 | |
parent | 6b89a74be0fbbc6cc639d5cf7dcf8e6ee0f120a7 (diff) |
LSM/Audit: Introduce generic Audit LSM hooks
Introduce a generic Audit interface for security modules
by adding the following new LSM hooks:
audit_rule_init(field, op, rulestr, lsmrule)
audit_rule_known(krule)
audit_rule_match(secid, field, op, rule, actx)
audit_rule_free(rule)
Those hooks are only available if CONFIG_AUDIT is enabled.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
Acked-by: James Morris <jmorris@namei.org>
Reviewed-by: Paul Moore <paul.moore@hp.com>
-rw-r--r-- | include/linux/security.h | 72 | ||||
-rw-r--r-- | security/dummy.c | 31 | ||||
-rw-r--r-- | security/security.c | 25 |
3 files changed, 127 insertions, 1 deletions
diff --git a/include/linux/security.h b/include/linux/security.h index 45717d9d9656..697f228daf19 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -37,6 +37,7 @@ | |||
37 | extern unsigned securebits; | 37 | extern unsigned securebits; |
38 | 38 | ||
39 | struct ctl_table; | 39 | struct ctl_table; |
40 | struct audit_krule; | ||
40 | 41 | ||
41 | /* | 42 | /* |
42 | * These functions are in security/capability.c and are used | 43 | * These functions are in security/capability.c and are used |
@@ -1235,6 +1236,37 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1235 | * @secdata contains the security context. | 1236 | * @secdata contains the security context. |
1236 | * @seclen contains the length of the security context. | 1237 | * @seclen contains the length of the security context. |
1237 | * | 1238 | * |
1239 | * Security hooks for Audit | ||
1240 | * | ||
1241 | * @audit_rule_init: | ||
1242 | * Allocate and initialize an LSM audit rule structure. | ||
1243 | * @field contains the required Audit action. Fields flags are defined in include/linux/audit.h | ||
1244 | * @op contains the operator the rule uses. | ||
1245 | * @rulestr contains the context where the rule will be applied to. | ||
1246 | * @lsmrule contains a pointer to receive the result. | ||
1247 | * Return 0 if @lsmrule has been successfully set, | ||
1248 | * -EINVAL in case of an invalid rule. | ||
1249 | * | ||
1250 | * @audit_rule_known: | ||
1251 | * Specifies whether given @rule contains any fields related to current LSM. | ||
1252 | * @rule contains the audit rule of interest. | ||
1253 | * Return 1 in case of relation found, 0 otherwise. | ||
1254 | * | ||
1255 | * @audit_rule_match: | ||
1256 | * Determine if given @secid matches a rule previously approved | ||
1257 | * by @audit_rule_known. | ||
1258 | * @secid contains the security id in question. | ||
1259 | * @field contains the field which relates to current LSM. | ||
1260 | * @op contains the operator that will be used for matching. | ||
1261 | * @rule points to the audit rule that will be checked against. | ||
1262 | * @actx points to the audit context associated with the check. | ||
1263 | * Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure. | ||
1264 | * | ||
1265 | * @audit_rule_free: | ||
1266 | * Deallocate the LSM audit rule structure previously allocated by | ||
1267 | * audit_rule_init. | ||
1268 | * @rule contains the allocated rule | ||
1269 | * | ||
1238 | * This is the main security structure. | 1270 | * This is the main security structure. |
1239 | */ | 1271 | */ |
1240 | struct security_operations { | 1272 | struct security_operations { |
@@ -1494,6 +1526,13 @@ struct security_operations { | |||
1494 | 1526 | ||
1495 | #endif /* CONFIG_KEYS */ | 1527 | #endif /* CONFIG_KEYS */ |
1496 | 1528 | ||
1529 | #ifdef CONFIG_AUDIT | ||
1530 | int (*audit_rule_init)(u32 field, u32 op, char *rulestr, void **lsmrule); | ||
1531 | int (*audit_rule_known)(struct audit_krule *krule); | ||
1532 | int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule, | ||
1533 | struct audit_context *actx); | ||
1534 | void (*audit_rule_free)(void *lsmrule); | ||
1535 | #endif /* CONFIG_AUDIT */ | ||
1497 | }; | 1536 | }; |
1498 | 1537 | ||
1499 | /* prototypes */ | 1538 | /* prototypes */ |
@@ -2700,5 +2739,38 @@ static inline int security_key_permission(key_ref_t key_ref, | |||
2700 | #endif | 2739 | #endif |
2701 | #endif /* CONFIG_KEYS */ | 2740 | #endif /* CONFIG_KEYS */ |
2702 | 2741 | ||
2742 | #ifdef CONFIG_AUDIT | ||
2743 | #ifdef CONFIG_SECURITY | ||
2744 | int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule); | ||
2745 | int security_audit_rule_known(struct audit_krule *krule); | ||
2746 | int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule, | ||
2747 | struct audit_context *actx); | ||
2748 | void security_audit_rule_free(void *lsmrule); | ||
2749 | |||
2750 | #else | ||
2751 | |||
2752 | static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr, | ||
2753 | void **lsmrule) | ||
2754 | { | ||
2755 | return 0; | ||
2756 | } | ||
2757 | |||
2758 | static inline int security_audit_rule_known(struct audit_krule *krule) | ||
2759 | { | ||
2760 | return 0; | ||
2761 | } | ||
2762 | |||
2763 | static inline int security_audit_rule_match(u32 secid, u32 field, u32 op, | ||
2764 | void *lsmrule, struct audit_context *actx) | ||
2765 | { | ||
2766 | return 0; | ||
2767 | } | ||
2768 | |||
2769 | static inline void security_audit_rule_free(void *lsmrule) | ||
2770 | { } | ||
2771 | |||
2772 | #endif /* CONFIG_SECURITY */ | ||
2773 | #endif /* CONFIG_AUDIT */ | ||
2774 | |||
2703 | #endif /* ! __LINUX_SECURITY_H */ | 2775 | #endif /* ! __LINUX_SECURITY_H */ |
2704 | 2776 | ||
diff --git a/security/dummy.c b/security/dummy.c index fb2e942efbb6..1ac9f8e66aa2 100644 --- a/security/dummy.c +++ b/security/dummy.c | |||
@@ -993,6 +993,30 @@ static inline int dummy_key_permission(key_ref_t key_ref, | |||
993 | } | 993 | } |
994 | #endif /* CONFIG_KEYS */ | 994 | #endif /* CONFIG_KEYS */ |
995 | 995 | ||
996 | #ifdef CONFIG_AUDIT | ||
997 | static inline int dummy_audit_rule_init(u32 field, u32 op, char *rulestr, | ||
998 | void **lsmrule) | ||
999 | { | ||
1000 | return 0; | ||
1001 | } | ||
1002 | |||
1003 | static inline int dummy_audit_rule_known(struct audit_krule *krule) | ||
1004 | { | ||
1005 | return 0; | ||
1006 | } | ||
1007 | |||
1008 | static inline int dummy_audit_rule_match(u32 secid, u32 field, u32 op, | ||
1009 | void *lsmrule, | ||
1010 | struct audit_context *actx) | ||
1011 | { | ||
1012 | return 0; | ||
1013 | } | ||
1014 | |||
1015 | static inline void dummy_audit_rule_free(void *lsmrule) | ||
1016 | { } | ||
1017 | |||
1018 | #endif /* CONFIG_AUDIT */ | ||
1019 | |||
996 | struct security_operations dummy_security_ops; | 1020 | struct security_operations dummy_security_ops; |
997 | 1021 | ||
998 | #define set_to_dummy_if_null(ops, function) \ | 1022 | #define set_to_dummy_if_null(ops, function) \ |
@@ -1182,6 +1206,11 @@ void security_fixup_ops (struct security_operations *ops) | |||
1182 | set_to_dummy_if_null(ops, key_free); | 1206 | set_to_dummy_if_null(ops, key_free); |
1183 | set_to_dummy_if_null(ops, key_permission); | 1207 | set_to_dummy_if_null(ops, key_permission); |
1184 | #endif /* CONFIG_KEYS */ | 1208 | #endif /* CONFIG_KEYS */ |
1185 | 1209 | #ifdef CONFIG_AUDIT | |
1210 | set_to_dummy_if_null(ops, audit_rule_init); | ||
1211 | set_to_dummy_if_null(ops, audit_rule_known); | ||
1212 | set_to_dummy_if_null(ops, audit_rule_match); | ||
1213 | set_to_dummy_if_null(ops, audit_rule_free); | ||
1214 | #endif | ||
1186 | } | 1215 | } |
1187 | 1216 | ||
diff --git a/security/security.c b/security/security.c index 290482bdbbb0..2ef593ec70f3 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -1120,3 +1120,28 @@ int security_key_permission(key_ref_t key_ref, | |||
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | #endif /* CONFIG_KEYS */ | 1122 | #endif /* CONFIG_KEYS */ |
1123 | |||
1124 | #ifdef CONFIG_AUDIT | ||
1125 | |||
1126 | int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule) | ||
1127 | { | ||
1128 | return security_ops->audit_rule_init(field, op, rulestr, lsmrule); | ||
1129 | } | ||
1130 | |||
1131 | int security_audit_rule_known(struct audit_krule *krule) | ||
1132 | { | ||
1133 | return security_ops->audit_rule_known(krule); | ||
1134 | } | ||
1135 | |||
1136 | void security_audit_rule_free(void *lsmrule) | ||
1137 | { | ||
1138 | security_ops->audit_rule_free(lsmrule); | ||
1139 | } | ||
1140 | |||
1141 | int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule, | ||
1142 | struct audit_context *actx) | ||
1143 | { | ||
1144 | return security_ops->audit_rule_match(secid, field, op, lsmrule, actx); | ||
1145 | } | ||
1146 | |||
1147 | #endif /* CONFIG_AUDIT */ | ||