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

« back to all changes in this revision

Viewing changes to kernel-patches/for-mainline/apparmor_getprocattr.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
 
Index: linux-2.6/security/apparmor/apparmor.h
2
 
===================================================================
3
 
--- linux-2.6.orig/security/apparmor/apparmor.h
4
 
+++ linux-2.6/security/apparmor/apparmor.h
5
 
@@ -253,7 +253,8 @@ extern void free_aa_profile(struct aa_pr
6
 
 extern void free_aa_profile_kref(struct kref *kref);
7
 
 
8
 
 /* procattr.c */
9
 
-extern size_t aa_getprocattr(struct aa_profile *profile, char *str, size_t size);
10
 
+extern int aa_getprocattr(struct aa_profile *profile, char **string,
11
 
+                         unsigned *len);
12
 
 extern int aa_setprocattr_changehat(char *hatinfo, size_t infosize);
13
 
 extern int aa_setprocattr_setprofile(struct task_struct *task,
14
 
                                     char *profilename,
15
 
Index: linux-2.6/security/apparmor/lsm.c
16
 
===================================================================
17
 
--- linux-2.6.orig/security/apparmor/lsm.c
18
 
+++ linux-2.6/security/apparmor/lsm.c
19
 
@@ -575,11 +575,11 @@ static void apparmor_task_reparent_to_in
20
 
 }
21
 
 
22
 
 static int apparmor_getprocattr(struct task_struct *task, char *name,
23
 
-                               void *value, size_t size)
24
 
+                               char **value)
25
 
 {
26
 
+       unsigned len;
27
 
        int error;
28
 
        struct aa_profile *profile;
29
 
-       char *str = value;
30
 
 
31
 
        /* AppArmor only supports the "current" process attribute */
32
 
        if (strcmp(name, "current") != 0) {
33
 
@@ -594,8 +594,10 @@ static int apparmor_getprocattr(struct t
34
 
        }
35
 
 
36
 
        profile = aa_get_profile(task);
37
 
-       error = aa_getprocattr(profile, str, size);
38
 
+       error = aa_getprocattr(profile, value, &len);
39
 
        aa_put_profile(profile);
40
 
+       if (!error)
41
 
+               error = len;
42
 
 
43
 
 out:
44
 
        return error;
45
 
Index: linux-2.6/security/apparmor/procattr.c
46
 
===================================================================
47
 
--- linux-2.6.orig/security/apparmor/procattr.c
48
 
+++ linux-2.6/security/apparmor/procattr.c
49
 
@@ -14,66 +14,45 @@
50
 
 #include "apparmor.h"
51
 
 #include "inline.h"
52
 
 
53
 
-size_t aa_getprocattr(struct aa_profile *profile, char *str, size_t size)
54
 
+int aa_getprocattr(struct aa_profile *profile, char **string, unsigned *len)
55
 
 {
56
 
-       int error = -EACCES;    /* default to a perm denied */
57
 
-       size_t len;
58
 
+       char *str;
59
 
 
60
 
        if (profile) {
61
 
-               size_t lena, lenm, lenp = 0;
62
 
-               const char *enforce_str = " (enforce)";
63
 
-               const char *complain_str = " (complain)";
64
 
-               const char *mode_str =
65
 
-                       PROFILE_COMPLAIN(profile) ? complain_str : enforce_str;
66
 
+               const char *mode_str = PROFILE_COMPLAIN(profile) ?
67
 
+                       " (complain)" : " (enforce)";
68
 
 
69
 
-               lenm = strlen(mode_str);
70
 
+               *len = ((profile != profile->parent) ?
71
 
+                          strlen(profile->parent->name) + 1 : 0) +
72
 
+                      strlen(mode_str) + strlen(profile->name) + 1;
73
 
+               str = kmalloc(*len, GFP_ATOMIC);
74
 
+               if (!str)
75
 
+                       return -ENOMEM;
76
 
 
77
 
-               lena = strlen(profile->name);
78
 
-
79
 
-               len = lena;
80
 
                if (profile != profile->parent) {
81
 
-                       lenp = strlen(profile->parent->name);
82
 
-                       len += (lenp + 1);      /* +1 for ^ */
83
 
-               }
84
 
-               /* DONT null terminate strings we output via proc */
85
 
-               len += (lenm + 1);      /* for \n */
86
 
-
87
 
-               if (len <= size) {
88
 
-                       if (lenp) {
89
 
-                               memcpy(str, profile->parent->name,
90
 
-                                      lenp);
91
 
-                               str += lenp;
92
 
-                               *str++ = '^';
93
 
-                       }
94
 
-
95
 
-                       memcpy(str, profile->name, lena);
96
 
-                       str += lena;
97
 
-                       memcpy(str, mode_str, lenm);
98
 
-                       str += lenm;
99
 
-                       *str++ = '\n';
100
 
-                       error = len;
101
 
-               } else if (size == 0) {
102
 
-                       error = len;
103
 
-               } else {
104
 
-                       error = -ERANGE;
105
 
+                       memcpy(str, profile->parent->name,
106
 
+                              strlen(profile->parent->name));
107
 
+                       str += strlen(profile->parent->name);
108
 
+                       *str++ = '^';
109
 
                }
110
 
+               memcpy(str, profile->name, strlen(profile->name));
111
 
+               str += strlen(profile->name);
112
 
+               memcpy(str, mode_str, strlen(mode_str));
113
 
+               str += strlen(mode_str);
114
 
+               *str++ = '\n';
115
 
        } else {
116
 
                const char *unconfined_str = "unconfined\n";
117
 
-               len = strlen(unconfined_str);
118
 
 
119
 
-               /* DONT null terminate strings we output via proc */
120
 
-               if (len <= size) {
121
 
-                       memcpy(str, unconfined_str, len);
122
 
-                       error = len;
123
 
-               } else if (size == 0) {
124
 
-                       error = len;
125
 
-               } else {
126
 
-                       error = -ERANGE;
127
 
-               }
128
 
+               *len = strlen(unconfined_str);
129
 
+               str = kmalloc(*len, GFP_ATOMIC);
130
 
+               if (!str)
131
 
+                       return -ENOMEM;
132
 
+               
133
 
+               memcpy(str, unconfined_str, *len);
134
 
        }
135
 
+       *string = str;
136
 
 
137
 
-       return error;
138
 
-
139
 
+       return 0;
140
 
 }
141
 
 
142
 
 int aa_setprocattr_changehat(char *hatinfo, size_t infosize)