2017-01-16 01:42:15 -07:00
|
|
|
/*
|
|
|
|
* AppArmor security module
|
|
|
|
*
|
|
|
|
* This file contains AppArmor policy definitions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998-2008 Novell/SUSE
|
|
|
|
* Copyright 2009-2017 Canonical Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation, version 2 of the
|
|
|
|
* License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __AA_NAMESPACE_H
|
|
|
|
#define __AA_NAMESPACE_H
|
|
|
|
|
|
|
|
#include <linux/kref.h>
|
|
|
|
|
|
|
|
#include "apparmor.h"
|
|
|
|
#include "apparmorfs.h"
|
|
|
|
#include "policy.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* struct aa_ns_acct - accounting of profiles in namespace
|
|
|
|
* @max_size: maximum space allowed for all profiles in namespace
|
|
|
|
* @max_count: maximum number of profiles that can be in this namespace
|
|
|
|
* @size: current size of profiles
|
|
|
|
* @count: current count of profiles (includes null profiles)
|
|
|
|
*/
|
|
|
|
struct aa_ns_acct {
|
|
|
|
int max_size;
|
|
|
|
int max_count;
|
|
|
|
int size;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
2017-01-16 01:42:16 -07:00
|
|
|
/* struct aa_ns - namespace for a set of profiles
|
2017-01-16 01:42:15 -07:00
|
|
|
* @base: common policy
|
|
|
|
* @parent: parent of namespace
|
|
|
|
* @lock: lock for modifying the object
|
|
|
|
* @acct: accounting for the namespace
|
|
|
|
* @unconfined: special unconfined profile for the namespace
|
|
|
|
* @sub_ns: list of namespaces under the current namespace.
|
|
|
|
* @uniq_null: uniq value used for null learning profiles
|
|
|
|
* @uniq_id: a unique id count for the profiles in the namespace
|
2017-01-16 01:42:45 -07:00
|
|
|
* @level: level of ns within the tree hierarchy
|
2017-01-16 01:42:15 -07:00
|
|
|
* @dents: dentries for the namespaces file entries in apparmorfs
|
|
|
|
*
|
2017-01-16 01:42:24 -07:00
|
|
|
* An aa_ns defines the set profiles that are searched to determine which
|
|
|
|
* profile to attach to a task. Profiles can not be shared between aa_ns
|
|
|
|
* and profile names within a namespace are guaranteed to be unique. When
|
|
|
|
* profiles in separate namespaces have the same name they are NOT considered
|
|
|
|
* to be equivalent.
|
2017-01-16 01:42:15 -07:00
|
|
|
*
|
|
|
|
* Namespaces are hierarchical and only namespaces and profiles below the
|
|
|
|
* current namespace are visible.
|
|
|
|
*
|
|
|
|
* Namespace names must be unique and can not contain the characters :/\0
|
|
|
|
*/
|
2017-01-16 01:42:16 -07:00
|
|
|
struct aa_ns {
|
2017-01-16 01:42:15 -07:00
|
|
|
struct aa_policy base;
|
2017-01-16 01:42:16 -07:00
|
|
|
struct aa_ns *parent;
|
2017-01-16 01:42:15 -07:00
|
|
|
struct mutex lock;
|
|
|
|
struct aa_ns_acct acct;
|
|
|
|
struct aa_profile *unconfined;
|
|
|
|
struct list_head sub_ns;
|
|
|
|
atomic_t uniq_null;
|
|
|
|
long uniq_id;
|
2017-01-16 01:42:45 -07:00
|
|
|
int level;
|
2017-05-09 01:08:41 -06:00
|
|
|
long revision;
|
2017-05-26 17:27:58 -06:00
|
|
|
wait_queue_head_t wait;
|
2017-05-09 01:08:41 -06:00
|
|
|
|
|
|
|
struct list_head rawdata_list;
|
2017-01-16 01:42:15 -07:00
|
|
|
|
|
|
|
struct dentry *dents[AAFS_NS_SIZEOF];
|
|
|
|
};
|
|
|
|
|
2017-01-16 01:42:16 -07:00
|
|
|
extern struct aa_ns *root_ns;
|
2017-01-16 01:42:15 -07:00
|
|
|
|
|
|
|
extern const char *aa_hidden_ns_name;
|
|
|
|
|
2017-01-16 01:42:25 -07:00
|
|
|
bool aa_ns_visible(struct aa_ns *curr, struct aa_ns *view, bool subns);
|
|
|
|
const char *aa_ns_name(struct aa_ns *parent, struct aa_ns *child, bool subns);
|
2017-01-16 01:42:16 -07:00
|
|
|
void aa_free_ns(struct aa_ns *ns);
|
2017-01-16 01:42:15 -07:00
|
|
|
int aa_alloc_root_ns(void);
|
|
|
|
void aa_free_root_ns(void);
|
2017-01-16 01:42:16 -07:00
|
|
|
void aa_free_ns_kref(struct kref *kref);
|
2017-01-16 01:42:15 -07:00
|
|
|
|
2017-01-16 01:42:16 -07:00
|
|
|
struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name);
|
2017-01-16 01:42:22 -07:00
|
|
|
struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n);
|
2017-06-02 18:44:27 -06:00
|
|
|
struct aa_ns *__aa_lookupn_ns(struct aa_ns *view, const char *hname, size_t n);
|
|
|
|
struct aa_ns *aa_lookupn_ns(struct aa_ns *view, const char *name, size_t n);
|
2017-01-16 01:42:34 -07:00
|
|
|
struct aa_ns *__aa_find_or_create_ns(struct aa_ns *parent, const char *name,
|
|
|
|
struct dentry *dir);
|
|
|
|
struct aa_ns *aa_prepare_ns(struct aa_ns *root, const char *name);
|
2017-01-16 01:42:16 -07:00
|
|
|
void __aa_remove_ns(struct aa_ns *ns);
|
2017-01-16 01:42:15 -07:00
|
|
|
|
|
|
|
static inline struct aa_profile *aa_deref_parent(struct aa_profile *p)
|
|
|
|
{
|
|
|
|
return rcu_dereference_protected(p->parent,
|
|
|
|
mutex_is_locked(&p->ns->lock));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 01:42:16 -07:00
|
|
|
* aa_get_ns - increment references count on @ns
|
2017-01-16 01:42:15 -07:00
|
|
|
* @ns: namespace to increment reference count of (MAYBE NULL)
|
|
|
|
*
|
|
|
|
* Returns: pointer to @ns, if @ns is NULL returns NULL
|
|
|
|
* Requires: @ns must be held with valid refcount when called
|
|
|
|
*/
|
2017-01-16 01:42:16 -07:00
|
|
|
static inline struct aa_ns *aa_get_ns(struct aa_ns *ns)
|
2017-01-16 01:42:15 -07:00
|
|
|
{
|
|
|
|
if (ns)
|
|
|
|
aa_get_profile(ns->unconfined);
|
|
|
|
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 01:42:16 -07:00
|
|
|
* aa_put_ns - decrement refcount on @ns
|
2017-01-16 01:42:15 -07:00
|
|
|
* @ns: namespace to put reference of
|
|
|
|
*
|
|
|
|
* Decrement reference count of @ns and if no longer in use free it
|
|
|
|
*/
|
2017-01-16 01:42:16 -07:00
|
|
|
static inline void aa_put_ns(struct aa_ns *ns)
|
2017-01-16 01:42:15 -07:00
|
|
|
{
|
|
|
|
if (ns)
|
|
|
|
aa_put_profile(ns->unconfined);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 01:42:22 -07:00
|
|
|
* __aa_findn_ns - find a namespace on a list by @name
|
2017-01-16 01:42:15 -07:00
|
|
|
* @head: list to search for namespace on (NOT NULL)
|
|
|
|
* @name: name of namespace to look for (NOT NULL)
|
2017-01-16 01:42:22 -07:00
|
|
|
* @n: length of @name
|
2017-01-16 01:42:15 -07:00
|
|
|
* Returns: unrefcounted namespace
|
|
|
|
*
|
|
|
|
* Requires: rcu_read_lock be held
|
|
|
|
*/
|
2017-01-16 01:42:22 -07:00
|
|
|
static inline struct aa_ns *__aa_findn_ns(struct list_head *head,
|
|
|
|
const char *name, size_t n)
|
|
|
|
{
|
|
|
|
return (struct aa_ns *)__policy_strn_find(head, name, n);
|
|
|
|
}
|
|
|
|
|
2017-01-16 01:42:16 -07:00
|
|
|
static inline struct aa_ns *__aa_find_ns(struct list_head *head,
|
|
|
|
const char *name)
|
2017-01-16 01:42:15 -07:00
|
|
|
{
|
2017-01-16 01:42:22 -07:00
|
|
|
return __aa_findn_ns(head, name, strlen(name));
|
2017-01-16 01:42:15 -07:00
|
|
|
}
|
|
|
|
|
2017-06-02 18:44:27 -06:00
|
|
|
static inline struct aa_ns *__aa_lookup_ns(struct aa_ns *base,
|
|
|
|
const char *hname)
|
|
|
|
{
|
|
|
|
return __aa_lookupn_ns(base, hname, strlen(hname));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct aa_ns *aa_lookup_ns(struct aa_ns *view, const char *name)
|
|
|
|
{
|
|
|
|
return aa_lookupn_ns(view, name, strlen(name));
|
|
|
|
}
|
|
|
|
|
2017-01-16 01:42:15 -07:00
|
|
|
#endif /* AA_NAMESPACE_H */
|