aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2012-04-03 12:38:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-04-03 12:49:41 -0400
commit3f0882c48286e7bdb0bbdec9c4bfa934e0db8e09 (patch)
tree20a7485417c8528d975ef4ff6e90467f63f67ab2 /security/selinux
parentf8294f1144ad0630075918df4bf94075f5384604 (diff)
SELinux: do not allocate stack space for AVC data unless needed
Instead of declaring the entire selinux_audit_data on the stack when we start an operation on declare it on the stack if we are going to use it. We know it's usefulness at the end of the security decision and can declare it there. Signed-off-by: Eric Paris <eparis@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/avc.c27
-rw-r--r--security/selinux/include/avc.h14
2 files changed, 27 insertions, 14 deletions
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index b5545a84448a..36c42bb52d81 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -436,9 +436,9 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
436{ 436{
437 struct common_audit_data *ad = a; 437 struct common_audit_data *ad = a;
438 audit_log_format(ab, "avc: %s ", 438 audit_log_format(ab, "avc: %s ",
439 ad->selinux_audit_data->denied ? "denied" : "granted"); 439 ad->selinux_audit_data->slad->denied ? "denied" : "granted");
440 avc_dump_av(ab, ad->selinux_audit_data->tclass, 440 avc_dump_av(ab, ad->selinux_audit_data->slad->tclass,
441 ad->selinux_audit_data->audited); 441 ad->selinux_audit_data->slad->audited);
442 audit_log_format(ab, " for "); 442 audit_log_format(ab, " for ");
443} 443}
444 444
@@ -452,9 +452,9 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
452{ 452{
453 struct common_audit_data *ad = a; 453 struct common_audit_data *ad = a;
454 audit_log_format(ab, " "); 454 audit_log_format(ab, " ");
455 avc_dump_query(ab, ad->selinux_audit_data->ssid, 455 avc_dump_query(ab, ad->selinux_audit_data->slad->ssid,
456 ad->selinux_audit_data->tsid, 456 ad->selinux_audit_data->slad->tsid,
457 ad->selinux_audit_data->tclass); 457 ad->selinux_audit_data->slad->tclass);
458} 458}
459 459
460/* This is the slow part of avc audit with big stack footprint */ 460/* This is the slow part of avc audit with big stack footprint */
@@ -465,6 +465,7 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
465{ 465{
466 struct common_audit_data stack_data; 466 struct common_audit_data stack_data;
467 struct selinux_audit_data sad = {0,}; 467 struct selinux_audit_data sad = {0,};
468 struct selinux_late_audit_data slad;
468 469
469 if (!a) { 470 if (!a) {
470 a = &stack_data; 471 a = &stack_data;
@@ -483,12 +484,14 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
483 (flags & MAY_NOT_BLOCK)) 484 (flags & MAY_NOT_BLOCK))
484 return -ECHILD; 485 return -ECHILD;
485 486
486 a->selinux_audit_data->tclass = tclass; 487 slad.tclass = tclass;
487 a->selinux_audit_data->requested = requested; 488 slad.requested = requested;
488 a->selinux_audit_data->ssid = ssid; 489 slad.ssid = ssid;
489 a->selinux_audit_data->tsid = tsid; 490 slad.tsid = tsid;
490 a->selinux_audit_data->audited = audited; 491 slad.audited = audited;
491 a->selinux_audit_data->denied = denied; 492 slad.denied = denied;
493
494 a->selinux_audit_data->slad = &slad;
492 a->lsm_pre_audit = avc_audit_pre_callback; 495 a->lsm_pre_audit = avc_audit_pre_callback;
493 a->lsm_post_audit = avc_audit_post_callback; 496 a->lsm_post_audit = avc_audit_post_callback;
494 common_lsm_audit(a); 497 common_lsm_audit(a);
diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h
index 09c3eda12128..1931370233d7 100644
--- a/security/selinux/include/avc.h
+++ b/security/selinux/include/avc.h
@@ -46,19 +46,29 @@ struct avc_cache_stats {
46 unsigned int frees; 46 unsigned int frees;
47}; 47};
48 48
49struct selinux_audit_data { 49/*
50 * We only need this data after we have decided to send an audit message.
51 */
52struct selinux_late_audit_data {
50 u32 ssid; 53 u32 ssid;
51 u32 tsid; 54 u32 tsid;
52 u16 tclass; 55 u16 tclass;
53 u32 requested; 56 u32 requested;
54 u32 audited; 57 u32 audited;
55 u32 denied; 58 u32 denied;
59 int result;
60};
61
62/*
63 * We collect this at the beginning or during an selinux security operation
64 */
65struct selinux_audit_data {
56 /* 66 /*
57 * auditdeny is a bit tricky and unintuitive. See the 67 * auditdeny is a bit tricky and unintuitive. See the
58 * comments in avc.c for it's meaning and usage. 68 * comments in avc.c for it's meaning and usage.
59 */ 69 */
60 u32 auditdeny; 70 u32 auditdeny;
61 int result; 71 struct selinux_late_audit_data *slad;
62}; 72};
63 73
64/* 74/*