Skip to content

Commit

Permalink
AppArmor: Abstract use of cred security blob
Browse files Browse the repository at this point in the history
Don't use the cred->security pointer directly.
Provide a helper function that provides the security blob pointer.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
[kees: adjusted for ordered init series]
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
Casey Schaufler authored and Kees Cook committed Jan 8, 2019
1 parent 3d25252 commit 69b5a44
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion security/apparmor/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm)
}
aa_put_label(cred_label(bprm->cred));
/* transfer reference, released when cred is freed */
cred_label(bprm->cred) = new;
set_cred_label(bprm->cred, new);

done:
aa_put_label(label);
Expand Down
16 changes: 15 additions & 1 deletion security/apparmor/include/cred.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,22 @@
#include "policy_ns.h"
#include "task.h"

#define cred_label(X) ((X)->security)
static inline struct aa_label *cred_label(const struct cred *cred)
{
struct aa_label **blob = cred->security;

AA_BUG(!blob);
return *blob;
}

static inline void set_cred_label(const struct cred *cred,
struct aa_label *label)
{
struct aa_label **blob = cred->security;

AA_BUG(!blob);
*blob = label;
}

/**
* aa_cred_raw_label - obtain cred's label
Expand Down
10 changes: 5 additions & 5 deletions security/apparmor/lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ DEFINE_PER_CPU(struct aa_buffers, aa_buffers);
static void apparmor_cred_free(struct cred *cred)
{
aa_put_label(cred_label(cred));
cred_label(cred) = NULL;
set_cred_label(cred, NULL);
}

/*
* allocate the apparmor part of blank credentials
*/
static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
{
cred_label(cred) = NULL;
set_cred_label(cred, NULL);
return 0;
}

Expand All @@ -78,7 +78,7 @@ static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
gfp_t gfp)
{
cred_label(new) = aa_get_newest_label(cred_label(old));
set_cred_label(new, aa_get_newest_label(cred_label(old)));
return 0;
}

Expand All @@ -87,7 +87,7 @@ static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
*/
static void apparmor_cred_transfer(struct cred *new, const struct cred *old)
{
cred_label(new) = aa_get_newest_label(cred_label(old));
set_cred_label(new, aa_get_newest_label(cred_label(old)));
}

static void apparmor_task_free(struct task_struct *task)
Expand Down Expand Up @@ -1485,7 +1485,7 @@ static int __init set_init_ctx(void)
if (!ctx)
return -ENOMEM;

cred_label(cred) = aa_get_label(ns_unconfined(root_ns));
set_cred_label(cred, aa_get_label(ns_unconfined(root_ns)));
task_ctx(current) = ctx;

return 0;
Expand Down
6 changes: 3 additions & 3 deletions security/apparmor/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int aa_replace_current_label(struct aa_label *label)
*/
aa_get_label(label);
aa_put_label(cred_label(new));
cred_label(new) = label;
set_cred_label(new, label);

commit_creds(new);
return 0;
Expand Down Expand Up @@ -138,7 +138,7 @@ int aa_set_current_hat(struct aa_label *label, u64 token)
return -EACCES;
}

cred_label(new) = aa_get_newest_label(label);
set_cred_label(new, aa_get_newest_label(label));
/* clear exec on switching context */
aa_put_label(ctx->onexec);
ctx->onexec = NULL;
Expand Down Expand Up @@ -172,7 +172,7 @@ int aa_restore_previous_label(u64 token)
return -ENOMEM;

aa_put_label(cred_label(new));
cred_label(new) = aa_get_newest_label(ctx->previous);
set_cred_label(new, aa_get_newest_label(ctx->previous));
AA_BUG(!cred_label(new));
/* clear exec && prev information when restoring to previous context */
aa_clear_task_ctx_trans(ctx);
Expand Down

0 comments on commit 69b5a44

Please sign in to comment.