1 From 50d30adbef98a0b6cc531a9413d05f564eb633ee Mon Sep 17 00:00:00 2001
2 From: John Johansen <john.johansen@canonical.com>
3 Date: Wed, 16 Aug 2017 08:59:57 -0700
4 Subject: [PATCH 13/17] apparmor: move new_null_profile to after profile lookup
7 new_null_profile will need to use some of the profile lookup fns()
8 so move instead of doing forward fn declarations.
10 Signed-off-by: John Johansen <john.johansen@canonical.com>
11 (cherry picked from commit cf1e50dfc6f627bc2989b57076b129c330fb3f0a)
13 security/apparmor/policy.c | 158 ++++++++++++++++++++++-----------------------
14 1 file changed, 79 insertions(+), 79 deletions(-)
16 diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
17 index 244ea4a4a8f0..a81a384a63b1 100644
18 --- a/security/apparmor/policy.c
19 +++ b/security/apparmor/policy.c
20 @@ -289,85 +289,6 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
25 - * aa_new_null_profile - create or find a null-X learning profile
26 - * @parent: profile that caused this profile to be created (NOT NULL)
27 - * @hat: true if the null- learning profile is a hat
28 - * @base: name to base the null profile off of
29 - * @gfp: type of allocation
31 - * Find/Create a null- complain mode profile used in learning mode. The
32 - * name of the profile is unique and follows the format of parent//null-XXX.
33 - * where XXX is based on the @name or if that fails or is not supplied
36 - * null profiles are added to the profile list but the list does not
37 - * hold a count on them so that they are automatically released when
40 - * Returns: new refcounted profile else NULL on failure
42 -struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
43 - const char *base, gfp_t gfp)
45 - struct aa_profile *profile;
51 - name = kmalloc(strlen(parent->base.hname) + 8 + strlen(base),
54 - sprintf(name, "%s//null-%s", parent->base.hname, base);
57 - /* fall through to try shorter uniq */
60 - name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, gfp);
63 - sprintf(name, "%s//null-%x", parent->base.hname,
64 - atomic_inc_return(&parent->ns->uniq_null));
67 - /* lookup to see if this is a dup creation */
68 - profile = aa_find_child(parent, basename(name));
72 - profile = aa_alloc_profile(name, NULL, gfp);
76 - profile->mode = APPARMOR_COMPLAIN;
77 - profile->label.flags |= FLAG_NULL;
79 - profile->label.flags |= FLAG_HAT;
80 - profile->path_flags = parent->path_flags;
82 - /* released on free_profile */
83 - rcu_assign_pointer(profile->parent, aa_get_profile(parent));
84 - profile->ns = aa_get_ns(parent->ns);
85 - profile->file.dfa = aa_get_dfa(nulldfa);
86 - profile->policy.dfa = aa_get_dfa(nulldfa);
88 - mutex_lock(&profile->ns->lock);
89 - __add_profile(&parent->base.profiles, profile);
90 - mutex_unlock(&profile->ns->lock);
92 - /* refcount released by caller */
99 - aa_free_profile(profile);
103 /* TODO: profile accounting - setup in remove */
106 @@ -559,6 +480,85 @@ struct aa_profile *aa_fqlookupn_profile(struct aa_label *base,
110 + * aa_new_null_profile - create or find a null-X learning profile
111 + * @parent: profile that caused this profile to be created (NOT NULL)
112 + * @hat: true if the null- learning profile is a hat
113 + * @base: name to base the null profile off of
114 + * @gfp: type of allocation
116 + * Find/Create a null- complain mode profile used in learning mode. The
117 + * name of the profile is unique and follows the format of parent//null-XXX.
118 + * where XXX is based on the @name or if that fails or is not supplied
121 + * null profiles are added to the profile list but the list does not
122 + * hold a count on them so that they are automatically released when
125 + * Returns: new refcounted profile else NULL on failure
127 +struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
128 + const char *base, gfp_t gfp)
130 + struct aa_profile *profile;
136 + name = kmalloc(strlen(parent->base.hname) + 8 + strlen(base),
139 + sprintf(name, "%s//null-%s", parent->base.hname, base);
142 + /* fall through to try shorter uniq */
145 + name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, gfp);
148 + sprintf(name, "%s//null-%x", parent->base.hname,
149 + atomic_inc_return(&parent->ns->uniq_null));
152 + /* lookup to see if this is a dup creation */
153 + profile = aa_find_child(parent, basename(name));
157 + profile = aa_alloc_profile(name, NULL, gfp);
161 + profile->mode = APPARMOR_COMPLAIN;
162 + profile->label.flags |= FLAG_NULL;
164 + profile->label.flags |= FLAG_HAT;
165 + profile->path_flags = parent->path_flags;
167 + /* released on free_profile */
168 + rcu_assign_pointer(profile->parent, aa_get_profile(parent));
169 + profile->ns = aa_get_ns(parent->ns);
170 + profile->file.dfa = aa_get_dfa(nulldfa);
171 + profile->policy.dfa = aa_get_dfa(nulldfa);
173 + mutex_lock(&profile->ns->lock);
174 + __add_profile(&parent->base.profiles, profile);
175 + mutex_unlock(&profile->ns->lock);
177 + /* refcount released by caller */
184 + aa_free_profile(profile);
189 * replacement_allowed - test to see if replacement is allowed
190 * @profile: profile to test if it can be replaced (MAYBE NULL)
191 * @noreplace: true if replacement shouldn't be allowed but addition is okay