Path: blob/master/security/apparmor/include/policy_ns.h
26444 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* AppArmor security module3*4* This file contains AppArmor policy definitions.5*6* Copyright (C) 1998-2008 Novell/SUSE7* Copyright 2009-2017 Canonical Ltd.8*/910#ifndef __AA_NAMESPACE_H11#define __AA_NAMESPACE_H1213#include <linux/kref.h>1415#include "apparmor.h"16#include "apparmorfs.h"17#include "label.h"18#include "policy.h"192021/* struct aa_ns_acct - accounting of profiles in namespace22* @max_size: maximum space allowed for all profiles in namespace23* @max_count: maximum number of profiles that can be in this namespace24* @size: current size of profiles25* @count: current count of profiles (includes null profiles)26*/27struct aa_ns_acct {28int max_size;29int max_count;30int size;31int count;32};3334/* struct aa_ns - namespace for a set of profiles35* @base: common policy36* @parent: parent of namespace37* @lock: lock for modifying the object38* @acct: accounting for the namespace39* @unconfined: special unconfined profile for the namespace40* @sub_ns: list of namespaces under the current namespace.41* @uniq_null: uniq value used for null learning profiles42* @uniq_id: a unique id count for the profiles in the namespace43* @level: level of ns within the tree hierarchy44* @dents: dentries for the namespaces file entries in apparmorfs45*46* An aa_ns defines the set profiles that are searched to determine which47* profile to attach to a task. Profiles can not be shared between aa_ns48* and profile names within a namespace are guaranteed to be unique. When49* profiles in separate namespaces have the same name they are NOT considered50* to be equivalent.51*52* Namespaces are hierarchical and only namespaces and profiles below the53* current namespace are visible.54*55* Namespace names must be unique and can not contain the characters :/\056*/57struct aa_ns {58struct aa_policy base;59struct aa_ns *parent;60struct mutex lock;61struct aa_ns_acct acct;62struct aa_profile *unconfined;63struct list_head sub_ns;64atomic_t uniq_null;65long uniq_id;66int level;67long revision;68wait_queue_head_t wait;6970struct aa_labelset labels;71struct list_head rawdata_list;7273struct dentry *dents[AAFS_NS_SIZEOF];74};7576extern struct aa_label *kernel_t;77extern struct aa_ns *root_ns;7879extern const char *aa_hidden_ns_name;8081#define ns_unconfined(NS) (&(NS)->unconfined->label)8283bool aa_ns_visible(struct aa_ns *curr, struct aa_ns *view, bool subns);84const char *aa_ns_name(struct aa_ns *parent, struct aa_ns *child, bool subns);85void aa_free_ns(struct aa_ns *ns);86int aa_alloc_root_ns(void);87void aa_free_root_ns(void);8889struct aa_ns *__aa_lookupn_ns(struct aa_ns *view, const char *hname, size_t n);90struct aa_ns *aa_lookupn_ns(struct aa_ns *view, const char *name, size_t n);91struct aa_ns *__aa_find_or_create_ns(struct aa_ns *parent, const char *name,92struct dentry *dir);93struct aa_ns *aa_prepare_ns(struct aa_ns *root, const char *name);94void __aa_remove_ns(struct aa_ns *ns);9596static inline struct aa_profile *aa_deref_parent(struct aa_profile *p)97{98return rcu_dereference_protected(p->parent,99mutex_is_locked(&p->ns->lock));100}101102/**103* aa_get_ns - increment references count on @ns104* @ns: namespace to increment reference count of (MAYBE NULL)105*106* Returns: pointer to @ns, if @ns is NULL returns NULL107* Requires: @ns must be held with valid refcount when called108*/109static inline struct aa_ns *aa_get_ns(struct aa_ns *ns)110{111if (ns)112aa_get_profile(ns->unconfined);113114return ns;115}116117/**118* aa_put_ns - decrement refcount on @ns119* @ns: namespace to put reference of120*121* Decrement reference count of @ns and if no longer in use free it122*/123static inline void aa_put_ns(struct aa_ns *ns)124{125if (ns)126aa_put_profile(ns->unconfined);127}128129/**130* __aa_findn_ns - find a namespace on a list by @name131* @head: list to search for namespace on (NOT NULL)132* @name: name of namespace to look for (NOT NULL)133* @n: length of @name134* Returns: unrefcounted namespace135*136* Requires: rcu_read_lock be held137*/138static inline struct aa_ns *__aa_findn_ns(struct list_head *head,139const char *name, size_t n)140{141return (struct aa_ns *)__policy_strn_find(head, name, n);142}143144static inline struct aa_ns *__aa_find_ns(struct list_head *head,145const char *name)146{147return __aa_findn_ns(head, name, strlen(name));148}149150#endif /* AA_NAMESPACE_H */151152153