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

« back to all changes in this revision

Viewing changes to kernel-patches/for-mainline/fix-capabilities.diff

  • 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
 
It's just insane to keep a table of capability names that can go
2
 
out of sync with capabilities.h at any time. Just generate the
3
 
table on the fly instead.
4
 
 
5
 
Index: b/security/apparmor/Makefile
6
 
===================================================================
7
 
--- a/security/apparmor/Makefile
8
 
+++ b/security/apparmor/Makefile
9
 
@@ -2,5 +2,12 @@
10
 
 #
11
 
 obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
12
 
 
13
 
-apparmor-y := main.o list.o procattr.o lsm.o apparmorfs.o capabilities.o \
14
 
+apparmor-y := main.o list.o procattr.o lsm.o apparmorfs.o \
15
 
              module_interface.o match.o
16
 
+
17
 
+quiet_cmd_make-caps = GEN     $@
18
 
+cmd_make-caps = sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z > $@
19
 
+
20
 
+$(obj)/main.o : $(obj)/capability_names.h
21
 
+$(obj)/capability_names.h : $(srctree)/include/linux/capability.h
22
 
+       $(call cmd,make-caps)
23
 
Index: b/security/apparmor/capabilities.c
24
 
===================================================================
25
 
--- a/security/apparmor/capabilities.c
26
 
+++ /dev/null
27
 
@@ -1,56 +0,0 @@
28
 
-/*
29
 
- *     Copyright (C) 2005 Novell/SUSE
30
 
- *
31
 
- *     This program is free software; you can redistribute it and/or
32
 
- *     modify it under the terms of the GNU General Public License as
33
 
- *     published by the Free Software Foundation, version 2 of the
34
 
- *     License.
35
 
- *
36
 
- *     AppArmor capability definitions
37
 
- */
38
 
-
39
 
-#include "apparmor.h"
40
 
-
41
 
-static const char *cap_names[] = {
42
 
-       "chown",
43
 
-       "dac_override",
44
 
-       "dac_read_search",
45
 
-       "fowner",
46
 
-       "fsetid",
47
 
-       "kill",
48
 
-       "setgid",
49
 
-       "setuid",
50
 
-       "setpcap",
51
 
-       "linux_immutable",
52
 
-       "net_bind_service",
53
 
-       "net_broadcast",
54
 
-       "net_admin",
55
 
-       "net_raw",
56
 
-       "ipc_lock",
57
 
-       "ipc_owner",
58
 
-       "sys_module",
59
 
-       "sys_rawio",
60
 
-       "sys_chroot",
61
 
-       "sys_ptrace",
62
 
-       "sys_pacct",
63
 
-       "sys_admin",
64
 
-       "sys_boot",
65
 
-       "sys_nice",
66
 
-       "sys_resource",
67
 
-       "sys_time",
68
 
-       "sys_tty_config",
69
 
-       "mknod",
70
 
-       "lease",
71
 
-       "audit_write",
72
 
-       "audit_control"
73
 
-};
74
 
-
75
 
-const char *capability_to_name(unsigned int cap)
76
 
-{
77
 
-       const char *name;
78
 
-
79
 
-       name = (cap < (sizeof(cap_names) / sizeof(char *))
80
 
-                  ? cap_names[cap] : "invalid-capability");
81
 
-
82
 
-       return name;
83
 
-}
84
 
Index: b/security/apparmor/main.c
85
 
===================================================================
86
 
--- a/security/apparmor/main.c
87
 
+++ b/security/apparmor/main.c
88
 
@@ -17,6 +17,13 @@
89
 
 
90
 
 #include "inline.h"
91
 
 
92
 
+/*
93
 
+ * A table of capability names: we generate it from capabilities.h.
94
 
+ */
95
 
+static const char *capability_names[] = {
96
 
+#include "capability_names.h"
97
 
+};
98
 
+
99
 
 /* NULL complain profile
100
 
  *
101
 
  * Used when in complain mode, to emit Permitting messages for non-existant
102
 
@@ -446,7 +453,7 @@ int aa_audit(struct aa_profile *active, 
103
 
        } else if (sa->type == AA_AUDITTYPE_CAP) {
104
 
                audit_log_format(ab,
105
 
                        "access to capability '%s' ",
106
 
-                       capability_to_name(sa->capability));
107
 
+                       capability_names[sa->capability]);
108
 
 
109
 
                opspec_error = -EPERM;
110
 
        } else if (sa->type == AA_AUDITTYPE_SYSCALL) {
111
 
Index: b/security/apparmor/apparmor.h
112
 
===================================================================
113
 
--- a/security/apparmor/apparmor.h
114
 
+++ b/security/apparmor/apparmor.h
115
 
@@ -267,9 +267,6 @@ extern int aa_setprocattr_setprofile(str
116
 
 extern int create_apparmorfs(void);
117
 
 extern void destroy_apparmorfs(void);
118
 
 
119
 
-/* capabilities.c */
120
 
-extern const char *capability_to_name(unsigned int cap);
121
 
-
122
 
 /* match.c */
123
 
 struct aa_dfa *aa_match_alloc(void);
124
 
 void aa_match_free(struct aa_dfa *dfa);