~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to kernel-patches/2.6.37/0002-AppArmor-compatibility-patch-for-v5-interface.patch

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From a89f0bb2dfd82445e58f5f6bfceb40ab8bee543f Mon Sep 17 00:00:00 2001
 
2
From: John Johansen <john.johansen@canonical.com>
 
3
Date: Thu, 22 Jul 2010 02:32:02 -0700
 
4
Subject: [PATCH 2/3] AppArmor: compatibility patch for v5 interface
 
5
 
 
6
Signed-off-by: John Johansen <john.johansen@canonical.com>
 
7
---
 
8
 security/apparmor/Kconfig              |    9 +
 
9
 security/apparmor/Makefile             |    2 +
 
10
 security/apparmor/apparmorfs-24.c      |  287 ++++++++++++++++++++++++++++++++
 
11
 security/apparmor/apparmorfs.c         |   18 ++-
 
12
 security/apparmor/include/apparmorfs.h |    6 +
 
13
 5 files changed, 320 insertions(+), 2 deletions(-)
 
14
 create mode 100644 security/apparmor/apparmorfs-24.c
 
15
 
 
16
diff --git a/security/apparmor/Kconfig b/security/apparmor/Kconfig
 
17
index 9b9013b..51ebf96 100644
 
18
--- a/security/apparmor/Kconfig
 
19
+++ b/security/apparmor/Kconfig
 
20
@@ -29,3 +29,12 @@ config SECURITY_APPARMOR_BOOTPARAM_VALUE
 
21
          boot.
 
22
 
 
23
          If you are unsure how to answer this question, answer 1.
 
24
+
 
25
+config SECURITY_APPARMOR_COMPAT_24
 
26
+       bool "Enable AppArmor 2.4 compatability"
 
27
+       depends on SECURITY_APPARMOR
 
28
+       default y
 
29
+       help
 
30
+         This option enables compatability with AppArmor 2.4.  It is
 
31
+          recommended if compatability with older versions of AppArmor
 
32
+          is desired.
 
33
diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile
 
34
index a9a1db0..e5e8968 100644
 
35
--- a/security/apparmor/Makefile
 
36
+++ b/security/apparmor/Makefile
 
37
@@ -6,6 +6,8 @@ apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \
 
38
               path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
 
39
               resource.o sid.o file.o net.o
 
40
 
 
41
+apparmor-$(CONFIG_SECURITY_APPARMOR_COMPAT_24) += apparmorfs-24.o
 
42
+
 
43
 clean-files: capability_names.h af_names.h
 
44
 
 
45
 quiet_cmd_make-caps = GEN     $@
 
46
diff --git a/security/apparmor/apparmorfs-24.c b/security/apparmor/apparmorfs-24.c
 
47
new file mode 100644
 
48
index 0000000..dc8c744
 
49
--- /dev/null
 
50
+++ b/security/apparmor/apparmorfs-24.c
 
51
@@ -0,0 +1,287 @@
 
52
+/*
 
53
+ * AppArmor security module
 
54
+ *
 
55
+ * This file contains AppArmor /sys/kernel/secrutiy/apparmor interface functions
 
56
+ *
 
57
+ * Copyright (C) 1998-2008 Novell/SUSE
 
58
+ * Copyright 2009-2010 Canonical Ltd.
 
59
+ *
 
60
+ * This program is free software; you can redistribute it and/or
 
61
+ * modify it under the terms of the GNU General Public License as
 
62
+ * published by the Free Software Foundation, version 2 of the
 
63
+ * License.
 
64
+ *
 
65
+ *
 
66
+ * This file contain functions providing an interface for <= AppArmor 2.4
 
67
+ * compatibility.  It is dependent on CONFIG_SECURITY_APPARMOR_COMPAT_24
 
68
+ * being set (see Makefile).
 
69
+ */
 
70
+
 
71
+#include <linux/security.h>
 
72
+#include <linux/vmalloc.h>
 
73
+#include <linux/module.h>
 
74
+#include <linux/seq_file.h>
 
75
+#include <linux/uaccess.h>
 
76
+#include <linux/namei.h>
 
77
+
 
78
+#include "include/apparmor.h"
 
79
+#include "include/audit.h"
 
80
+#include "include/context.h"
 
81
+#include "include/policy.h"
 
82
+
 
83
+
 
84
+/* apparmor/matching */
 
