Commit 9a2d40c12d00ead1b1a3ac8383d2d66e35674fdb

Authored by John Johansen
1 parent 1741e9eb8c

apparmor: add strn version of aa_find_ns

Signed-off-by: John Johansen <john.johansen@canonical.com>

Showing 2 changed files with 29 additions and 6 deletions Side-by-side Diff

security/apparmor/include/policy_ns.h
... ... @@ -82,6 +82,7 @@
82 82 void aa_free_ns_kref(struct kref *kref);
83 83  
84 84 struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name);
  85 +struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n);
85 86 struct aa_ns *aa_prepare_ns(const char *name);
86 87 void __aa_remove_ns(struct aa_ns *ns);
87 88  
88 89  
89 90  
90 91  
... ... @@ -119,18 +120,24 @@
119 120 }
120 121  
121 122 /**
122   - * __aa_find_ns - find a namespace on a list by @name
  123 + * __aa_findn_ns - find a namespace on a list by @name
123 124 * @head: list to search for namespace on (NOT NULL)
124 125 * @name: name of namespace to look for (NOT NULL)
125   - *
  126 + * @n: length of @name
126 127 * Returns: unrefcounted namespace
127 128 *
128 129 * Requires: rcu_read_lock be held
129 130 */
  131 +static inline struct aa_ns *__aa_findn_ns(struct list_head *head,
  132 + const char *name, size_t n)
  133 +{
  134 + return (struct aa_ns *)__policy_strn_find(head, name, n);
  135 +}
  136 +
130 137 static inline struct aa_ns *__aa_find_ns(struct list_head *head,
131 138 const char *name)
132 139 {
133   - return (struct aa_ns *)__policy_find(head, name);
  140 + return __aa_findn_ns(head, name, strlen(name));
134 141 }
135 142  
136 143 #endif /* AA_NAMESPACE_H */
security/apparmor/policy_ns.c
... ... @@ -139,24 +139,40 @@
139 139 }
140 140  
141 141 /**
142   - * aa_find_ns - look up a profile namespace on the namespace list
  142 + * aa_findn_ns - look up a profile namespace on the namespace list
143 143 * @root: namespace to search in (NOT NULL)
144 144 * @name: name of namespace to find (NOT NULL)
  145 + * @n: length of @name
145 146 *
146 147 * Returns: a refcounted namespace on the list, or NULL if no namespace
147 148 * called @name exists.
148 149 *
149 150 * refcount released by caller
150 151 */
151   -struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name)
  152 +struct aa_ns *aa_findn_ns(struct aa_ns *root, const char *name, size_t n)
152 153 {
153 154 struct aa_ns *ns = NULL;
154 155  
155 156 rcu_read_lock();
156   - ns = aa_get_ns(__aa_find_ns(&root->sub_ns, name));
  157 + ns = aa_get_ns(__aa_findn_ns(&root->sub_ns, name, n));
157 158 rcu_read_unlock();
158 159  
159 160 return ns;
  161 +}
  162 +
  163 +/**
  164 + * aa_find_ns - look up a profile namespace on the namespace list
  165 + * @root: namespace to search in (NOT NULL)
  166 + * @name: name of namespace to find (NOT NULL)
  167 + *
  168 + * Returns: a refcounted namespace on the list, or NULL if no namespace
  169 + * called @name exists.
  170 + *
  171 + * refcount released by caller
  172 + */
  173 +struct aa_ns *aa_find_ns(struct aa_ns *root, const char *name)
  174 +{
  175 + return aa_findn_ns(root, name, strlen(name));
160 176 }
161 177  
162 178 /**