aboutsummaryrefslogtreecommitdiffstats
path: root/security/apparmor/policy.c
diff options
context:
space:
mode:
authorJohn Johansen <john.johansen@canonical.com>2013-02-18 19:11:34 -0500
committerJohn Johansen <john.johansen@canonical.com>2013-04-28 03:37:24 -0400
commit4da05cc08da3f2058cecbe42ed9f4803d669730a (patch)
tree34be63209a5dd6034ad33bb9244047d34c2a3e42 /security/apparmor/policy.c
parenta4987857d2c958b93b2faafe0811eea1a63ff59a (diff)
apparmor: move the free_profile fn ahead of aa_alloc_profile
Move the free_profile fn ahead of aa_alloc_profile so it can be used in aa_alloc_profile without a forward declaration. Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Kees Cook <kees@ubuntu.com>
Diffstat (limited to 'security/apparmor/policy.c')
-rw-r--r--security/apparmor/policy.c150
1 files changed, 75 insertions, 75 deletions
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 13fc9efddd5d..f4ee72b44de4 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -635,81 +635,6 @@ void __init aa_free_root_ns(void)
635} 635}
636 636
637/** 637/**
638 * aa_alloc_profile - allocate, initialize and return a new profile
639 * @hname: name of the profile (NOT NULL)
640 *
641 * Returns: refcount profile or NULL on failure
642 */
643struct aa_profile *aa_alloc_profile(const char *hname)
644{
645 struct aa_profile *profile;
646
647 /* freed by free_profile - usually through aa_put_profile */
648 profile = kzalloc(sizeof(*profile), GFP_KERNEL);
649 if (!profile)
650 return NULL;
651
652 if (!policy_init(&profile->base, NULL, hname)) {
653 kzfree(profile);
654 return NULL;
655 }
656
657 /* refcount released by caller */
658 return profile;
659}
660
661/**
662 * aa_new_null_profile - create a new null-X learning profile
663 * @parent: profile that caused this profile to be created (NOT NULL)
664 * @hat: true if the null- learning profile is a hat
665 *
666 * Create a null- complain mode profile used in learning mode. The name of
667 * the profile is unique and follows the format of parent//null-<uniq>.
668 *
669 * null profiles are added to the profile list but the list does not
670 * hold a count on them so that they are automatically released when
671 * not in use.
672 *
673 * Returns: new refcounted profile else NULL on failure
674 */
675struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat)
676{
677 struct aa_profile *profile = NULL;
678 char *name;
679 int uniq = atomic_inc_return(&parent->ns->uniq_null);
680
681 /* freed below */
682 name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, GFP_KERNEL);
683 if (!name)
684 goto fail;
685 sprintf(name, "%s//null-%x", parent->base.hname, uniq);
686
687 profile = aa_alloc_profile(name);
688 kfree(name);
689 if (!profile)
690 goto fail;
691
692 profile->mode = APPARMOR_COMPLAIN;
693 profile->flags = PFLAG_NULL;
694 if (hat)
695 profile->flags |= PFLAG_HAT;
696
697 /* released on free_profile */
698 profile->parent = aa_get_profile(parent);
699 profile->ns = aa_get_namespace(parent->ns);
700
701 write_lock(&profile->ns->lock);
702 __list_add_profile(&parent->base.profiles, profile);
703 write_unlock(&profile->ns->lock);
704
705 /* refcount released by caller */
706 return profile;
707
708fail:
709 return NULL;
710}
711
712/**
713 * free_profile - free a profile 638 * free_profile - free a profile
714 * @profile: the profile to free (MAYBE NULL) 639 * @profile: the profile to free (MAYBE NULL)
715 * 640 *
@@ -786,6 +711,81 @@ void aa_free_profile_kref(struct kref *kref)
786 free_profile(p); 711 free_profile(p);
787} 712}
788 713
714/**
715 * aa_alloc_profile - allocate, initialize and return a new profile
716 * @hname: name of the profile (NOT NULL)
717 *
718 * Returns: refcount profile or NULL on failure
719 */
720struct aa_profile *aa_alloc_profile(const char *hname)
721{
722 struct aa_profile *profile;
723
724 /* freed by free_profile - usually through aa_put_profile */
725 profile = kzalloc(sizeof(*profile), GFP_KERNEL);
726 if (!profile)
727 return NULL;
728
729 if (!policy_init(&profile->base, NULL, hname)) {
730 kzfree(profile);
731 return NULL;
732 }
733
734 /* refcount released by caller */
735 return profile;
736}
737
738/**
739 * aa_new_null_profile - create a new null-X learning profile
740 * @parent: profile that caused this profile to be created (NOT NULL)
741 * @hat: true if the null- learning profile is a hat
742 *
743 * Create a null- complain mode profile used in learning mode. The name of
744 * the profile is unique and follows the format of parent//null-<uniq>.
745 *
746 * null profiles are added to the profile list but the list does not
747 * hold a count on them so that they are automatically released when
748 * not in use.
749 *
750 * Returns: new refcounted profile else NULL on failure
751 */
752struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat)
753{
754 struct aa_profile *profile = NULL;
755 char *name;
756 int uniq = atomic_inc_return(&parent->ns->uniq_null);
757
758 /* freed below */
759 name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, GFP_KERNEL);
760 if (!name)
761 goto fail;
762 sprintf(name, "%s//null-%x", parent->base.hname, uniq);
763
764 profile = aa_alloc_profile(name);
765 kfree(name);
766 if (!profile)
767 goto fail;
768
769 profile->mode = APPARMOR_COMPLAIN;
770 profile->flags = PFLAG_NULL;
771 if (hat)
772 profile->flags |= PFLAG_HAT;
773
774 /* released on free_profile */
775 profile->parent = aa_get_profile(parent);
776 profile->ns = aa_get_namespace(parent->ns);
777
778 write_lock(&profile->ns->lock);
779 __list_add_profile(&parent->base.profiles, profile);
780 write_unlock(&profile->ns->lock);
781
782 /* refcount released by caller */
783 return profile;
784
785fail:
786 return NULL;
787}
788
789/* TODO: profile accounting - setup in remove */ 789/* TODO: profile accounting - setup in remove */
790 790
791/** 791/**