85
+static ssize_t aa_matching_read(struct file *file, char __user *buf,
 
86
+                               size_t size, loff_t *ppos)
 
87
+{
 
88
+       const char matching[] = "pattern=aadfa audit perms=crwxamlk/ "
 
89
+           "user::other";
 
90
+
 
91
+       return simple_read_from_buffer(buf, size, ppos, matching,
 
92
+                                      sizeof(matching) - 1);
 
93
+}
 
94
+
 
95
+const struct file_operations aa_fs_matching_fops = {
 
96
+       .read = aa_matching_read,
 
97
+};
 
98
+
 
99
+/* apparmor/features */
 
100
+static ssize_t aa_features_read(struct file *file, char __user *buf,
 
101
+                               size_t size, loff_t *ppos)
 
102
+{
 
103
+       const char features[] = "file=3.1 capability=2.0 network=1.0 "
 
104
+           "change_hat=1.5 change_profile=1.1 " "aanamespaces=1.1 rlimit=1.1";
 
105
+
 
106
+       return simple_read_from_buffer(buf, size, ppos, features,
 
107
+                                      sizeof(features) - 1);
 
108
+}
 
109
+
 
110
+const struct file_operations aa_fs_features_fops = {
 
111
+       .read = aa_features_read,
 
112
+};
 
113
+
 
114
+/**
 
115
+ * __next_namespace - find the next namespace to list
 
116
+ * @root: root namespace to stop search at (NOT NULL)
 
117
+ * @ns: current ns position (NOT NULL)
 
118
+ *
 
119
+ * Find the next namespace from @ns under @root and handle all locking needed
 
120
+ * while switching current namespace.
 
121
+ *
 
122
+ * Returns: next namespace or NULL if at last namespace under @root
 
123
+ * NOTE: will not unlock root->lock
 
124
+ */
 
125
+static struct aa_namespace *__next_namespace(struct aa_namespace *root,
 
126
+                                            struct aa_namespace *ns)
 
127
+{
 
128
+       struct aa_namespace *parent;
 
129
+
 
130
+       /* is next namespace a child */
 
131
+       if (!list_empty(&ns->sub_ns)) {
 
132
+               struct aa_namespace *next;
 
133
+               next = list_first_entry(&ns->sub_ns, typeof(*ns), base.list);
 
134
+               read_lock(&next->lock);
 
135
+               return next;
 
136
+       }
 
137
+
 
138
+       /* check if the next ns is a sibling, parent, gp, .. */
 
139
+       parent = ns->parent;
 
140
+       while (parent) {
 
141
+               read_unlock(&ns->lock);
 
142
+               list_for_each_entry_continue(ns, &parent->sub_ns, base.list) {
 
143
+                       read_lock(&ns->lock);
 
144
+                       return ns;
 
145
+               }
 
146
+               if (parent == root)
 
147
+                       return NULL;
 
148
+               ns = parent;
 
149
+               parent = parent->parent;
 
150
+       }
 
151
+
 
152
+       return NULL;
 
153
+}
 
154
+
 
155
+/**
 
156
+ * __first_profile - find the first profile in a namespace
 
157
+ * @root: namespace that is root of profiles being displayed (NOT NULL)
 
158
+ * @ns: namespace to start in   (NOT NULL)
 
159
+ *
 
160
+ * Returns: unrefcounted profile or NULL if no profile
 
161
+ */
 
162
+static struct aa_profile *__first_profile(struct aa_namespace *root,
 
163
+                                         struct aa_namespace *ns)
 
164
+{
 
165
+       for ( ; ns; ns = __next_namespace(root, ns)) {
 
166
+               if (!list_empty(&ns->base.profiles))
 
167
+                       return list_first_entry(&ns->base.profiles,
 
168
+                                               struct aa_profile, base.list);
 
169
+       }
 
170
+       return NULL;
 
171
+}
 
172
+
 
173
+/**
 
174
+ * __next_profile - step to the next profile in a profile tree
 
175
+ * @profile: current profile in tree (NOT NULL)
 
176
+ *
 
177
+ * Perform a depth first taversal on the profile tree in a namespace
 
178
+ *
 
179
+ * Returns: next profile or NULL if done
 
180
+ * Requires: profile->ns.lock to be held
 
181
+ */
 
182
+static struct aa_profile *__next_profile(struct aa_profile *p)
 
