aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
Diffstat (limited to 'security')
-rw-r--r--security/apparmor/audit.c42
-rw-r--r--security/apparmor/capability.c6
-rw-r--r--security/apparmor/file.c54
-rw-r--r--security/apparmor/include/audit.h28
-rw-r--r--security/apparmor/ipc.c10
-rw-r--r--security/apparmor/lib.c4
-rw-r--r--security/apparmor/lsm.c8
-rw-r--r--security/apparmor/policy.c10
-rw-r--r--security/apparmor/policy_unpack.c20
-rw-r--r--security/apparmor/resource.c12
-rw-r--r--security/commoncap.c6
-rw-r--r--security/lsm_audit.c80
-rw-r--r--security/selinux/avc.c45
-rw-r--r--security/selinux/hooks.c176
-rw-r--r--security/selinux/include/avc.h25
-rw-r--r--security/smack/smack.h23
-rw-r--r--security/smack/smack_access.c14
-rw-r--r--security/smack/smack_lsm.c86
-rw-r--r--security/smack/smackfs.c14
19 files changed, 437 insertions, 226 deletions
diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c
index 5ff67776a5ad..cc3520d39a78 100644
--- a/security/apparmor/audit.c
+++ b/security/apparmor/audit.c
@@ -115,23 +115,23 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
115 115
116 if (aa_g_audit_header) { 116 if (aa_g_audit_header) {
117 audit_log_format(ab, "apparmor="); 117 audit_log_format(ab, "apparmor=");
118 audit_log_string(ab, aa_audit_type[sa->aad.type]); 118 audit_log_string(ab, aa_audit_type[sa->aad->type]);
119 } 119 }
120 120
121 if (sa->aad.op) { 121 if (sa->aad->op) {
122 audit_log_format(ab, " operation="); 122 audit_log_format(ab, " operation=");
123 audit_log_string(ab, op_table[sa->aad.op]); 123 audit_log_string(ab, op_table[sa->aad->op]);
124 } 124 }
125 125
126 if (sa->aad.info) { 126 if (sa->aad->info) {
127 audit_log_format(ab, " info="); 127 audit_log_format(ab, " info=");
128 audit_log_string(ab, sa->aad.info); 128 audit_log_string(ab, sa->aad->info);
129 if (sa->aad.error) 129 if (sa->aad->error)
130 audit_log_format(ab, " error=%d", sa->aad.error); 130 audit_log_format(ab, " error=%d", sa->aad->error);
131 } 131 }
132 132
133 if (sa->aad.profile) { 133 if (sa->aad->profile) {
134 struct aa_profile *profile = sa->aad.profile; 134 struct aa_profile *profile = sa->aad->profile;
135 pid_t pid; 135 pid_t pid;
136 rcu_read_lock(); 136 rcu_read_lock();
137 pid = rcu_dereference(tsk->real_parent)->pid; 137 pid = rcu_dereference(tsk->real_parent)->pid;
@@ -145,9 +145,9 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
145 audit_log_untrustedstring(ab, profile->base.hname); 145 audit_log_untrustedstring(ab, profile->base.hname);
146 } 146 }
147 147
148 if (sa->aad.name) { 148 if (sa->aad->name) {
149 audit_log_format(ab, " name="); 149 audit_log_format(ab, " name=");
150 audit_log_untrustedstring(ab, sa->aad.name); 150 audit_log_untrustedstring(ab, sa->aad->name);
151 } 151 }
152} 152}
153 153
@@ -159,10 +159,8 @@ static void audit_pre(struct audit_buffer *ab, void *ca)
159void aa_audit_msg(int type, struct common_audit_data *sa, 159void aa_audit_msg(int type, struct common_audit_data *sa,
160 void (*cb) (struct audit_buffer *, void *)) 160 void (*cb) (struct audit_buffer *, void *))
161{ 161{
162 sa->aad.type = type; 162 sa->aad->type = type;
163 sa->lsm_pre_audit = audit_pre; 163 common_lsm_audit(sa, audit_pre, cb);
164 sa->lsm_post_audit = cb;
165 common_lsm_audit(sa);
166} 164}
167 165
168/** 166/**
@@ -184,7 +182,7 @@ int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
184 BUG_ON(!profile); 182 BUG_ON(!profile);
185 183
186 if (type == AUDIT_APPARMOR_AUTO) { 184 if (type == AUDIT_APPARMOR_AUTO) {
187 if (likely(!sa->aad.error)) { 185 if (likely(!sa->aad->error)) {
188 if (AUDIT_MODE(profile) != AUDIT_ALL) 186 if (AUDIT_MODE(profile) != AUDIT_ALL)
189 return 0; 187 return 0;
190 type = AUDIT_APPARMOR_AUDIT; 188 type = AUDIT_APPARMOR_AUDIT;
@@ -196,21 +194,21 @@ int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
196 if (AUDIT_MODE(profile) == AUDIT_QUIET || 194 if (AUDIT_MODE(profile) == AUDIT_QUIET ||
197 (type == AUDIT_APPARMOR_DENIED && 195 (type == AUDIT_APPARMOR_DENIED &&
198 AUDIT_MODE(profile) == AUDIT_QUIET)) 196 AUDIT_MODE(profile) == AUDIT_QUIET))
199 return sa->aad.error; 197 return sa->aad->error;
200 198
201 if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED) 199 if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED)
202 type = AUDIT_APPARMOR_KILL; 200 type = AUDIT_APPARMOR_KILL;
203 201
204 if (!unconfined(profile)) 202 if (!unconfined(profile))
205 sa->aad.profile = profile; 203 sa->aad->profile = profile;
206 204
207 aa_audit_msg(type, sa, cb); 205 aa_audit_msg(type, sa, cb);
208 206
209 if (sa->aad.type == AUDIT_APPARMOR_KILL) 207 if (sa->aad->type == AUDIT_APPARMOR_KILL)
210 (void)send_sig_info(SIGKILL, NULL, sa->tsk ? sa->tsk : current); 208 (void)send_sig_info(SIGKILL, NULL, sa->tsk ? sa->tsk : current);
211 209
212 if (sa->aad.type == AUDIT_APPARMOR_ALLOWED) 210 if (sa->aad->type == AUDIT_APPARMOR_ALLOWED)
213 return complain_error(sa->aad.error); 211 return complain_error(sa->aad->error);
214 212
215 return sa->aad.error; 213 return sa->aad->error;
216} 214}
diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c
index 9982c48def4e..088dba3bf7dc 100644
--- a/security/apparmor/capability.c
+++ b/security/apparmor/capability.c
@@ -64,11 +64,13 @@ static int audit_caps(struct aa_profile *profile, struct task_struct *task,
64 struct audit_cache *ent; 64 struct audit_cache *ent;
65 int type = AUDIT_APPARMOR_AUTO; 65 int type = AUDIT_APPARMOR_AUTO;
66 struct common_audit_data sa; 66 struct common_audit_data sa;
67 struct apparmor_audit_data aad = {0,};
67 COMMON_AUDIT_DATA_INIT(&sa, CAP); 68 COMMON_AUDIT_DATA_INIT(&sa, CAP);
69 sa.aad = &aad;
68 sa.tsk = task; 70 sa.tsk = task;
69 sa.u.cap = cap; 71 sa.u.cap = cap;
70 sa.aad.op = OP_CAPABLE; 72 sa.aad->op = OP_CAPABLE;
71 sa.aad.error = error; 73 sa.aad->error = error;
72 74
73 if (likely(!error)) { 75 if (likely(!error)) {
74 /* test if auditing is being forced */ 76 /* test if auditing is being forced */
diff --git a/security/apparmor/file.c b/security/apparmor/file.c
index 5d176f2530c9..2f8fcba9ce4b 100644
--- a/security/apparmor/file.c
+++ b/security/apparmor/file.c
@@ -67,22 +67,22 @@ static void file_audit_cb(struct audit_buffer *ab, void *va)
67 struct common_audit_data *sa = va; 67 struct common_audit_data *sa = va;
68 uid_t fsuid = current_fsuid(); 68 uid_t fsuid = current_fsuid();
69 69
70 if (sa->aad.fs.request & AA_AUDIT_FILE_MASK) { 70 if (sa->aad->fs.request & AA_AUDIT_FILE_MASK) {
71 audit_log_format(ab, " requested_mask="); 71 audit_log_format(ab, " requested_mask=");
72 audit_file_mask(ab, sa->aad.fs.request); 72 audit_file_mask(ab, sa->aad->fs.request);
73 } 73 }
74 if (sa->aad.fs.denied & AA_AUDIT_FILE_MASK) { 74 if (sa->aad->fs.denied & AA_AUDIT_FILE_MASK) {
75 audit_log_format(ab, " denied_mask="); 75 audit_log_format(ab, " denied_mask=");
76 audit_file_mask(ab, sa->aad.fs.denied); 76 audit_file_mask(ab, sa->aad->fs.denied);
77 } 77 }
78 if (sa->aad.fs.request & AA_AUDIT_FILE_MASK) { 78 if (sa->aad->fs.request & AA_AUDIT_FILE_MASK) {
79 audit_log_format(ab, " fsuid=%d", fsuid); 79 audit_log_format(ab, " fsuid=%d", fsuid);
80 audit_log_format(ab, " ouid=%d", sa->aad.fs.ouid); 80 audit_log_format(ab, " ouid=%d", sa->aad->fs.ouid);
81 } 81 }
82 82
83 if (sa->aad.fs.target) { 83 if (sa->aad->fs.target) {
84 audit_log_format(ab, " target="); 84 audit_log_format(ab, " target=");
85 audit_log_untrustedstring(ab, sa->aad.fs.target); 85 audit_log_untrustedstring(ab, sa->aad->fs.target);
86 } 86 }
87} 87}
88 88
@@ -107,45 +107,47 @@ int aa_audit_file(struct aa_profile *profile, struct file_perms *perms,
107{ 107{
108 int type = AUDIT_APPARMOR_AUTO; 108 int type = AUDIT_APPARMOR_AUTO;
109 struct common_audit_data sa; 109 struct common_audit_data sa;
110 struct apparmor_audit_data aad = {0,};
110 COMMON_AUDIT_DATA_INIT(&sa, NONE); 111 COMMON_AUDIT_DATA_INIT(&sa, NONE);
111 sa.aad.op = op, 112 sa.aad = &aad;
112 sa.aad.fs.request = request; 113 aad.op = op,
113 sa.aad.name = name; 114 aad.fs.request = request;
114 sa.aad.fs.target = target; 115 aad.name = name;
115 sa.aad.fs.ouid = ouid; 116 aad.fs.target = target;
116 sa.aad.info = info; 117 aad.fs.ouid = ouid;
117 sa.aad.error = error; 118 aad.info = info;
118 119 aad.error = error;
119 if (likely(!sa.aad.error)) { 120
121 if (likely(!sa.aad->error)) {
120 u32 mask = perms->audit; 122 u32 mask = perms->audit;
121 123
122 if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL)) 124 if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL))
123 mask = 0xffff; 125 mask = 0xffff;
124 126
125 /* mask off perms that are not being force audited */ 127 /* mask off perms that are not being force audited */
126 sa.aad.fs.request &= mask; 128 sa.aad->fs.request &= mask;
127 129
128 if (likely(!sa.aad.fs.request)) 130 if (likely(!sa.aad->fs.request))
129 return 0; 131 return 0;
130 type = AUDIT_APPARMOR_AUDIT; 132 type = AUDIT_APPARMOR_AUDIT;
131 } else { 133 } else {
132 /* only report permissions that were denied */ 134 /* only report permissions that were denied */
133 sa.aad.fs.request = sa.aad.fs.request & ~perms->allow; 135 sa.aad->fs.request = sa.aad->fs.request & ~perms->allow;
134 136
135 if (sa.aad.fs.request & perms->kill) 137 if (sa.aad->fs.request & perms->kill)
136 type = AUDIT_APPARMOR_KILL; 138 type = AUDIT_APPARMOR_KILL;
137 139
138 /* quiet known rejects, assumes quiet and kill do not overlap */ 140 /* quiet known rejects, assumes quiet and kill do not overlap */
139 if ((sa.aad.fs.request & perms->quiet) && 141 if ((sa.aad->fs.request & perms->quiet) &&
140 AUDIT_MODE(profile) != AUDIT_NOQUIET && 142 AUDIT_MODE(profile) != AUDIT_NOQUIET &&
141 AUDIT_MODE(profile) != AUDIT_ALL) 143 AUDIT_MODE(profile) != AUDIT_ALL)
142 sa.aad.fs.request &= ~perms->quiet; 144 sa.aad->fs.request &= ~perms->quiet;
143 145
144 if (!sa.aad.fs.request) 146 if (!sa.aad->fs.request)
145 return COMPLAIN_MODE(profile) ? 0 : sa.aad.error; 147 return COMPLAIN_MODE(profile) ? 0 : sa.aad->error;
146 } 148 }
147 149
148 sa.aad.fs.denied = sa.aad.fs.request & ~perms->allow; 150 sa.aad->fs.denied = sa.aad->fs.request & ~perms->allow;
149 return aa_audit(type, profile, gfp, &sa, file_audit_cb); 151 return aa_audit(type, profile, gfp, &sa, file_audit_cb);
150} 152}
151 153
diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h
index 4ba78c203af1..3868b1e5d5ba 100644
--- a/security/apparmor/include/audit.h
+++ b/security/apparmor/include/audit.h
@@ -103,7 +103,33 @@ enum aa_ops {
103}; 103};
104 104
105 105
106/* define a short hand for apparmor_audit_data portion of common_audit_data */ 106struct apparmor_audit_data {
107 int error;
108 int op;
109 int type;
110 void *profile;
111 const char *name;
112 const char *info;
113 union {
114 void *target;
115 struct {
116 long pos;
117 void *target;
118 } iface;
119 struct {
120 int rlim;
121 unsigned long max;
122 } rlim;
123 struct {
124 const char *target;
125 u32 request;
126 u32 denied;
127 uid_t ouid;
128 } fs;
129 };
130};
131
132/* define a short hand for apparmor_audit_data structure */
107#define aad apparmor_audit_data 133#define aad apparmor_audit_data
108 134
109void aa_audit_msg(int type, struct common_audit_data *sa, 135void aa_audit_msg(int type, struct common_audit_data *sa,
diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c
index 7ee05c6f3c64..c3da93a5150d 100644
--- a/security/apparmor/ipc.c
+++ b/security/apparmor/ipc.c
@@ -26,7 +26,7 @@ static void audit_cb(struct audit_buffer *ab, void *va)
26{ 26{
27 struct common_audit_data *sa = va; 27 struct common_audit_data *sa = va;
28 audit_log_format(ab, " target="); 28 audit_log_format(ab, " target=");
29 audit_log_untrustedstring(ab, sa->aad.target); 29 audit_log_untrustedstring(ab, sa->aad->target);
30} 30}
31 31
32/** 32/**
@@ -41,10 +41,12 @@ static int aa_audit_ptrace(struct aa_profile *profile,
41 struct aa_profile *target, int error) 41 struct aa_profile *target, int error)
42{ 42{
43 struct common_audit_data sa; 43 struct common_audit_data sa;
44 struct apparmor_audit_data aad = {0,};
44 COMMON_AUDIT_DATA_INIT(&sa, NONE); 45 COMMON_AUDIT_DATA_INIT(&sa, NONE);
45 sa.aad.op = OP_PTRACE; 46 sa.aad = &aad;
46 sa.aad.target = target; 47 aad.op = OP_PTRACE;
47 sa.aad.error = error; 48 aad.target = target;
49 aad.error = error;
48 50
49 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_ATOMIC, &sa, 51 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_ATOMIC, &sa,
50 audit_cb); 52 audit_cb);
diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c
index 9516948041ad..e75829ba0ff9 100644
--- a/security/apparmor/lib.c
+++ b/security/apparmor/lib.c
@@ -65,8 +65,10 @@ void aa_info_message(const char *str)
65{ 65{
66 if (audit_enabled) { 66 if (audit_enabled) {
67 struct common_audit_data sa; 67 struct common_audit_data sa;
68 struct apparmor_audit_data aad = {0,};
68 COMMON_AUDIT_DATA_INIT(&sa, NONE); 69 COMMON_AUDIT_DATA_INIT(&sa, NONE);
69 sa.aad.info = str; 70 sa.aad = &aad;
71 aad.info = str;
70 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL); 72 aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL);
71 } 73 }
72 printk(KERN_INFO "AppArmor: %s\n", str); 74 printk(KERN_INFO "AppArmor: %s\n", str);
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 97ce8fae49b3..ad05d391974d 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -588,10 +588,12 @@ static int apparmor_setprocattr(struct task_struct *task, char *name,
588 error = aa_setprocattr_permipc(args); 588 error = aa_setprocattr_permipc(args);
589 } else { 589 } else {
590 struct common_audit_data sa; 590 struct common_audit_data sa;
591 struct apparmor_audit_data aad = {0,};
591 COMMON_AUDIT_DATA_INIT(&sa, NONE); 592 COMMON_AUDIT_DATA_INIT(&sa, NONE);
592 sa.aad.op = OP_SETPROCATTR; 593 sa.aad = &aad;
593 sa.aad.info = name; 594 aad.op = OP_SETPROCATTR;
594 sa.aad.error = -EINVAL; 595 aad.info = name;
596 aad.error = -EINVAL;
595 return aa_audit(AUDIT_APPARMOR_DENIED, 597 return aa_audit(AUDIT_APPARMOR_DENIED,
596 __aa_current_profile(), GFP_KERNEL, 598 __aa_current_profile(), GFP_KERNEL,
597 &sa, NULL); 599 &sa, NULL);
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 906414383022..f1f7506a464d 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -964,11 +964,13 @@ static int audit_policy(int op, gfp_t gfp, const char *name, const char *info,
964 int error) 964 int error)
965{ 965{
966 struct common_audit_data sa; 966 struct common_audit_data sa;
967 struct apparmor_audit_data aad = {0,};
967 COMMON_AUDIT_DATA_INIT(&sa, NONE); 968 COMMON_AUDIT_DATA_INIT(&sa, NONE);
968 sa.aad.op = op; 969 sa.aad = &aad;
969 sa.aad.name = name; 970 aad.op = op;
970 sa.aad.info = info; 971 aad.name = name;
971 sa.aad.error = error; 972 aad.info = info;
973 aad.error = error;
972 974
973 return aa_audit(AUDIT_APPARMOR_STATUS, __aa_current_profile(), gfp, 975 return aa_audit(AUDIT_APPARMOR_STATUS, __aa_current_profile(), gfp,
974 &sa, NULL); 976 &sa, NULL);
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index 25fd51edc8da..deab7c7e8dc0 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -70,13 +70,13 @@ struct aa_ext {
70static void audit_cb(struct audit_buffer *ab, void *va) 70static void audit_cb(struct audit_buffer *ab, void *va)
71{ 71{
72 struct common_audit_data *sa = va; 72 struct common_audit_data *sa = va;
73 if (sa->aad.iface.target) { 73 if (sa->aad->iface.target) {
74 struct aa_profile *name = sa->aad.iface.target; 74 struct aa_profile *name = sa->aad->iface.target;
75 audit_log_format(ab, " name="); 75 audit_log_format(ab, " name=");
76 audit_log_untrustedstring(ab, name->base.hname); 76 audit_log_untrustedstring(ab, name->base.hname);
77 } 77 }
78 if (sa->aad.iface.pos) 78 if (sa->aad->iface.pos)
79 audit_log_format(ab, " offset=%ld", sa->aad.iface.pos); 79 audit_log_format(ab, " offset=%ld", sa->aad->iface.pos);
80} 80}
81 81
82/** 82/**
@@ -94,13 +94,15 @@ static int audit_iface(struct aa_profile *new, const char *name,
94{ 94{
95 struct aa_profile *profile = __aa_current_profile(); 95 struct aa_profile *profile = __aa_current_profile();
96 struct common_audit_data sa; 96 struct common_audit_data sa;
97 struct apparmor_audit_data aad = {0,};
97 COMMON_AUDIT_DATA_INIT(&sa, NONE); 98 COMMON_AUDIT_DATA_INIT(&sa, NONE);
99 sa.aad = &aad;
98 if (e) 100 if (e)
99 sa.aad.iface.pos = e->pos - e->start; 101 aad.iface.pos = e->pos - e->start;
100 sa.aad.iface.target = new; 102 aad.iface.target = new;
101 sa.aad.name = name; 103 aad.name = name;
102 sa.aad.info = info; 104 aad.info = info;
103 sa.aad.error = error; 105 aad.error = error;
104 106
105 return aa_audit(AUDIT_APPARMOR_STATUS, profile, GFP_KERNEL, &sa, 107 return aa_audit(AUDIT_APPARMOR_STATUS, profile, GFP_KERNEL, &sa,
106 audit_cb); 108 audit_cb);
diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c
index 72c25a4f2cfd..2fe8613efe33 100644
--- a/security/apparmor/resource.c
+++ b/security/apparmor/resource.c
@@ -34,7 +34,7 @@ static void audit_cb(struct audit_buffer *ab, void *va)
34 struct common_audit_data *sa = va; 34 struct common_audit_data *sa = va;
35 35
36 audit_log_format(ab, " rlimit=%s value=%lu", 36 audit_log_format(ab, " rlimit=%s value=%lu",
37 rlim_names[sa->aad.rlim.rlim], sa->aad.rlim.max); 37 rlim_names[sa->aad->rlim.rlim], sa->aad->rlim.max);
38} 38}
39 39
40/** 40/**
@@ -50,12 +50,14 @@ static int audit_resource(struct aa_profile *profile, unsigned int resource,
50 unsigned long value, int error) 50 unsigned long value, int error)
51{ 51{
52 struct common_audit_data sa; 52 struct common_audit_data sa;
53 struct apparmor_audit_data aad = {0,};
53 54
54 COMMON_AUDIT_DATA_INIT(&sa, NONE); 55 COMMON_AUDIT_DATA_INIT(&sa, NONE);
55 sa.aad.op = OP_SETRLIMIT, 56 sa.aad = &aad;
56 sa.aad.rlim.rlim = resource; 57 aad.op = OP_SETRLIMIT,
57 sa.aad.rlim.max = value; 58 aad.rlim.rlim = resource;
58 sa.aad.error = error; 59 aad.rlim.max = value;
60 aad.error = error;
59 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_KERNEL, &sa, 61 return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_KERNEL, &sa,
60 audit_cb); 62 audit_cb);
61} 63}
diff --git a/security/commoncap.c b/security/commoncap.c
index 0cf4b53480a7..71a166a05975 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -29,6 +29,7 @@
29#include <linux/securebits.h> 29#include <linux/securebits.h>
30#include <linux/user_namespace.h> 30#include <linux/user_namespace.h>
31#include <linux/binfmts.h> 31#include <linux/binfmts.h>
32#include <linux/personality.h>
32 33
33/* 34/*
34 * If a non-root user executes a setuid-root binary in 35 * If a non-root user executes a setuid-root binary in
@@ -505,6 +506,11 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
505 } 506 }
506skip: 507skip:
507 508
509 /* if we have fs caps, clear dangerous personality flags */
510 if (!cap_issubset(new->cap_permitted, old->cap_permitted))
511 bprm->per_clear |= PER_CLEAR_ON_SETID;
512
513
508 /* Don't let someone trace a set[ug]id/setpcap binary with the revised 514 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
509 * credentials unless they have the appropriate permit 515 * credentials unless they have the appropriate permit
510 */ 516 */
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 8b8f0902f6e5..90c129b0102f 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -49,8 +49,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
49 if (ih == NULL) 49 if (ih == NULL)
50 return -EINVAL; 50 return -EINVAL;
51 51
52 ad->u.net.v4info.saddr = ih->saddr; 52 ad->u.net->v4info.saddr = ih->saddr;
53 ad->u.net.v4info.daddr = ih->daddr; 53 ad->u.net->v4info.daddr = ih->daddr;
54 54
55 if (proto) 55 if (proto)
56 *proto = ih->protocol; 56 *proto = ih->protocol;
@@ -64,8 +64,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
64 if (th == NULL) 64 if (th == NULL)
65 break; 65 break;
66 66
67 ad->u.net.sport = th->source; 67 ad->u.net->sport = th->source;
68 ad->u.net.dport = th->dest; 68 ad->u.net->dport = th->dest;
69 break; 69 break;
70 } 70 }
71 case IPPROTO_UDP: { 71 case IPPROTO_UDP: {
@@ -73,8 +73,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
73 if (uh == NULL) 73 if (uh == NULL)
74 break; 74 break;
75 75
76 ad->u.net.sport = uh->source; 76 ad->u.net->sport = uh->source;
77 ad->u.net.dport = uh->dest; 77 ad->u.net->dport = uh->dest;
78 break; 78 break;
79 } 79 }
80 case IPPROTO_DCCP: { 80 case IPPROTO_DCCP: {
@@ -82,16 +82,16 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
82 if (dh == NULL) 82 if (dh == NULL)
83 break; 83 break;
84 84
85 ad->u.net.sport = dh->dccph_sport; 85 ad->u.net->sport = dh->dccph_sport;
86 ad->u.net.dport = dh->dccph_dport; 86 ad->u.net->dport = dh->dccph_dport;
87 break; 87 break;
88 } 88 }
89 case IPPROTO_SCTP: { 89 case IPPROTO_SCTP: {
90 struct sctphdr *sh = sctp_hdr(skb); 90 struct sctphdr *sh = sctp_hdr(skb);
91 if (sh == NULL) 91 if (sh == NULL)
92 break; 92 break;
93 ad->u.net.sport = sh->source; 93 ad->u.net->sport = sh->source;
94 ad->u.net.dport = sh->dest; 94 ad->u.net->dport = sh->dest;
95 break; 95 break;
96 } 96 }
97 default: 97 default:
@@ -119,8 +119,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
119 ip6 = ipv6_hdr(skb); 119 ip6 = ipv6_hdr(skb);
120 if (ip6 == NULL) 120 if (ip6 == NULL)
121 return -EINVAL; 121 return -EINVAL;
122 ad->u.net.v6info.saddr = ip6->saddr; 122 ad->u.net->v6info.saddr = ip6->saddr;
123 ad->u.net.v6info.daddr = ip6->daddr; 123 ad->u.net->v6info.daddr = ip6->daddr;
124 ret = 0; 124 ret = 0;
125 /* IPv6 can have several extension header before the Transport header 125 /* IPv6 can have several extension header before the Transport header
126 * skip them */ 126 * skip them */
@@ -140,8 +140,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
140 if (th == NULL) 140 if (th == NULL)
141 break; 141 break;
142 142
143 ad->u.net.sport = th->source; 143 ad->u.net->sport = th->source;
144 ad->u.net.dport = th->dest; 144 ad->u.net->dport = th->dest;
145 break; 145 break;
146 } 146 }
147 case IPPROTO_UDP: { 147 case IPPROTO_UDP: {
@@ -151,8 +151,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
151 if (uh == NULL) 151 if (uh == NULL)
152 break; 152 break;
153 153
154 ad->u.net.sport = uh->source; 154 ad->u.net->sport = uh->source;
155 ad->u.net.dport = uh->dest; 155 ad->u.net->dport = uh->dest;
156 break; 156 break;
157 } 157 }
158 case IPPROTO_DCCP: { 158 case IPPROTO_DCCP: {
@@ -162,8 +162,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
162 if (dh == NULL) 162 if (dh == NULL)
163 break; 163 break;
164 164
165 ad->u.net.sport = dh->dccph_sport; 165 ad->u.net->sport = dh->dccph_sport;
166 ad->u.net.dport = dh->dccph_dport; 166 ad->u.net->dport = dh->dccph_dport;
167 break; 167 break;
168 } 168 }
169 case IPPROTO_SCTP: { 169 case IPPROTO_SCTP: {
@@ -172,8 +172,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
172 sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph); 172 sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph);
173 if (sh == NULL) 173 if (sh == NULL)
174 break; 174 break;
175 ad->u.net.sport = sh->source; 175 ad->u.net->sport = sh->source;
176 ad->u.net.dport = sh->dest; 176 ad->u.net->dport = sh->dest;
177 break; 177 break;
178 } 178 }
179 default: 179 default:
@@ -281,8 +281,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
281 } 281 }
282 break; 282 break;
283 case LSM_AUDIT_DATA_NET: 283 case LSM_AUDIT_DATA_NET:
284 if (a->u.net.sk) { 284 if (a->u.net->sk) {
285 struct sock *sk = a->u.net.sk; 285 struct sock *sk = a->u.net->sk;
286 struct unix_sock *u; 286 struct unix_sock *u;
287 int len = 0; 287 int len = 0;
288 char *p = NULL; 288 char *p = NULL;
@@ -330,29 +330,29 @@ static void dump_common_audit_data(struct audit_buffer *ab,
330 } 330 }
331 } 331 }
332 332
333 switch (a->u.net.family) { 333 switch (a->u.net->family) {
334 case AF_INET: 334 case AF_INET:
335 print_ipv4_addr(ab, a->u.net.v4info.saddr, 335 print_ipv4_addr(ab, a->u.net->v4info.saddr,
336 a->u.net.sport, 336 a->u.net->sport,
337 "saddr", "src"); 337 "saddr", "src");
338 print_ipv4_addr(ab, a->u.net.v4info.daddr, 338 print_ipv4_addr(ab, a->u.net->v4info.daddr,
339 a->u.net.dport, 339 a->u.net->dport,
340 "daddr", "dest"); 340 "daddr", "dest");
341 break; 341 break;
342 case AF_INET6: 342 case AF_INET6:
343 print_ipv6_addr(ab, &a->u.net.v6info.saddr, 343 print_ipv6_addr(ab, &a->u.net->v6info.saddr,
344 a->u.net.sport, 344 a->u.net->sport,
345 "saddr", "src"); 345 "saddr", "src");
346 print_ipv6_addr(ab, &a->u.net.v6info.daddr, 346 print_ipv6_addr(ab, &a->u.net->v6info.daddr,
347 a->u.net.dport, 347 a->u.net->dport,
348 "daddr", "dest"); 348 "daddr", "dest");
349 break; 349 break;
350 } 350 }
351 if (a->u.net.netif > 0) { 351 if (a->u.net->netif > 0) {
352 struct net_device *dev; 352 struct net_device *dev;
353 353
354 /* NOTE: we always use init's namespace */ 354 /* NOTE: we always use init's namespace */
355 dev = dev_get_by_index(&init_net, a->u.net.netif); 355 dev = dev_get_by_index(&init_net, a->u.net->netif);
356 if (dev) { 356 if (dev) {
357 audit_log_format(ab, " netif=%s", dev->name); 357 audit_log_format(ab, " netif=%s", dev->name);
358 dev_put(dev); 358 dev_put(dev);
@@ -378,11 +378,15 @@ static void dump_common_audit_data(struct audit_buffer *ab,
378/** 378/**
379 * common_lsm_audit - generic LSM auditing function 379 * common_lsm_audit - generic LSM auditing function
380 * @a: auxiliary audit data 380 * @a: auxiliary audit data
381 * @pre_audit: lsm-specific pre-audit callback
382 * @post_audit: lsm-specific post-audit callback
381 * 383 *
382 * setup the audit buffer for common security information 384 * setup the audit buffer for common security information
383 * uses callback to print LSM specific information 385 * uses callback to print LSM specific information
384 */ 386 */
385void common_lsm_audit(struct common_audit_data *a) 387void common_lsm_audit(struct common_audit_data *a,
388 void (*pre_audit)(struct audit_buffer *, void *),
389 void (*post_audit)(struct audit_buffer *, void *))
386{ 390{
387 struct audit_buffer *ab; 391 struct audit_buffer *ab;
388 392
@@ -394,13 +398,13 @@ void common_lsm_audit(struct common_audit_data *a)
394 if (ab == NULL) 398 if (ab == NULL)
395 return; 399 return;
396 400
397 if (a->lsm_pre_audit) 401 if (pre_audit)
398 a->lsm_pre_audit(ab, a); 402 pre_audit(ab, a);
399 403
400 dump_common_audit_data(ab, a); 404 dump_common_audit_data(ab, a);
401 405
402 if (a->lsm_post_audit) 406 if (post_audit)
403 a->lsm_post_audit(ab, a); 407 post_audit(ab, a);
404 408
405 audit_log_end(ab); 409 audit_log_end(ab);
406} 410}
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 1a70fa26da72..8ee42b2a5f19 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,22 +452,25 @@ 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 */
461static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass, 461static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
462 u32 requested, u32 audited, u32 denied, 462 u32 requested, u32 audited, u32 denied,
463 struct av_decision *avd, struct common_audit_data *a, 463 struct common_audit_data *a,
464 unsigned flags) 464 unsigned flags)
465{ 465{
466 struct common_audit_data stack_data; 466 struct common_audit_data stack_data;
467 struct selinux_audit_data sad = {0,};
468 struct selinux_late_audit_data slad;
467 469
468 if (!a) { 470 if (!a) {
469 a = &stack_data; 471 a = &stack_data;
470 COMMON_AUDIT_DATA_INIT(a, NONE); 472 COMMON_AUDIT_DATA_INIT(a, NONE);
473 a->selinux_audit_data = &sad;
471 } 474 }
472 475
473 /* 476 /*
@@ -481,15 +484,15 @@ static noinline int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
481 (flags & MAY_NOT_BLOCK)) 484 (flags & MAY_NOT_BLOCK))
482 return -ECHILD; 485 return -ECHILD;
483 486
484 a->selinux_audit_data.tclass = tclass; 487 slad.tclass = tclass;
485 a->selinux_audit_data.requested = requested; 488 slad.requested = requested;
486 a->selinux_audit_data.ssid = ssid; 489 slad.ssid = ssid;
487 a->selinux_audit_data.tsid = tsid; 490 slad.tsid = tsid;
488 a->selinux_audit_data.audited = audited; 491 slad.audited = audited;
489 a->selinux_audit_data.denied = denied; 492 slad.denied = denied;
490 a->lsm_pre_audit = avc_audit_pre_callback; 493
491 a->lsm_post_audit = avc_audit_post_callback; 494 a->selinux_audit_data->slad = &slad;
492 common_lsm_audit(a); 495 common_lsm_audit(a, avc_audit_pre_callback, avc_audit_post_callback);
493 return 0; 496 return 0;
494} 497}
495 498
@@ -523,7 +526,7 @@ inline int avc_audit(u32 ssid, u32 tsid,
523 if (unlikely(denied)) { 526 if (unlikely(denied)) {
524 audited = denied & avd->auditdeny; 527 audited = denied & avd->auditdeny;
525 /* 528 /*
526 * a->selinux_audit_data.auditdeny is TRICKY! Setting a bit in 529 * a->selinux_audit_data->auditdeny is TRICKY! Setting a bit in
527 * this field means that ANY denials should NOT be audited if 530 * this field means that ANY denials should NOT be audited if
528 * the policy contains an explicit dontaudit rule for that 531 * the policy contains an explicit dontaudit rule for that
529 * permission. Take notice that this is unrelated to the 532 * permission. Take notice that this is unrelated to the
@@ -532,15 +535,15 @@ inline int avc_audit(u32 ssid, u32 tsid,
532 * 535 *
533 * denied == READ 536 * denied == READ
534 * avd.auditdeny & ACCESS == 0 (not set means explicit rule) 537 * avd.auditdeny & ACCESS == 0 (not set means explicit rule)
535 * selinux_audit_data.auditdeny & ACCESS == 1 538 * selinux_audit_data->auditdeny & ACCESS == 1
536 * 539 *
537 * We will NOT audit the denial even though the denied 540 * We will NOT audit the denial even though the denied
538 * permission was READ and the auditdeny checks were for 541 * permission was READ and the auditdeny checks were for
539 * ACCESS 542 * ACCESS
540 */ 543 */
541 if (a && 544 if (a &&
542 a->selinux_audit_data.auditdeny && 545 a->selinux_audit_data->auditdeny &&
543 !(a->selinux_audit_data.auditdeny & avd->auditdeny)) 546 !(a->selinux_audit_data->auditdeny & avd->auditdeny))
544 audited = 0; 547 audited = 0;
545 } else if (result) 548 } else if (result)
546 audited = denied = requested; 549 audited = denied = requested;
@@ -551,7 +554,7 @@ inline int avc_audit(u32 ssid, u32 tsid,
551 554
552 return slow_avc_audit(ssid, tsid, tclass, 555 return slow_avc_audit(ssid, tsid, tclass,
553 requested, audited, denied, 556 requested, audited, denied,
554 avd, a, flags); 557 a, flags);
555} 558}
556 559
557/** 560/**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 28482f9e15b8..d85b793c9321 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1420,6 +1420,7 @@ static int cred_has_capability(const struct cred *cred,
1420 int cap, int audit) 1420 int cap, int audit)
1421{ 1421{
1422 struct common_audit_data ad; 1422 struct common_audit_data ad;
1423 struct selinux_audit_data sad = {0,};
1423 struct av_decision avd; 1424 struct av_decision avd;
1424 u16 sclass; 1425 u16 sclass;
1425 u32 sid = cred_sid(cred); 1426 u32 sid = cred_sid(cred);
@@ -1427,6 +1428,7 @@ static int cred_has_capability(const struct cred *cred,
1427 int rc; 1428 int rc;
1428 1429
1429 COMMON_AUDIT_DATA_INIT(&ad, CAP); 1430 COMMON_AUDIT_DATA_INIT(&ad, CAP);
1431 ad.selinux_audit_data = &sad;
1430 ad.tsk = current; 1432 ad.tsk = current;
1431 ad.u.cap = cap; 1433 ad.u.cap = cap;
1432 1434
@@ -1492,9 +1494,11 @@ static int inode_has_perm_noadp(const struct cred *cred,
1492 unsigned flags) 1494 unsigned flags)
1493{ 1495{
1494 struct common_audit_data ad; 1496 struct common_audit_data ad;
1497 struct selinux_audit_data sad = {0,};
1495 1498
1496 COMMON_AUDIT_DATA_INIT(&ad, INODE); 1499 COMMON_AUDIT_DATA_INIT(&ad, INODE);
1497 ad.u.inode = inode; 1500 ad.u.inode = inode;
1501 ad.selinux_audit_data = &sad;
1498 return inode_has_perm(cred, inode, perms, &ad, flags); 1502 return inode_has_perm(cred, inode, perms, &ad, flags);
1499} 1503}
1500 1504
@@ -1507,9 +1511,11 @@ static inline int dentry_has_perm(const struct cred *cred,
1507{ 1511{
1508 struct inode *inode = dentry->d_inode; 1512 struct inode *inode = dentry->d_inode;
1509 struct common_audit_data ad; 1513 struct common_audit_data ad;
1514 struct selinux_audit_data sad = {0,};
1510 1515
1511 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1516 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1512 ad.u.dentry = dentry; 1517 ad.u.dentry = dentry;
1518 ad.selinux_audit_data = &sad;
1513 return inode_has_perm(cred, inode, av, &ad, 0); 1519 return inode_has_perm(cred, inode, av, &ad, 0);
1514} 1520}
1515 1521
@@ -1522,9 +1528,11 @@ static inline int path_has_perm(const struct cred *cred,
1522{ 1528{
1523 struct inode *inode = path->dentry->d_inode; 1529 struct inode *inode = path->dentry->d_inode;
1524 struct common_audit_data ad; 1530 struct common_audit_data ad;
1531 struct selinux_audit_data sad = {0,};
1525 1532
1526 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1533 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1527 ad.u.path = *path; 1534 ad.u.path = *path;
1535 ad.selinux_audit_data = &sad;
1528 return inode_has_perm(cred, inode, av, &ad, 0); 1536 return inode_has_perm(cred, inode, av, &ad, 0);
1529} 1537}
1530 1538
@@ -1543,11 +1551,13 @@ static int file_has_perm(const struct cred *cred,
1543 struct file_security_struct *fsec = file->f_security; 1551 struct file_security_struct *fsec = file->f_security;
1544 struct inode *inode = file->f_path.dentry->d_inode; 1552 struct inode *inode = file->f_path.dentry->d_inode;
1545 struct common_audit_data ad; 1553 struct common_audit_data ad;
1554 struct selinux_audit_data sad = {0,};
1546 u32 sid = cred_sid(cred); 1555 u32 sid = cred_sid(cred);
1547 int rc; 1556 int rc;
1548 1557
1549 COMMON_AUDIT_DATA_INIT(&ad, PATH); 1558 COMMON_AUDIT_DATA_INIT(&ad, PATH);
1550 ad.u.path = file->f_path; 1559 ad.u.path = file->f_path;
1560 ad.selinux_audit_data = &sad;
1551 1561
1552 if (sid != fsec->sid) { 1562 if (sid != fsec->sid) {
1553 rc = avc_has_perm(sid, fsec->sid, 1563 rc = avc_has_perm(sid, fsec->sid,
@@ -1577,6 +1587,7 @@ static int may_create(struct inode *dir,
1577 struct superblock_security_struct *sbsec; 1587 struct superblock_security_struct *sbsec;
1578 u32 sid, newsid; 1588 u32 sid, newsid;
1579 struct common_audit_data ad; 1589 struct common_audit_data ad;
1590 struct selinux_audit_data sad = {0,};
1580 int rc; 1591 int rc;
1581 1592
1582 dsec = dir->i_security; 1593 dsec = dir->i_security;
@@ -1587,6 +1598,7 @@ static int may_create(struct inode *dir,
1587 1598
1588 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1599 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1589 ad.u.dentry = dentry; 1600 ad.u.dentry = dentry;
1601 ad.selinux_audit_data = &sad;
1590 1602
1591 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR, 1603 rc = avc_has_perm(sid, dsec->sid, SECCLASS_DIR,
1592 DIR__ADD_NAME | DIR__SEARCH, 1604 DIR__ADD_NAME | DIR__SEARCH,
@@ -1631,6 +1643,7 @@ static int may_link(struct inode *dir,
1631{ 1643{
1632 struct inode_security_struct *dsec, *isec; 1644 struct inode_security_struct *dsec, *isec;
1633 struct common_audit_data ad; 1645 struct common_audit_data ad;
1646 struct selinux_audit_data sad = {0,};
1634 u32 sid = current_sid(); 1647 u32 sid = current_sid();
1635 u32 av; 1648 u32 av;
1636 int rc; 1649 int rc;
@@ -1640,6 +1653,7 @@ static int may_link(struct inode *dir,
1640 1653
1641 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1654 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1642 ad.u.dentry = dentry; 1655 ad.u.dentry = dentry;
1656 ad.selinux_audit_data = &sad;
1643 1657
1644 av = DIR__SEARCH; 1658 av = DIR__SEARCH;
1645 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME); 1659 av |= (kind ? DIR__REMOVE_NAME : DIR__ADD_NAME);
@@ -1674,6 +1688,7 @@ static inline int may_rename(struct inode *old_dir,
1674{ 1688{
1675 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec; 1689 struct inode_security_struct *old_dsec, *new_dsec, *old_isec, *new_isec;
1676 struct common_audit_data ad; 1690 struct common_audit_data ad;
1691 struct selinux_audit_data sad = {0,};
1677 u32 sid = current_sid(); 1692 u32 sid = current_sid();
1678 u32 av; 1693 u32 av;
1679 int old_is_dir, new_is_dir; 1694 int old_is_dir, new_is_dir;
@@ -1685,6 +1700,7 @@ static inline int may_rename(struct inode *old_dir,
1685 new_dsec = new_dir->i_security; 1700 new_dsec = new_dir->i_security;
1686 1701
1687 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 1702 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
1703 ad.selinux_audit_data = &sad;
1688 1704
1689 ad.u.dentry = old_dentry; 1705 ad.u.dentry = old_dentry;
1690 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR, 1706 rc = avc_has_perm(sid, old_dsec->sid, SECCLASS_DIR,
@@ -1970,6 +1986,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
1970 struct task_security_struct *new_tsec; 1986 struct task_security_struct *new_tsec;
1971 struct inode_security_struct *isec; 1987 struct inode_security_struct *isec;
1972 struct common_audit_data ad; 1988 struct common_audit_data ad;
1989 struct selinux_audit_data sad = {0,};
1973 struct inode *inode = bprm->file->f_path.dentry->d_inode; 1990 struct inode *inode = bprm->file->f_path.dentry->d_inode;
1974 int rc; 1991 int rc;
1975 1992
@@ -2009,6 +2026,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
2009 } 2026 }
2010 2027
2011 COMMON_AUDIT_DATA_INIT(&ad, PATH); 2028 COMMON_AUDIT_DATA_INIT(&ad, PATH);
2029 ad.selinux_audit_data = &sad;
2012 ad.u.path = bprm->file->f_path; 2030 ad.u.path = bprm->file->f_path;
2013 2031
2014 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID) 2032 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
@@ -2098,6 +2116,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2098 struct files_struct *files) 2116 struct files_struct *files)
2099{ 2117{
2100 struct common_audit_data ad; 2118 struct common_audit_data ad;
2119 struct selinux_audit_data sad = {0,};
2101 struct file *file, *devnull = NULL; 2120 struct file *file, *devnull = NULL;
2102 struct tty_struct *tty; 2121 struct tty_struct *tty;
2103 struct fdtable *fdt; 2122 struct fdtable *fdt;
@@ -2135,6 +2154,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2135 /* Revalidate access to inherited open files. */ 2154 /* Revalidate access to inherited open files. */
2136 2155
2137 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2156 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2157 ad.selinux_audit_data = &sad;
2138 2158
2139 spin_lock(&files->file_lock); 2159 spin_lock(&files->file_lock);
2140 for (;;) { 2160 for (;;) {
@@ -2472,6 +2492,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2472{ 2492{
2473 const struct cred *cred = current_cred(); 2493 const struct cred *cred = current_cred();
2474 struct common_audit_data ad; 2494 struct common_audit_data ad;
2495 struct selinux_audit_data sad = {0,};
2475 int rc; 2496 int rc;
2476 2497
2477 rc = superblock_doinit(sb, data); 2498 rc = superblock_doinit(sb, data);
@@ -2483,6 +2504,7 @@ static int selinux_sb_kern_mount(struct super_block *sb, int flags, void *data)
2483 return 0; 2504 return 0;
2484 2505
2485 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2506 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2507 ad.selinux_audit_data = &sad;
2486 ad.u.dentry = sb->s_root; 2508 ad.u.dentry = sb->s_root;
2487 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad); 2509 return superblock_has_perm(cred, sb, FILESYSTEM__MOUNT, &ad);
2488} 2510}
@@ -2491,8 +2513,10 @@ static int selinux_sb_statfs(struct dentry *dentry)
2491{ 2513{
2492 const struct cred *cred = current_cred(); 2514 const struct cred *cred = current_cred();
2493 struct common_audit_data ad; 2515 struct common_audit_data ad;
2516 struct selinux_audit_data sad = {0,};
2494 2517
2495 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2518 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2519 ad.selinux_audit_data = &sad;
2496 ad.u.dentry = dentry->d_sb->s_root; 2520 ad.u.dentry = dentry->d_sb->s_root;
2497 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad); 2521 return superblock_has_perm(cred, dentry->d_sb, FILESYSTEM__GETATTR, &ad);
2498} 2522}
@@ -2656,6 +2680,7 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2656{ 2680{
2657 const struct cred *cred = current_cred(); 2681 const struct cred *cred = current_cred();
2658 struct common_audit_data ad; 2682 struct common_audit_data ad;
2683 struct selinux_audit_data sad = {0,};
2659 u32 perms; 2684 u32 perms;
2660 bool from_access; 2685 bool from_access;
2661 unsigned flags = mask & MAY_NOT_BLOCK; 2686 unsigned flags = mask & MAY_NOT_BLOCK;
@@ -2668,10 +2693,11 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2668 return 0; 2693 return 0;
2669 2694
2670 COMMON_AUDIT_DATA_INIT(&ad, INODE); 2695 COMMON_AUDIT_DATA_INIT(&ad, INODE);
2696 ad.selinux_audit_data = &sad;
2671 ad.u.inode = inode; 2697 ad.u.inode = inode;
2672 2698
2673 if (from_access) 2699 if (from_access)
2674 ad.selinux_audit_data.auditdeny |= FILE__AUDIT_ACCESS; 2700 ad.selinux_audit_data->auditdeny |= FILE__AUDIT_ACCESS;
2675 2701
2676 perms = file_mask_to_av(inode->i_mode, mask); 2702 perms = file_mask_to_av(inode->i_mode, mask);
2677 2703
@@ -2737,6 +2763,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2737 struct inode_security_struct *isec = inode->i_security; 2763 struct inode_security_struct *isec = inode->i_security;
2738 struct superblock_security_struct *sbsec; 2764 struct superblock_security_struct *sbsec;
2739 struct common_audit_data ad; 2765 struct common_audit_data ad;
2766 struct selinux_audit_data sad = {0,};
2740 u32 newsid, sid = current_sid(); 2767 u32 newsid, sid = current_sid();
2741 int rc = 0; 2768 int rc = 0;
2742 2769
@@ -2751,6 +2778,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2751 return -EPERM; 2778 return -EPERM;
2752 2779
2753 COMMON_AUDIT_DATA_INIT(&ad, DENTRY); 2780 COMMON_AUDIT_DATA_INIT(&ad, DENTRY);
2781 ad.selinux_audit_data = &sad;
2754 ad.u.dentry = dentry; 2782 ad.u.dentry = dentry;
2755 2783
2756 rc = avc_has_perm(sid, isec->sid, isec->sclass, 2784 rc = avc_has_perm(sid, isec->sid, isec->sclass,
@@ -3345,10 +3373,12 @@ static int selinux_kernel_module_request(char *kmod_name)
3345{ 3373{
3346 u32 sid; 3374 u32 sid;
3347 struct common_audit_data ad; 3375 struct common_audit_data ad;
3376 struct selinux_audit_data sad = {0,};
3348 3377
3349 sid = task_sid(current); 3378 sid = task_sid(current);
3350 3379
3351 COMMON_AUDIT_DATA_INIT(&ad, KMOD); 3380 COMMON_AUDIT_DATA_INIT(&ad, KMOD);
3381 ad.selinux_audit_data = &sad;
3352 ad.u.kmod_name = kmod_name; 3382 ad.u.kmod_name = kmod_name;
3353 3383
3354 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM, 3384 return avc_has_perm(sid, SECINITSID_KERNEL, SECCLASS_SYSTEM,
@@ -3487,8 +3517,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3487 if (ihlen < sizeof(_iph)) 3517 if (ihlen < sizeof(_iph))
3488 goto out; 3518 goto out;
3489 3519
3490 ad->u.net.v4info.saddr = ih->saddr; 3520 ad->u.net->v4info.saddr = ih->saddr;
3491 ad->u.net.v4info.daddr = ih->daddr; 3521 ad->u.net->v4info.daddr = ih->daddr;
3492 ret = 0; 3522 ret = 0;
3493 3523
3494 if (proto) 3524 if (proto)
@@ -3506,8 +3536,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3506 if (th == NULL) 3536 if (th == NULL)
3507 break; 3537 break;
3508 3538
3509 ad->u.net.sport = th->source; 3539 ad->u.net->sport = th->source;
3510 ad->u.net.dport = th->dest; 3540 ad->u.net->dport = th->dest;
3511 break; 3541 break;
3512 } 3542 }
3513 3543
@@ -3522,8 +3552,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3522 if (uh == NULL) 3552 if (uh == NULL)
3523 break; 3553 break;
3524 3554
3525 ad->u.net.sport = uh->source; 3555 ad->u.net->sport = uh->source;
3526 ad->u.net.dport = uh->dest; 3556 ad->u.net->dport = uh->dest;
3527 break; 3557 break;
3528 } 3558 }
3529 3559
@@ -3538,8 +3568,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
3538 if (dh == NULL) 3568 if (dh == NULL)
3539 break; 3569 break;
3540 3570
3541 ad->u.net.sport = dh->dccph_sport; 3571 ad->u.net->sport = dh->dccph_sport;
3542 ad->u.net.dport = dh->dccph_dport; 3572 ad->u.net->dport = dh->dccph_dport;
3543 break; 3573 break;
3544 } 3574 }
3545 3575
@@ -3566,8 +3596,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3566 if (ip6 == NULL) 3596 if (ip6 == NULL)
3567 goto out; 3597 goto out;
3568 3598
3569 ad->u.net.v6info.saddr = ip6->saddr; 3599 ad->u.net->v6info.saddr = ip6->saddr;
3570 ad->u.net.v6info.daddr = ip6->daddr; 3600 ad->u.net->v6info.daddr = ip6->daddr;
3571 ret = 0; 3601 ret = 0;
3572 3602
3573 nexthdr = ip6->nexthdr; 3603 nexthdr = ip6->nexthdr;
@@ -3587,8 +3617,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3587 if (th == NULL) 3617 if (th == NULL)
3588 break; 3618 break;
3589 3619
3590 ad->u.net.sport = th->source; 3620 ad->u.net->sport = th->source;
3591 ad->u.net.dport = th->dest; 3621 ad->u.net->dport = th->dest;
3592 break; 3622 break;
3593 } 3623 }
3594 3624
@@ -3599,8 +3629,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3599 if (uh == NULL) 3629 if (uh == NULL)
3600 break; 3630 break;
3601 3631
3602 ad->u.net.sport = uh->source; 3632 ad->u.net->sport = uh->source;
3603 ad->u.net.dport = uh->dest; 3633 ad->u.net->dport = uh->dest;
3604 break; 3634 break;
3605 } 3635 }
3606 3636
@@ -3611,8 +3641,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
3611 if (dh == NULL) 3641 if (dh == NULL)
3612 break; 3642 break;
3613 3643
3614 ad->u.net.sport = dh->dccph_sport; 3644 ad->u.net->sport = dh->dccph_sport;
3615 ad->u.net.dport = dh->dccph_dport; 3645 ad->u.net->dport = dh->dccph_dport;
3616 break; 3646 break;
3617 } 3647 }
3618 3648
@@ -3632,13 +3662,13 @@ static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
3632 char *addrp; 3662 char *addrp;
3633 int ret; 3663 int ret;
3634 3664
3635 switch (ad->u.net.family) { 3665 switch (ad->u.net->family) {
3636 case PF_INET: 3666 case PF_INET:
3637 ret = selinux_parse_skb_ipv4(skb, ad, proto); 3667 ret = selinux_parse_skb_ipv4(skb, ad, proto);
3638 if (ret) 3668 if (ret)
3639 goto parse_error; 3669 goto parse_error;
3640 addrp = (char *)(src ? &ad->u.net.v4info.saddr : 3670 addrp = (char *)(src ? &ad->u.net->v4info.saddr :
3641 &ad->u.net.v4info.daddr); 3671 &ad->u.net->v4info.daddr);
3642 goto okay; 3672 goto okay;
3643 3673
3644#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 3674#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
@@ -3646,8 +3676,8 @@ static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
3646 ret = selinux_parse_skb_ipv6(skb, ad, proto); 3676 ret = selinux_parse_skb_ipv6(skb, ad, proto);
3647 if (ret) 3677 if (ret)
3648 goto parse_error; 3678 goto parse_error;
3649 addrp = (char *)(src ? &ad->u.net.v6info.saddr : 3679 addrp = (char *)(src ? &ad->u.net->v6info.saddr :
3650 &ad->u.net.v6info.daddr); 3680 &ad->u.net->v6info.daddr);
3651 goto okay; 3681 goto okay;
3652#endif /* IPV6 */ 3682#endif /* IPV6 */
3653 default: 3683 default:
@@ -3721,13 +3751,17 @@ static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
3721{ 3751{
3722 struct sk_security_struct *sksec = sk->sk_security; 3752 struct sk_security_struct *sksec = sk->sk_security;
3723 struct common_audit_data ad; 3753 struct common_audit_data ad;
3754 struct selinux_audit_data sad = {0,};
3755 struct lsm_network_audit net = {0,};
3724 u32 tsid = task_sid(task); 3756 u32 tsid = task_sid(task);
3725 3757
3726 if (sksec->sid == SECINITSID_KERNEL) 3758 if (sksec->sid == SECINITSID_KERNEL)
3727 return 0; 3759 return 0;
3728 3760
3729 COMMON_AUDIT_DATA_INIT(&ad, NET); 3761 COMMON_AUDIT_DATA_INIT(&ad, NET);
3730 ad.u.net.sk = sk; 3762 ad.selinux_audit_data = &sad;
3763 ad.u.net = &net;
3764 ad.u.net->sk = sk;
3731 3765
3732 return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad); 3766 return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad);
3733} 3767}
@@ -3805,6 +3839,8 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3805 char *addrp; 3839 char *addrp;
3806 struct sk_security_struct *sksec = sk->sk_security; 3840 struct sk_security_struct *sksec = sk->sk_security;
3807 struct common_audit_data ad; 3841 struct common_audit_data ad;
3842 struct selinux_audit_data sad = {0,};
3843 struct lsm_network_audit net = {0,};
3808 struct sockaddr_in *addr4 = NULL; 3844 struct sockaddr_in *addr4 = NULL;
3809 struct sockaddr_in6 *addr6 = NULL; 3845 struct sockaddr_in6 *addr6 = NULL;
3810 unsigned short snum; 3846 unsigned short snum;
@@ -3831,8 +3867,10 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3831 if (err) 3867 if (err)
3832 goto out; 3868 goto out;
3833 COMMON_AUDIT_DATA_INIT(&ad, NET); 3869 COMMON_AUDIT_DATA_INIT(&ad, NET);
3834 ad.u.net.sport = htons(snum); 3870 ad.selinux_audit_data = &sad;
3835 ad.u.net.family = family; 3871 ad.u.net = &net;
3872 ad.u.net->sport = htons(snum);
3873 ad.u.net->family = family;
3836 err = avc_has_perm(sksec->sid, sid, 3874 err = avc_has_perm(sksec->sid, sid,
3837 sksec->sclass, 3875 sksec->sclass,
3838 SOCKET__NAME_BIND, &ad); 3876 SOCKET__NAME_BIND, &ad);
@@ -3864,13 +3902,15 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
3864 goto out; 3902 goto out;
3865 3903
3866 COMMON_AUDIT_DATA_INIT(&ad, NET); 3904 COMMON_AUDIT_DATA_INIT(&ad, NET);
3867 ad.u.net.sport = htons(snum); 3905 ad.selinux_audit_data = &sad;
3868 ad.u.net.family = family; 3906 ad.u.net = &net;
3907 ad.u.net->sport = htons(snum);
3908 ad.u.net->family = family;
3869 3909
3870 if (family == PF_INET) 3910 if (family == PF_INET)
3871 ad.u.net.v4info.saddr = addr4->sin_addr.s_addr; 3911 ad.u.net->v4info.saddr = addr4->sin_addr.s_addr;
3872 else 3912 else
3873 ad.u.net.v6info.saddr = addr6->sin6_addr; 3913 ad.u.net->v6info.saddr = addr6->sin6_addr;
3874 3914
3875 err = avc_has_perm(sksec->sid, sid, 3915 err = avc_has_perm(sksec->sid, sid,
3876 sksec->sclass, node_perm, &ad); 3916 sksec->sclass, node_perm, &ad);
@@ -3897,6 +3937,8 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3897 if (sksec->sclass == SECCLASS_TCP_SOCKET || 3937 if (sksec->sclass == SECCLASS_TCP_SOCKET ||
3898 sksec->sclass == SECCLASS_DCCP_SOCKET) { 3938 sksec->sclass == SECCLASS_DCCP_SOCKET) {
3899 struct common_audit_data ad; 3939 struct common_audit_data ad;
3940 struct selinux_audit_data sad = {0,};
3941 struct lsm_network_audit net = {0,};
3900 struct sockaddr_in *addr4 = NULL; 3942 struct sockaddr_in *addr4 = NULL;
3901 struct sockaddr_in6 *addr6 = NULL; 3943 struct sockaddr_in6 *addr6 = NULL;
3902 unsigned short snum; 3944 unsigned short snum;
@@ -3922,8 +3964,10 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3922 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT; 3964 TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3923 3965
3924 COMMON_AUDIT_DATA_INIT(&ad, NET); 3966 COMMON_AUDIT_DATA_INIT(&ad, NET);
3925 ad.u.net.dport = htons(snum); 3967 ad.selinux_audit_data = &sad;
3926 ad.u.net.family = sk->sk_family; 3968 ad.u.net = &net;
3969 ad.u.net->dport = htons(snum);
3970 ad.u.net->family = sk->sk_family;
3927 err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad); 3971 err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad);
3928 if (err) 3972 if (err)
3929 goto out; 3973 goto out;
@@ -4012,10 +4056,14 @@ static int selinux_socket_unix_stream_connect(struct sock *sock,
4012 struct sk_security_struct *sksec_other = other->sk_security; 4056 struct sk_security_struct *sksec_other = other->sk_security;
4013 struct sk_security_struct *sksec_new = newsk->sk_security; 4057 struct sk_security_struct *sksec_new = newsk->sk_security;
4014 struct common_audit_data ad; 4058 struct common_audit_data ad;
4059 struct selinux_audit_data sad = {0,};
4060 struct lsm_network_audit net = {0,};
4015 int err; 4061 int err;
4016 4062
4017 COMMON_AUDIT_DATA_INIT(&ad, NET); 4063 COMMON_AUDIT_DATA_INIT(&ad, NET);
4018 ad.u.net.sk = other; 4064 ad.selinux_audit_data = &sad;
4065 ad.u.net = &net;
4066 ad.u.net->sk = other;
4019 4067
4020 err = avc_has_perm(sksec_sock->sid, sksec_other->sid, 4068 err = avc_has_perm(sksec_sock->sid, sksec_other->sid,
4021 sksec_other->sclass, 4069 sksec_other->sclass,
@@ -4042,9 +4090,13 @@ static int selinux_socket_unix_may_send(struct socket *sock,
4042 struct sk_security_struct *ssec = sock->sk->sk_security; 4090 struct sk_security_struct *ssec = sock->sk->sk_security;
4043 struct sk_security_struct *osec = other->sk->sk_security; 4091 struct sk_security_struct *osec = other->sk->sk_security;
4044 struct common_audit_data ad; 4092 struct common_audit_data ad;
4093 struct selinux_audit_data sad = {0,};
4094 struct lsm_network_audit net = {0,};
4045 4095
4046 COMMON_AUDIT_DATA_INIT(&ad, NET); 4096 COMMON_AUDIT_DATA_INIT(&ad, NET);
4047 ad.u.net.sk = other->sk; 4097 ad.selinux_audit_data = &sad;
4098 ad.u.net = &net;
4099 ad.u.net->sk = other->sk;
4048 4100
4049 return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO, 4101 return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO,
4050 &ad); 4102 &ad);
@@ -4080,11 +4132,15 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4080 struct sk_security_struct *sksec = sk->sk_security; 4132 struct sk_security_struct *sksec = sk->sk_security;
4081 u32 sk_sid = sksec->sid; 4133 u32 sk_sid = sksec->sid;
4082 struct common_audit_data ad; 4134 struct common_audit_data ad;
4135 struct selinux_audit_data sad = {0,};
4136 struct lsm_network_audit net = {0,};
4083 char *addrp; 4137 char *addrp;
4084 4138
4085 COMMON_AUDIT_DATA_INIT(&ad, NET); 4139 COMMON_AUDIT_DATA_INIT(&ad, NET);
4086 ad.u.net.netif = skb->skb_iif; 4140 ad.selinux_audit_data = &sad;
4087 ad.u.net.family = family; 4141 ad.u.net = &net;
4142 ad.u.net->netif = skb->skb_iif;
4143 ad.u.net->family = family;
4088 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL); 4144 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4089 if (err) 4145 if (err)
4090 return err; 4146 return err;
@@ -4111,6 +4167,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4111 u16 family = sk->sk_family; 4167 u16 family = sk->sk_family;
4112 u32 sk_sid = sksec->sid; 4168 u32 sk_sid = sksec->sid;
4113 struct common_audit_data ad; 4169 struct common_audit_data ad;
4170 struct selinux_audit_data sad = {0,};
4171 struct lsm_network_audit net = {0,};
4114 char *addrp; 4172 char *addrp;
4115 u8 secmark_active; 4173 u8 secmark_active;
4116 u8 peerlbl_active; 4174 u8 peerlbl_active;
@@ -4135,8 +4193,10 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4135 return 0; 4193 return 0;
4136 4194
4137 COMMON_AUDIT_DATA_INIT(&ad, NET); 4195 COMMON_AUDIT_DATA_INIT(&ad, NET);
4138 ad.u.net.netif = skb->skb_iif; 4196 ad.selinux_audit_data = &sad;
4139 ad.u.net.family = family; 4197 ad.u.net = &net;
4198 ad.u.net->netif = skb->skb_iif;
4199 ad.u.net->family = family;
4140 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL); 4200 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4141 if (err) 4201 if (err)
4142 return err; 4202 return err;
@@ -4471,6 +4531,8 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4471 char *addrp; 4531 char *addrp;
4472 u32 peer_sid; 4532 u32 peer_sid;
4473 struct common_audit_data ad; 4533 struct common_audit_data ad;
4534 struct selinux_audit_data sad = {0,};
4535 struct lsm_network_audit net = {0,};
4474 u8 secmark_active; 4536 u8 secmark_active;
4475 u8 netlbl_active; 4537 u8 netlbl_active;
4476 u8 peerlbl_active; 4538 u8 peerlbl_active;
@@ -4488,8 +4550,10 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4488 return NF_DROP; 4550 return NF_DROP;
4489 4551
4490 COMMON_AUDIT_DATA_INIT(&ad, NET); 4552 COMMON_AUDIT_DATA_INIT(&ad, NET);
4491 ad.u.net.netif = ifindex; 4553 ad.selinux_audit_data = &sad;
4492 ad.u.net.family = family; 4554 ad.u.net = &net;
4555 ad.u.net->netif = ifindex;
4556 ad.u.net->family = family;
4493 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0) 4557 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
4494 return NF_DROP; 4558 return NF_DROP;
4495 4559
@@ -4576,6 +4640,8 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4576 struct sock *sk = skb->sk; 4640 struct sock *sk = skb->sk;
4577 struct sk_security_struct *sksec; 4641 struct sk_security_struct *sksec;
4578 struct common_audit_data ad; 4642 struct common_audit_data ad;
4643 struct selinux_audit_data sad = {0,};
4644 struct lsm_network_audit net = {0,};
4579 char *addrp; 4645 char *addrp;
4580 u8 proto; 4646 u8 proto;
4581 4647
@@ -4584,8 +4650,10 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4584 sksec = sk->sk_security; 4650 sksec = sk->sk_security;
4585 4651
4586 COMMON_AUDIT_DATA_INIT(&ad, NET); 4652 COMMON_AUDIT_DATA_INIT(&ad, NET);
4587 ad.u.net.netif = ifindex; 4653 ad.selinux_audit_data = &sad;
4588 ad.u.net.family = family; 4654 ad.u.net = &net;
4655 ad.u.net->netif = ifindex;
4656 ad.u.net->family = family;
4589 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto)) 4657 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
4590 return NF_DROP; 4658 return NF_DROP;
4591 4659
@@ -4607,6 +4675,8 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4607 u32 peer_sid; 4675 u32 peer_sid;
4608 struct sock *sk; 4676 struct sock *sk;
4609 struct common_audit_data ad; 4677 struct common_audit_data ad;
4678 struct selinux_audit_data sad = {0,};
4679 struct lsm_network_audit net = {0,};
4610 char *addrp; 4680 char *addrp;
4611 u8 secmark_active; 4681 u8 secmark_active;
4612 u8 peerlbl_active; 4682 u8 peerlbl_active;
@@ -4653,8 +4723,10 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4653 } 4723 }
4654 4724
4655 COMMON_AUDIT_DATA_INIT(&ad, NET); 4725 COMMON_AUDIT_DATA_INIT(&ad, NET);
4656 ad.u.net.netif = ifindex; 4726 ad.selinux_audit_data = &sad;
4657 ad.u.net.family = family; 4727 ad.u.net = &net;
4728 ad.u.net->netif = ifindex;
4729 ad.u.net->family = family;
4658 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL)) 4730 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
4659 return NF_DROP; 4731 return NF_DROP;
4660 4732
@@ -4769,11 +4841,13 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
4769{ 4841{
4770 struct ipc_security_struct *isec; 4842 struct ipc_security_struct *isec;
4771 struct common_audit_data ad; 4843 struct common_audit_data ad;
4844 struct selinux_audit_data sad = {0,};
4772 u32 sid = current_sid(); 4845 u32 sid = current_sid();
4773 4846
4774 isec = ipc_perms->security; 4847 isec = ipc_perms->security;
4775 4848
4776 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4849 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4850 ad.selinux_audit_data = &sad;
4777 ad.u.ipc_id = ipc_perms->key; 4851 ad.u.ipc_id = ipc_perms->key;
4778 4852
4779 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad); 4853 return avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
@@ -4794,6 +4868,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4794{ 4868{
4795 struct ipc_security_struct *isec; 4869 struct ipc_security_struct *isec;
4796 struct common_audit_data ad; 4870 struct common_audit_data ad;
4871 struct selinux_audit_data sad = {0,};
4797 u32 sid = current_sid(); 4872 u32 sid = current_sid();
4798 int rc; 4873 int rc;
4799 4874
@@ -4804,6 +4879,7 @@ static int selinux_msg_queue_alloc_security(struct msg_queue *msq)
4804 isec = msq->q_perm.security; 4879 isec = msq->q_perm.security;
4805 4880
4806 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4881 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4882 ad.selinux_audit_data = &sad;
4807 ad.u.ipc_id = msq->q_perm.key; 4883 ad.u.ipc_id = msq->q_perm.key;
4808 4884
4809 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4885 rc = avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4824,11 +4900,13 @@ static int selinux_msg_queue_associate(struct msg_queue *msq, int msqflg)
4824{ 4900{
4825 struct ipc_security_struct *isec; 4901 struct ipc_security_struct *isec;
4826 struct common_audit_data ad; 4902 struct common_audit_data ad;
4903 struct selinux_audit_data sad = {0,};
4827 u32 sid = current_sid(); 4904 u32 sid = current_sid();
4828 4905
4829 isec = msq->q_perm.security; 4906 isec = msq->q_perm.security;
4830 4907
4831 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4908 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4909 ad.selinux_audit_data = &sad;
4832 ad.u.ipc_id = msq->q_perm.key; 4910 ad.u.ipc_id = msq->q_perm.key;
4833 4911
4834 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ, 4912 return avc_has_perm(sid, isec->sid, SECCLASS_MSGQ,
@@ -4868,6 +4946,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4868 struct ipc_security_struct *isec; 4946 struct ipc_security_struct *isec;
4869 struct msg_security_struct *msec; 4947 struct msg_security_struct *msec;
4870 struct common_audit_data ad; 4948 struct common_audit_data ad;
4949 struct selinux_audit_data sad = {0,};
4871 u32 sid = current_sid(); 4950 u32 sid = current_sid();
4872 int rc; 4951 int rc;
4873 4952
@@ -4889,6 +4968,7 @@ static int selinux_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
4889 } 4968 }
4890 4969
4891 COMMON_AUDIT_DATA_INIT(&ad, IPC); 4970 COMMON_AUDIT_DATA_INIT(&ad, IPC);
4971 ad.selinux_audit_data = &sad;
4892 ad.u.ipc_id = msq->q_perm.key; 4972 ad.u.ipc_id = msq->q_perm.key;
4893 4973
4894 /* Can this process write to the queue? */ 4974 /* Can this process write to the queue? */
@@ -4913,6 +4993,7 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4913 struct ipc_security_struct *isec; 4993 struct ipc_security_struct *isec;
4914 struct msg_security_struct *msec; 4994 struct msg_security_struct *msec;
4915 struct common_audit_data ad; 4995 struct common_audit_data ad;
4996 struct selinux_audit_data sad = {0,};
4916 u32 sid = task_sid(target); 4997 u32 sid = task_sid(target);
4917 int rc; 4998 int rc;
4918 4999
@@ -4920,6 +5001,7 @@ static int selinux_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
4920 msec = msg->security; 5001 msec = msg->security;
4921 5002
4922 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5003 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5004 ad.selinux_audit_data = &sad;
4923 ad.u.ipc_id = msq->q_perm.key; 5005 ad.u.ipc_id = msq->q_perm.key;
4924 5006
4925 rc = avc_has_perm(sid, isec->sid, 5007 rc = avc_has_perm(sid, isec->sid,
@@ -4935,6 +5017,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4935{ 5017{
4936 struct ipc_security_struct *isec; 5018 struct ipc_security_struct *isec;
4937 struct common_audit_data ad; 5019 struct common_audit_data ad;
5020 struct selinux_audit_data sad = {0,};
4938 u32 sid = current_sid(); 5021 u32 sid = current_sid();
4939 int rc; 5022 int rc;
4940 5023
@@ -4945,6 +5028,7 @@ static int selinux_shm_alloc_security(struct shmid_kernel *shp)
4945 isec = shp->shm_perm.security; 5028 isec = shp->shm_perm.security;
4946 5029
4947 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5030 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5031 ad.selinux_audit_data = &sad;
4948 ad.u.ipc_id = shp->shm_perm.key; 5032 ad.u.ipc_id = shp->shm_perm.key;
4949 5033
4950 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5034 rc = avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -4965,11 +5049,13 @@ static int selinux_shm_associate(struct shmid_kernel *shp, int shmflg)
4965{ 5049{
4966 struct ipc_security_struct *isec; 5050 struct ipc_security_struct *isec;
4967 struct common_audit_data ad; 5051 struct common_audit_data ad;
5052 struct selinux_audit_data sad = {0,};
4968 u32 sid = current_sid(); 5053 u32 sid = current_sid();
4969 5054
4970 isec = shp->shm_perm.security; 5055 isec = shp->shm_perm.security;
4971 5056
4972 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5057 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5058 ad.selinux_audit_data = &sad;
4973 ad.u.ipc_id = shp->shm_perm.key; 5059 ad.u.ipc_id = shp->shm_perm.key;
4974 5060
4975 return avc_has_perm(sid, isec->sid, SECCLASS_SHM, 5061 return avc_has_perm(sid, isec->sid, SECCLASS_SHM,
@@ -5027,6 +5113,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5027{ 5113{
5028 struct ipc_security_struct *isec; 5114 struct ipc_security_struct *isec;
5029 struct common_audit_data ad; 5115 struct common_audit_data ad;
5116 struct selinux_audit_data sad = {0,};
5030 u32 sid = current_sid(); 5117 u32 sid = current_sid();
5031 int rc; 5118 int rc;
5032 5119
@@ -5037,6 +5124,7 @@ static int selinux_sem_alloc_security(struct sem_array *sma)
5037 isec = sma->sem_perm.security; 5124 isec = sma->sem_perm.security;
5038 5125
5039 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5126 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5127 ad.selinux_audit_data = &sad;
5040 ad.u.ipc_id = sma->sem_perm.key; 5128 ad.u.ipc_id = sma->sem_perm.key;
5041 5129
5042 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5130 rc = avc_has_perm(sid, isec->sid, SECCLASS_SEM,
@@ -5057,11 +5145,13 @@ static int selinux_sem_associate(struct sem_array *sma, int semflg)
5057{ 5145{
5058 struct ipc_security_struct *isec; 5146 struct ipc_security_struct *isec;
5059 struct common_audit_data ad; 5147 struct common_audit_data ad;
5148 struct selinux_audit_data sad = {0,};
5060 u32 sid = current_sid(); 5149 u32 sid = current_sid();
5061 5150
5062 isec = sma->sem_perm.security; 5151 isec = sma->sem_perm.security;
5063 5152
5064 COMMON_AUDIT_DATA_INIT(&ad, IPC); 5153 COMMON_AUDIT_DATA_INIT(&ad, IPC);
5154 ad.selinux_audit_data = &sad;
5065 ad.u.ipc_id = sma->sem_perm.key; 5155 ad.u.ipc_id = sma->sem_perm.key;
5066 5156
5067 return avc_has_perm(sid, isec->sid, SECCLASS_SEM, 5157 return avc_has_perm(sid, isec->sid, SECCLASS_SEM,
diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h
index 005a91bcb200..1931370233d7 100644
--- a/security/selinux/include/avc.h
+++ b/security/selinux/include/avc.h
@@ -47,6 +47,31 @@ struct avc_cache_stats {
47}; 47};
48 48
49/* 49/*
50 * We only need this data after we have decided to send an audit message.
51 */
52struct selinux_late_audit_data {
53 u32 ssid;
54 u32 tsid;
55 u16 tclass;
56 u32 requested;
57 u32 audited;
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 {
66 /*
67 * auditdeny is a bit tricky and unintuitive. See the
68 * comments in avc.c for it's meaning and usage.
69 */
70 u32 auditdeny;
71 struct selinux_late_audit_data *slad;
72};
73
74/*
50 * AVC operations 75 * AVC operations
51 */ 76 */
52 77
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 2ad00657b801..4ede719922ed 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,16 @@ 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;
326}
327
328static inline void smk_ad_init_net(struct smk_audit_info *a, const char *func,
329 char type, struct lsm_network_audit *net)
330{
331 smk_ad_init(a, func, type);
332 memset(net, 0, sizeof(*net));
333 a->a.u.net = net;
315} 334}
316 335
317static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a, 336static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
@@ -337,7 +356,7 @@ static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
337static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a, 356static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
338 struct sock *sk) 357 struct sock *sk)
339{ 358{
340 a->a.u.net.sk = sk; 359 a->a.u.net->sk = sk;
341} 360}
342 361
343#else /* no AUDIT */ 362#else /* no AUDIT */
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index cc7cb6edba08..c8115f7308f8 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,19 +310,19 @@ 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;
321 sad->request = request_buffer; 322 sad->request = request_buffer;
322 sad->result = result; 323 sad->result = result;
323 a->lsm_pre_audit = smack_log_callback;
324 324
325 common_lsm_audit(a); 325 common_lsm_audit(a, smack_log_callback, NULL);
326} 326}
327#else /* #ifdef CONFIG_AUDIT */ 327#else /* #ifdef CONFIG_AUDIT */
328void smack_log(char *subject_label, char *object_label, int request, 328void smack_log(char *subject_label, char *object_label, int request,
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index cd667b4089a5..45c32f074166 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1943,13 +1943,15 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1943 rcu_read_lock(); 1943 rcu_read_lock();
1944 hostsp = smack_host_label(sap); 1944 hostsp = smack_host_label(sap);
1945 if (hostsp != NULL) { 1945 if (hostsp != NULL) {
1946 sk_lbl = SMACK_UNLABELED_SOCKET;
1947#ifdef CONFIG_AUDIT 1946#ifdef CONFIG_AUDIT
1948 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 1947 struct lsm_network_audit net;
1949 ad.a.u.net.family = sap->sin_family; 1948
1950 ad.a.u.net.dport = sap->sin_port; 1949 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
1951 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr; 1950 ad.a.u.net->family = sap->sin_family;
1951 ad.a.u.net->dport = sap->sin_port;
1952 ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
1952#endif 1953#endif
1954 sk_lbl = SMACK_UNLABELED_SOCKET;
1953 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad); 1955 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1954 } else { 1956 } else {
1955 sk_lbl = SMACK_CIPSO_SOCKET; 1957 sk_lbl = SMACK_CIPSO_SOCKET;
@@ -2810,8 +2812,12 @@ static int smack_unix_stream_connect(struct sock *sock,
2810 struct smk_audit_info ad; 2812 struct smk_audit_info ad;
2811 int rc = 0; 2813 int rc = 0;
2812 2814
2813 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 2815#ifdef CONFIG_AUDIT
2816 struct lsm_network_audit net;
2817
2818 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2814 smk_ad_setfield_u_net_sk(&ad, other); 2819 smk_ad_setfield_u_net_sk(&ad, other);
2820#endif
2815 2821
2816 if (!capable(CAP_MAC_OVERRIDE)) 2822 if (!capable(CAP_MAC_OVERRIDE))
2817 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad); 2823 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
@@ -2842,8 +2848,12 @@ static int smack_unix_may_send(struct socket *sock, struct socket *other)
2842 struct smk_audit_info ad; 2848 struct smk_audit_info ad;
2843 int rc = 0; 2849 int rc = 0;
2844 2850
2845 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 2851#ifdef CONFIG_AUDIT
2852 struct lsm_network_audit net;
2853
2854 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2846 smk_ad_setfield_u_net_sk(&ad, other->sk); 2855 smk_ad_setfield_u_net_sk(&ad, other->sk);
2856#endif
2847 2857
2848 if (!capable(CAP_MAC_OVERRIDE)) 2858 if (!capable(CAP_MAC_OVERRIDE))
2849 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad); 2859 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
@@ -2990,6 +3000,9 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2990 char *csp; 3000 char *csp;
2991 int rc; 3001 int rc;
2992 struct smk_audit_info ad; 3002 struct smk_audit_info ad;
3003#ifdef CONFIG_AUDIT
3004 struct lsm_network_audit net;
3005#endif
2993 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6) 3006 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2994 return 0; 3007 return 0;
2995 3008
@@ -3007,9 +3020,9 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
3007 netlbl_secattr_destroy(&secattr); 3020 netlbl_secattr_destroy(&secattr);
3008 3021
3009#ifdef CONFIG_AUDIT 3022#ifdef CONFIG_AUDIT
3010 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 3023 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3011 ad.a.u.net.family = sk->sk_family; 3024 ad.a.u.net->family = sk->sk_family;
3012 ad.a.u.net.netif = skb->skb_iif; 3025 ad.a.u.net->netif = skb->skb_iif;
3013 ipv4_skb_to_auditdata(skb, &ad.a, NULL); 3026 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3014#endif 3027#endif
3015 /* 3028 /*
@@ -3152,6 +3165,9 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3152 char *sp; 3165 char *sp;
3153 int rc; 3166 int rc;
3154 struct smk_audit_info ad; 3167 struct smk_audit_info ad;
3168#ifdef CONFIG_AUDIT
3169 struct lsm_network_audit net;
3170#endif
3155 3171
3156 /* handle mapped IPv4 packets arriving via IPv6 sockets */ 3172 /* handle mapped IPv4 packets arriving via IPv6 sockets */
3157 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) 3173 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
@@ -3166,9 +3182,9 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3166 netlbl_secattr_destroy(&secattr); 3182 netlbl_secattr_destroy(&secattr);
3167 3183
3168#ifdef CONFIG_AUDIT 3184#ifdef CONFIG_AUDIT
3169 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET); 3185 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3170 ad.a.u.net.family = family; 3186 ad.a.u.net->family = family;
3171 ad.a.u.net.netif = skb->skb_iif; 3187 ad.a.u.net->netif = skb->skb_iif;
3172 ipv4_skb_to_auditdata(skb, &ad.a, NULL); 3188 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3173#endif 3189#endif
3174 /* 3190 /*
@@ -3624,8 +3640,38 @@ struct security_operations smack_ops = {
3624}; 3640};
3625 3641
3626 3642
3627static __init void init_smack_know_list(void) 3643static __init void init_smack_known_list(void)
3628{ 3644{
3645 /*
3646 * Initialize CIPSO locks
3647 */
3648 spin_lock_init(&smack_known_huh.smk_cipsolock);
3649 spin_lock_init(&smack_known_hat.smk_cipsolock);
3650 spin_lock_init(&smack_known_star.smk_cipsolock);
3651 spin_lock_init(&smack_known_floor.smk_cipsolock);
3652 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3653 spin_lock_init(&smack_known_web.smk_cipsolock);
3654 /*
3655 * Initialize rule list locks
3656 */
3657 mutex_init(&smack_known_huh.smk_rules_lock);
3658 mutex_init(&smack_known_hat.smk_rules_lock);
3659 mutex_init(&smack_known_floor.smk_rules_lock);
3660 mutex_init(&smack_known_star.smk_rules_lock);
3661 mutex_init(&smack_known_invalid.smk_rules_lock);
3662 mutex_init(&smack_known_web.smk_rules_lock);
3663 /*
3664 * Initialize rule lists
3665 */
3666 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
3667 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
3668 INIT_LIST_HEAD(&smack_known_star.smk_rules);
3669 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
3670 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
3671 INIT_LIST_HEAD(&smack_known_web.smk_rules);
3672 /*
3673 * Create the known labels list
3674 */
3629 list_add(&smack_known_huh.list, &smack_known_list); 3675 list_add(&smack_known_huh.list, &smack_known_list);
3630 list_add(&smack_known_hat.list, &smack_known_list); 3676 list_add(&smack_known_hat.list, &smack_known_list);
3631 list_add(&smack_known_star.list, &smack_known_list); 3677 list_add(&smack_known_star.list, &smack_known_list);
@@ -3660,16 +3706,8 @@ static __init int smack_init(void)
3660 cred = (struct cred *) current->cred; 3706 cred = (struct cred *) current->cred;
3661 cred->security = tsp; 3707 cred->security = tsp;
3662 3708
3663 /* initialize the smack_know_list */ 3709 /* initialize the smack_known_list */
3664 init_smack_know_list(); 3710 init_smack_known_list();
3665 /*
3666 * Initialize locks
3667 */
3668 spin_lock_init(&smack_known_huh.smk_cipsolock);
3669 spin_lock_init(&smack_known_hat.smk_cipsolock);
3670 spin_lock_init(&smack_known_star.smk_cipsolock);
3671 spin_lock_init(&smack_known_floor.smk_cipsolock);
3672 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3673 3711
3674 /* 3712 /*
3675 * Register with LSM 3713 * Register with LSM
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 5c32f36ff706..038811cb7e62 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -1614,20 +1614,6 @@ static int __init init_smk_fs(void)
1614 smk_cipso_doi(); 1614 smk_cipso_doi();
1615 smk_unlbl_ambient(NULL); 1615 smk_unlbl_ambient(NULL);
1616 1616
1617 mutex_init(&smack_known_floor.smk_rules_lock);
1618 mutex_init(&smack_known_hat.smk_rules_lock);
1619 mutex_init(&smack_known_huh.smk_rules_lock);
1620 mutex_init(&smack_known_invalid.smk_rules_lock);
1621 mutex_init(&smack_known_star.smk_rules_lock);
1622 mutex_init(&smack_known_web.smk_rules_lock);
1623
1624 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
1625 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
1626 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
1627 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
1628 INIT_LIST_HEAD(&smack_known_star.smk_rules);
1629 INIT_LIST_HEAD(&smack_known_web.smk_rules);
1630
1631 return err; 1617 return err;
1632} 1618}
1633 1619