Skip to content

Commit d07881d

Browse files
committed
apparmor: move new_null_profile to after profile lookup fns()
new_null_profile will need to use some of the profile lookup fns() so move instead of doing forward fn declarations. Signed-off-by: John Johansen <[email protected]>
1 parent 651e28c commit d07881d

File tree

1 file changed

+79
-79
lines changed

1 file changed

+79
-79
lines changed

security/apparmor/policy.c

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -289,85 +289,6 @@ struct aa_profile *aa_alloc_profile(const char *hname, struct aa_proxy *proxy,
289289
return NULL;
290290
}
291291

292-
/**
293-
* aa_new_null_profile - create or find a null-X learning profile
294-
* @parent: profile that caused this profile to be created (NOT NULL)
295-
* @hat: true if the null- learning profile is a hat
296-
* @base: name to base the null profile off of
297-
* @gfp: type of allocation
298-
*
299-
* Find/Create a null- complain mode profile used in learning mode. The
300-
* name of the profile is unique and follows the format of parent//null-XXX.
301-
* where XXX is based on the @name or if that fails or is not supplied
302-
* a unique number
303-
*
304-
* null profiles are added to the profile list but the list does not
305-
* hold a count on them so that they are automatically released when
306-
* not in use.
307-
*
308-
* Returns: new refcounted profile else NULL on failure
309-
*/
310-
struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
311-
const char *base, gfp_t gfp)
312-
{
313-
struct aa_profile *profile;
314-
char *name;
315-
316-
AA_BUG(!parent);
317-
318-
if (base) {
319-
name = kmalloc(strlen(parent->base.hname) + 8 + strlen(base),
320-
gfp);
321-
if (name) {
322-
sprintf(name, "%s//null-%s", parent->base.hname, base);
323-
goto name;
324-
}
325-
/* fall through to try shorter uniq */
326-
}
327-
328-
name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, gfp);
329-
if (!name)
330-
return NULL;
331-
sprintf(name, "%s//null-%x", parent->base.hname,
332-
atomic_inc_return(&parent->ns->uniq_null));
333-
334-
name:
335-
/* lookup to see if this is a dup creation */
336-
profile = aa_find_child(parent, basename(name));
337-
if (profile)
338-
goto out;
339-
340-
profile = aa_alloc_profile(name, NULL, gfp);
341-
if (!profile)
342-
goto fail;
343-
344-
profile->mode = APPARMOR_COMPLAIN;
345-
profile->label.flags |= FLAG_NULL;
346-
if (hat)
347-
profile->label.flags |= FLAG_HAT;
348-
profile->path_flags = parent->path_flags;
349-
350-
/* released on free_profile */
351-
rcu_assign_pointer(profile->parent, aa_get_profile(parent));
352-
profile->ns = aa_get_ns(parent->ns);
353-
profile->file.dfa = aa_get_dfa(nulldfa);
354-
profile->policy.dfa = aa_get_dfa(nulldfa);
355-
356-
mutex_lock(&profile->ns->lock);
357-
__add_profile(&parent->base.profiles, profile);
358-
mutex_unlock(&profile->ns->lock);
359-
360-
/* refcount released by caller */
361-
out:
362-
kfree(name);
363-
364-
return profile;
365-
366-
fail:
367-
aa_free_profile(profile);
368-
return NULL;
369-
}
370-
371292
/* TODO: profile accounting - setup in remove */
372293

373294
/**
@@ -558,6 +479,85 @@ struct aa_profile *aa_fqlookupn_profile(struct aa_label *base,
558479
return profile;
559480
}
560481

482+
/**
483+
* aa_new_null_profile - create or find a null-X learning profile
484+
* @parent: profile that caused this profile to be created (NOT NULL)
485+
* @hat: true if the null- learning profile is a hat
486+
* @base: name to base the null profile off of
487+
* @gfp: type of allocation
488+
*
489+
* Find/Create a null- complain mode profile used in learning mode. The
490+
* name of the profile is unique and follows the format of parent//null-XXX.
491+
* where XXX is based on the @name or if that fails or is not supplied
492+
* a unique number
493+
*
494+
* null profiles are added to the profile list but the list does not
495+
* hold a count on them so that they are automatically released when
496+
* not in use.
497+
*
498+
* Returns: new refcounted profile else NULL on failure
499+
*/
500+
struct aa_profile *aa_new_null_profile(struct aa_profile *parent, bool hat,
501+
const char *base, gfp_t gfp)
502+
{
503+
struct aa_profile *profile;
504+
char *name;
505+
506+
AA_BUG(!parent);
507+
508+
if (base) {
509+
name = kmalloc(strlen(parent->base.hname) + 8 + strlen(base),
510+
gfp);
511+
if (name) {
512+
sprintf(name, "%s//null-%s", parent->base.hname, base);
513+
goto name;
514+
}
515+
/* fall through to try shorter uniq */
516+
}
517+
518+
name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, gfp);
519+
if (!name)
520+
return NULL;
521+
sprintf(name, "%s//null-%x", parent->base.hname,
522+
atomic_inc_return(&parent->ns->uniq_null));
523+
524+
name:
525+
/* lookup to see if this is a dup creation */
526+
profile = aa_find_child(parent, basename(name));
527+
if (profile)
528+
goto out;
529+
530+
profile = aa_alloc_profile(name, NULL, gfp);
531+
if (!profile)
532+
goto fail;
533+
534+
profile->mode = APPARMOR_COMPLAIN;
535+
profile->label.flags |= FLAG_NULL;
536+
if (hat)
537+
profile->label.flags |= FLAG_HAT;
538+
profile->path_flags = parent->path_flags;
539+
540+
/* released on free_profile */
541+
rcu_assign_pointer(profile->parent, aa_get_profile(parent));
542+
profile->ns = aa_get_ns(parent->ns);
543+
profile->file.dfa = aa_get_dfa(nulldfa);
544+
profile->policy.dfa = aa_get_dfa(nulldfa);
545+
546+
mutex_lock(&profile->ns->lock);
547+
__add_profile(&parent->base.profiles, profile);
548+
mutex_unlock(&profile->ns->lock);
549+
550+
/* refcount released by caller */
551+
out:
552+
kfree(name);
553+
554+
return profile;
555+
556+
fail:
557+
aa_free_profile(profile);
558+
return NULL;
559+
}
560+
561561
/**
562562
* replacement_allowed - test to see if replacement is allowed
563563
* @profile: profile to test if it can be replaced (MAYBE NULL)

0 commit comments

Comments
 (0)