183
+{
 
184
+       struct aa_profile *parent;
 
185
+       struct aa_namespace *ns = p->ns;
 
186
+
 
187
+       /* is next profile a child */
 
188
+       if (!list_empty(&p->base.profiles))
 
189
+               return list_first_entry(&p->base.profiles, typeof(*p),
 
190
+                                       base.list);
 
191
+
 
192
+       /* is next profile a sibling, parent sibling, gp, subling, .. */
 
193
+       parent = p->parent;
 
194
+       while (parent) {
 
195
+               list_for_each_entry_continue(p, &parent->base.profiles,
 
196
+                                            base.list)
 
197
+                               return p;
 
198
+               p = parent;
 
199
+               parent = parent->parent;
 
200
+       }
 
201
+
 
202
+       /* is next another profile in the namespace */
 
203
+       list_for_each_entry_continue(p, &ns->base.profiles, base.list)
 
204
+               return p;
 
205
+
 
206
+       return NULL;
 
207
+}
 
208
+
 
209
+/**
 
210
+ * next_profile - step to the next profile in where ever it may be
 
211
+ * @root: root namespace  (NOT NULL)
 
212
+ * @profile: current profile  (NOT NULL)
 
213
+ *
 
214
+ * Returns: next profile or NULL if there isn't one
 
215
+ */
 
216
+static struct aa_profile *next_profile(struct aa_namespace *root,
 
217
+                                      struct aa_profile *profile)
 
218
+{
 
219
+       struct aa_profile *next = __next_profile(profile);
 
220
+       if (next)
 
221
+               return next;
 
222
+
 
223
+       /* finished all profiles in namespace move to next namespace */
 
224
+       return __first_profile(root, __next_namespace(root, profile->ns));
 
225
+}
 
226
+
 
227
+/**
 
228
+ * p_start - start a depth first traversal of profile tree
 
229
+ * @f: seq_file to fill
 
230
+ * @pos: current position
 
231
+ *
 
232
+ * Returns: first profile under current namespace or NULL if none found
 
233
+ *
 
234
+ * acquires first ns->lock
 
235
+ */
 
236
+static void *p_start(struct seq_file *f, loff_t *pos)
 
237
+       __acquires(root->lock)
 
238
+{
 
239
+       struct aa_profile *profile = NULL;
 
240
+       struct aa_namespace *root = aa_current_profile()->ns;
 
241
+       loff_t l = *pos;
 
242
+       f->private = aa_get_namespace(root);
 
243
+
 
244
+
 
245
+       /* find the first profile */
 
246
+       read_lock(&root->lock);
 
247
+       profile = __first_profile(root, root);
 
248
+
 
249
+       /* skip to position */
 
250
+       for (; profile && l > 0; l--)
 
251
+               profile = next_profile(root, profile);
 
252
+
 
253
+       return profile;
 
254
+}
 
255
+
 
256
+/**
 
257
+ * p_next - read the next profile entry
 
258
+ * @f: seq_file to fill
 
259
+ * @p: profile previously returned
 
260
+ * @pos: current position
 
261
+ *
 
262
+ * Returns: next profile after @p or NULL if none
 
263
+ *
 
264
+ * may acquire/release locks in namespace tree as necessary
 
265
+ */
 
266
+static void *p_next(struct seq_file *f, void *p, loff_t *pos)
 
267
+{
 
268
+       struct aa_profile *profile = p;
 
269
+       struct aa_namespace *root = f->private;
 
270
+       (*pos)++;
 
271
+
 
272
+       return next_profile(root, profile);
 
273
+}
 
274
+
 
275
+/**
 
276
+ * p_stop - stop depth first traversal
 
277
+ * @f: seq_file we are filling
 
278
+ * @p: the last profile writen
 
279
+ *
 
280
+ * Release all locking done by p_start/p_next on namespace tree
 
281
+ */
 
282
+static void p_stop(struct seq_file *f, void *p)
 
283
+       __releases(root->lock)
 
284
+{
 
285
+       struct aa_profile *profile = p;
 
286
+       struct aa_namespace *root = f->private, *ns;
 
287
+
 
288
+       if (profile) {
 
289
+               for (ns = profile->ns; ns && ns != root; ns = ns->parent)
 
290
+                       read_unlock(&ns->lock);
 
291
+       }
 
292
+       read_unlock(&root->lock);
 
293
+       aa_put_namespace(root);
 
294
+}
 
