123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #include "include/context.h"
- #include "include/policy.h"
- struct aa_task_cxt *aa_alloc_task_context(gfp_t flags)
- {
- return kzalloc(sizeof(struct aa_task_cxt), flags);
- }
- void aa_free_task_context(struct aa_task_cxt *cxt)
- {
- if (cxt) {
- aa_put_profile(cxt->profile);
- aa_put_profile(cxt->previous);
- aa_put_profile(cxt->onexec);
- kzfree(cxt);
- }
- }
- void aa_dup_task_context(struct aa_task_cxt *new, const struct aa_task_cxt *old)
- {
- *new = *old;
- aa_get_profile(new->profile);
- aa_get_profile(new->previous);
- aa_get_profile(new->onexec);
- }
- struct aa_profile *aa_get_task_profile(struct task_struct *task)
- {
- struct aa_profile *p;
- rcu_read_lock();
- p = aa_get_profile(__aa_task_profile(task));
- rcu_read_unlock();
- return p;
- }
- int aa_replace_current_profile(struct aa_profile *profile)
- {
- struct aa_task_cxt *cxt = current_cxt();
- struct cred *new;
- BUG_ON(!profile);
- if (cxt->profile == profile)
- return 0;
- new = prepare_creds();
- if (!new)
- return -ENOMEM;
- cxt = cred_cxt(new);
- if (unconfined(profile) || (cxt->profile->ns != profile->ns))
-
- aa_clear_task_cxt_trans(cxt);
-
- aa_get_profile(profile);
- aa_put_profile(cxt->profile);
- cxt->profile = profile;
- commit_creds(new);
- return 0;
- }
- int aa_set_current_onexec(struct aa_profile *profile)
- {
- struct aa_task_cxt *cxt;
- struct cred *new = prepare_creds();
- if (!new)
- return -ENOMEM;
- cxt = cred_cxt(new);
- aa_get_profile(profile);
- aa_put_profile(cxt->onexec);
- cxt->onexec = profile;
- commit_creds(new);
- return 0;
- }
- int aa_set_current_hat(struct aa_profile *profile, u64 token)
- {
- struct aa_task_cxt *cxt;
- struct cred *new = prepare_creds();
- if (!new)
- return -ENOMEM;
- BUG_ON(!profile);
- cxt = cred_cxt(new);
- if (!cxt->previous) {
-
- cxt->previous = cxt->profile;
- cxt->token = token;
- } else if (cxt->token == token) {
- aa_put_profile(cxt->profile);
- } else {
-
- abort_creds(new);
- return -EACCES;
- }
- cxt->profile = aa_get_newest_profile(profile);
-
- aa_put_profile(cxt->onexec);
- cxt->onexec = NULL;
- commit_creds(new);
- return 0;
- }
- int aa_restore_previous_profile(u64 token)
- {
- struct aa_task_cxt *cxt;
- struct cred *new = prepare_creds();
- if (!new)
- return -ENOMEM;
- cxt = cred_cxt(new);
- if (cxt->token != token) {
- abort_creds(new);
- return -EACCES;
- }
-
- if (!cxt->previous) {
- abort_creds(new);
- return 0;
- }
- aa_put_profile(cxt->profile);
- cxt->profile = aa_get_newest_profile(cxt->previous);
- BUG_ON(!cxt->profile);
-
- aa_clear_task_cxt_trans(cxt);
- commit_creds(new);
- return 0;
- }
|