Skip to content

Commit 716d384

Browse files
committed
apparmor: make fn_label_build() capable of handling not supported
Currently fn_label_build() callback fns must provide a transition or failure. Change this so that a callback can indicate it should be skipped/not be involved in the label being built. This will be useful when building object labels based on mediation flags, as to whether the label should be set. Existing callers can keep treating NULL return as an error because none of those callback fns support skipping, but instead of the old error handling replace with AA_BUG. Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent ed7cc1c commit 716d384

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • security/apparmor/include

security/apparmor/include/lib.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,15 @@ void aa_policy_destroy(struct aa_policy *policy);
281281
* @FN: fn to call for each profile transition. @P is set to the profile
282282
*
283283
* Returns: new label on success
284+
* NULL if all callbacks decline to specify a transition
284285
* ERR_PTR if build @FN fails
285286
*
286-
* @FN must return a label or ERR_PTR on failure. NULL is not allowed
287+
* @FN must return a label or ERR_PTR on failure.
287288
*/
288289
#define fn_label_build(L, P, GFP, FN) \
289290
({ \
290291
__label__ __do_cleanup, __done; \
291-
struct aa_label *__new_; \
292+
struct aa_label *__new_ = NULL; \
292293
\
293294
if ((L)->size > 1) { \
294295
/* TODO: add cache of transitions already done */ \
@@ -303,11 +304,15 @@ void aa_policy_destroy(struct aa_policy *policy);
303304
__j = 0; \
304305
label_for_each(__i, (L), (P)) { \
305306
__new_ = (FN); \
306-
AA_BUG(!__new_); \
307+
if (!__new_) \
308+
continue; \
307309
if (IS_ERR(__new_)) \
308310
goto __do_cleanup; \
309311
__lvec[__j++] = __new_; \
310312
} \
313+
if (__j == 0) \
314+
/* no components adding to build */ \
315+
goto __do_cleanup; \
311316
for (__j = __count = 0; __j < (L)->size; __j++) \
312317
__count += __lvec[__j]->size; \
313318
if (!vec_setup(profile, __pvec, __count, (GFP))) { \
@@ -331,12 +336,10 @@ __do_cleanup: \
331336
} else { \
332337
(P) = labels_profile(L); \
333338
__new_ = (FN); \
334-
AA_BUG(!__new_); \
335339
} \
336340
__done: \
337341
if (PTR_ERR(__new_)) \
338342
AA_DEBUG(DEBUG_LABEL, "label build failed\n"); \
339-
AA_BUG(!__new_); \
340343
(__new_); \
341344
})
342345

0 commit comments

Comments
 (0)