295
+
 
296
+/**
 
297
+ * seq_show_profile - show a profile entry
 
298
+ * @f: seq_file to file
 
299
+ * @p: current position (profile)    (NOT NULL)
 
300
+ *
 
301
+ * Returns: error on failure
 
302
+ */
 
303
+static int seq_show_profile(struct seq_file *f, void *p)
 
304
+{
 
305
+       struct aa_profile *profile = (struct aa_profile *)p;
 
306
+       struct aa_namespace *root = f->private;
 
307
+
 
308
+       if (profile->ns != root)
 
309
+               seq_printf(f, ":%s://", aa_ns_name(root, profile->ns));
 
310
+       seq_printf(f, "%s (%s)\n", profile->base.hname,
 
311
+                  COMPLAIN_MODE(profile) ? "complain" : "enforce");
 
312
+
 
313
+       return 0;
 
314
+}
 
315
+
 
316
+static const struct seq_operations aa_fs_profiles_op = {
 
317
+       .start = p_start,
 
318
+       .next = p_next,
 
319
+       .stop = p_stop,
 
320
+       .show = seq_show_profile,
 
321
+};
 
322
+
 
323
+static int profiles_open(struct inode *inode, struct file *file)
 
324
+{
 
325
+       return seq_open(file, &aa_fs_profiles_op);
 
326
+}
 
327
+
 
328
+static int profiles_release(struct inode *inode, struct file *file)
 
329
+{
 
330
+       return seq_release(inode, file);
 
331
+}
 
332
+
 
333
+const struct file_operations aa_fs_profiles_fops = {
 
334
+       .open = profiles_open,
 
335
+       .read = seq_read,
 
336
+       .llseek = seq_lseek,
 
337
+       .release = profiles_release,
 
338
+};
 
339
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
 
340
index 0848292..28c52ac 100644
 
341
--- a/security/apparmor/apparmorfs.c
 
342
+++ b/security/apparmor/apparmorfs.c
 
343
@@ -187,7 +187,11 @@ void __init aa_destroy_aafs(void)
 
344
                aafs_remove(".remove");
 
345
                aafs_remove(".replace");
 
346
                aafs_remove(".load");
 
347
-
 
348
+#ifdef CONFIG_SECURITY_APPARMOR_COMPAT_24
 
349
+               aafs_remove("profiles");
 
350
+               aafs_remove("matching");
 
351
+               aafs_remove("features");
 
352
+#endif
 
353
                securityfs_remove(aa_fs_dentry);
 
354
                aa_fs_dentry = NULL;
 
355
        }
 
356
@@ -218,7 +222,17 @@ int __init aa_create_aafs(void)
 
357
                aa_fs_dentry = NULL;
 
358
                goto error;
 
359
        }
 
360
-
 
361
+#ifdef CONFIG_SECURITY_APPARMOR_COMPAT_24
 
362
+       error = aafs_create("matching", 0444, &aa_fs_matching_fops);
 
363
+       if (error)
 
364
+               goto error;
 
365
+       error = aafs_create("features", 0444, &aa_fs_features_fops);
 
366
+       if (error)
 
367
+               goto error;
 
368
+#endif
 
369
+       error = aafs_create("profiles", 0440, &aa_fs_profiles_fops);
 
370
+       if (error)
 
371
+               goto error;
 
372
        error = aafs_create(".load", 0640, &aa_fs_profile_load);
 
373
        if (error)
 
374
                goto error;
 
375
diff --git a/security/apparmor/include/apparmorfs.h b/security/apparmor/include/apparmorfs.h
 
376
index cb1e93a..14f955c 100644
 
377
--- a/security/apparmor/include/apparmorfs.h
 
378
+++ b/security/apparmor/include/apparmorfs.h
 
379
@@ -17,4 +17,10 @@
 
380
 
 
381
 extern void __init aa_destroy_aafs(void);
 
382
 
 
383
+#ifdef CONFIG_SECURITY_APPARMOR_COMPAT_24
 
384
+extern const struct file_operations aa_fs_matching_fops;
 
385
+extern const struct file_operations aa_fs_features_fops;
 
386
+extern const struct file_operations aa_fs_profiles_fops;
 
387
+#endif
 
388
+
 
389
 #endif /* __AA_APPARMORFS_H */
 
390
-- 
 
391
1.7.1
 
392