apparmor: add strn version of aa_find_ns

Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2017-01-16 00:42:22 -08:00
parent 1741e9eb8c
commit 9a2d40c12d
2 changed files with 33 additions and 10 deletions

View File

@ -82,6 +82,7 @@ void aa_free_root_ns(void);
void aa_free_ns_kref(struct kref *kref);
struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name);
struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n);
struct aa_ns *aa_prepare_ns(const char *name);
void __aa_remove_ns(struct aa_ns *ns);
@ -119,18 +120,24 @@ static inline void aa_put_ns(struct aa_ns *ns)
}
/**
* __aa_find_ns - find a namespace on a list by @name
* __aa_findn_ns - find a namespace on a list by @name
* @head: list to search for namespace on (NOT NULL)
* @name: name of namespace to look for (NOT NULL)
*
* @n: length of @name
* Returns: unrefcounted namespace
*
* Requires: rcu_read_lock be held
*/
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);
}
static inline struct aa_ns *__aa_find_ns(struct list_head *head,
const char *name)
{
return (struct aa_ns *)__policy_find(head, name);
return __aa_findn_ns(head, name, strlen(name));
}
#endif /* AA_NAMESPACE_H */

View File

@ -138,6 +138,28 @@ void aa_free_ns(struct aa_ns *ns)
kzfree(ns);
}
/**
* aa_findn_ns - look up a profile namespace on the namespace list
* @root: namespace to search in (NOT NULL)
* @name: name of namespace to find (NOT NULL)
* @n: length of @name
*
* Returns: a refcounted namespace on the list, or NULL if no namespace
* called @name exists.
*
* refcount released by caller
*/
struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n)
{
struct aa_ns *ns = NULL;
rcu_read_lock();
ns = aa_get_ns(__aa_findn_ns(&root->sub_ns, name, n));
rcu_read_unlock();
return ns;
}
/**
* aa_find_ns - look up a profile namespace on the namespace list
* @root: namespace to search in (NOT NULL)
@ -150,13 +172,7 @@ void aa_free_ns(struct aa_ns *ns)
*/
struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name)
{
struct aa_ns *ns = NULL;
rcu_read_lock();
ns = aa_get_ns(__aa_find_ns(&root->sub_ns, name));
rcu_read_unlock();
return ns;
return aa_findn_ns(root, name, strlen(name));
}
/**