aboutsummaryrefslogtreecommitdiffstats
path: root/security/smack
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2012-04-03 12:37:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-04-03 12:48:40 -0400
commit3b3b0e4fc15efa507b902d90cea39e496a523c3b (patch)
treed7b91c21ad6c6f4ac21dd51297b74eec47c61684 /security/smack
parent95694129b43165911dc4e8a972f0d39ad98d86be (diff)
LSM: shrink sizeof LSM specific portion of common_audit_data
Linus found that the gigantic size of the common audit data caused a big perf hit on something as simple as running stat() in a loop. This patch requires LSMs to declare the LSM specific portion separately rather than doing it in a union. Thus each LSM can be responsible for shrinking their portion and don't have to pay a penalty just because other LSMs have a bigger space requirement. Signed-off-by: Eric Paris <eparis@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/smack')
-rw-r--r--security/smack/smack.h13
-rw-r--r--security/smack/smack_access.c11
2 files changed, 18 insertions, 6 deletions
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 2ad00657b80..ccba3823d9e 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -185,6 +185,15 @@ struct smack_known {
185 */ 185 */
186#define SMK_NUM_ACCESS_TYPE 5 186#define SMK_NUM_ACCESS_TYPE 5
187 187
188/* SMACK data */
189struct smack_audit_data {
190 const char *function;
191 char *subject;
192 char *object;
193 char *request;
194 int result;
195};
196
188/* 197/*
189 * Smack audit data; is empty if CONFIG_AUDIT not set 198 * Smack audit data; is empty if CONFIG_AUDIT not set
190 * to save some stack 199 * to save some stack
@@ -192,6 +201,7 @@ struct smack_known {
192struct smk_audit_info { 201struct smk_audit_info {
193#ifdef CONFIG_AUDIT 202#ifdef CONFIG_AUDIT
194 struct common_audit_data a; 203 struct common_audit_data a;
204 struct smack_audit_data sad;
195#endif 205#endif
196}; 206};
197/* 207/*
@@ -311,7 +321,8 @@ static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
311{ 321{
312 memset(a, 0, sizeof(*a)); 322 memset(a, 0, sizeof(*a));
313 a->a.type = type; 323 a->a.type = type;
314 a->a.smack_audit_data.function = func; 324 a->a.smack_audit_data = &a->sad;
325 a->a.smack_audit_data->function = func;
315} 326}
316 327
317static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a, 328static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index cc7cb6edba0..2af7fcc98a7 100644
--- a/security/smack/smack_access.c
+++ b/security/smack/smack_access.c
@@ -275,9 +275,9 @@ static inline void smack_str_from_perm(char *string, int access)
275static void smack_log_callback(struct audit_buffer *ab, void *a) 275static void smack_log_callback(struct audit_buffer *ab, void *a)
276{ 276{
277 struct common_audit_data *ad = a; 277 struct common_audit_data *ad = a;
278 struct smack_audit_data *sad = &ad->smack_audit_data; 278 struct smack_audit_data *sad = ad->smack_audit_data;
279 audit_log_format(ab, "lsm=SMACK fn=%s action=%s", 279 audit_log_format(ab, "lsm=SMACK fn=%s action=%s",
280 ad->smack_audit_data.function, 280 ad->smack_audit_data->function,
281 sad->result ? "denied" : "granted"); 281 sad->result ? "denied" : "granted");
282 audit_log_format(ab, " subject="); 282 audit_log_format(ab, " subject=");
283 audit_log_untrustedstring(ab, sad->subject); 283 audit_log_untrustedstring(ab, sad->subject);
@@ -310,11 +310,12 @@ void smack_log(char *subject_label, char *object_label, int request,
310 if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) 310 if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0)
311 return; 311 return;
312 312
313 if (a->smack_audit_data.function == NULL) 313 sad = a->smack_audit_data;
314 a->smack_audit_data.function = "unknown"; 314
315 if (sad->function == NULL)
316 sad->function = "unknown";
315 317
316 /* end preparing the audit data */ 318 /* end preparing the audit data */
317 sad = &a->smack_audit_data;
318 smack_str_from_perm(request_buffer, request); 319 smack_str_from_perm(request_buffer, request);
319 sad->subject = subject_label; 320 sad->subject = subject_label;
320 sad->object = object_label; 321 sad->object = object_label;