From: John Johansen <john.johansen@canonical.com>
To: Paul Moore <paul@paul-moore.com>,
Casey Schaufler <casey@schaufler-ca.com>
Cc: selinux@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-audit@redhat.com
Subject: Re: [RFC PATCH 4/4] apparmor: differentiate between subjective and objective task credentials
Date: Sun, 21 Feb 2021 04:57:26 -0800 [thread overview]
Message-ID: <28174118-93d2-e7a5-50fb-004185354625@canonical.com> (raw)
In-Reply-To: <161377736385.87807.7033400948278183233.stgit@sifl>
On 2/19/21 3:29 PM, Paul Moore wrote:
> With the split of the security_task_getsecid() into subjective and
> objective variants it's time to update AppArmor to ensure it is
> using the correct task creds.
>
> Signed-off-by: Paul Moore <paul@paul-moore.com>
This has a couple problems, that I will work on addressing
> ---
> security/apparmor/domain.c | 2 +-
> security/apparmor/include/cred.h | 19 ++++++++++++++++---
> security/apparmor/include/task.h | 3 ++-
> security/apparmor/lsm.c | 23 +++++++++++++++--------
> security/apparmor/task.c | 23 ++++++++++++++++++++---
> 5 files changed, 54 insertions(+), 16 deletions(-)
>
> diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
> index f919ebd042fd2..9ed00b8dcdf0c 100644
> --- a/security/apparmor/domain.c
> +++ b/security/apparmor/domain.c
> @@ -67,7 +67,7 @@ static int may_change_ptraced_domain(struct aa_label *to_label,
> tracer = ptrace_parent(current);
> if (tracer)
> /* released below */
> - tracerl = aa_get_task_label(tracer);
> + tracerl = aa_get_task_label_subj(tracer);
>
> /* not ptraced */
> if (!tracer || unconfined(tracerl))
> diff --git a/security/apparmor/include/cred.h b/security/apparmor/include/cred.h
> index 0b9ae4804ef73..43c21ef5568ab 100644
> --- a/security/apparmor/include/cred.h
> +++ b/security/apparmor/include/cred.h
> @@ -64,14 +64,27 @@ static inline struct aa_label *aa_get_newest_cred_label(const struct cred *cred)
> }
>
> /**
> - * __aa_task_raw_label - retrieve another task's label
> + * __aa_task_raw_label_subj - retrieve another task's subjective label
> * @task: task to query (NOT NULL)
> *
> - * Returns: @task's label without incrementing its ref count
> + * Returns: @task's subjective label without incrementing its ref count
> *
> * If @task != current needs to be called in RCU safe critical section
> */
> -static inline struct aa_label *__aa_task_raw_label(struct task_struct *task)
> +static inline struct aa_label *__aa_task_raw_label_subj(struct task_struct *task)
> +{
> + return aa_cred_raw_label(rcu_dereference(task->cred));
> +}
> +
> +/**
> + * __aa_task_raw_label_obj - retrieve another task's objective label
> + * @task: task to query (NOT NULL)
> + *
> + * Returns: @task's objective label without incrementing its ref count
> + *
> + * If @task != current needs to be called in RCU safe critical section
> + */
> +static inline struct aa_label *__aa_task_raw_label_obj(struct task_struct *task)
> {
> return aa_cred_raw_label(__task_cred(task));
> }
> diff --git a/security/apparmor/include/task.h b/security/apparmor/include/task.h
> index f13d12373b25e..27a2961558555 100644
> --- a/security/apparmor/include/task.h
> +++ b/security/apparmor/include/task.h
> @@ -33,7 +33,8 @@ int aa_replace_current_label(struct aa_label *label);
> int aa_set_current_onexec(struct aa_label *label, bool stack);
> int aa_set_current_hat(struct aa_label *label, u64 token);
> int aa_restore_previous_label(u64 cookie);
> -struct aa_label *aa_get_task_label(struct task_struct *task);
> +struct aa_label *aa_get_task_label_subj(struct task_struct *task);
> +struct aa_label *aa_get_task_label_obj(struct task_struct *task);
>
> /**
> * aa_free_task_ctx - free a task_ctx
> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
> index 15e37b9132679..38430851675b9 100644
> --- a/security/apparmor/lsm.c
> +++ b/security/apparmor/lsm.c
> @@ -119,7 +119,7 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
> int error;
>
> tracer = __begin_current_label_crit_section();
> - tracee = aa_get_task_label(child);
> + tracee = aa_get_task_label_obj(child);
> error = aa_may_ptrace(tracer, tracee,
> (mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
> : AA_PTRACE_TRACE);
> @@ -135,7 +135,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent)
> int error;
>
> tracee = __begin_current_label_crit_section();
> - tracer = aa_get_task_label(parent);
> + tracer = aa_get_task_label_subj(parent);
> error = aa_may_ptrace(tracer, tracee, AA_PTRACE_TRACE);
> aa_put_label(tracer);
> __end_current_label_crit_section(tracee);
> @@ -719,9 +719,16 @@ static void apparmor_bprm_committed_creds(struct linux_binprm *bprm)
> return;
> }
>
> -static void apparmor_task_getsecid(struct task_struct *p, u32 *secid)
> +static void apparmor_task_getsecid_subj(struct task_struct *p, u32 *secid)
> {
> - struct aa_label *label = aa_get_task_label(p);
> + struct aa_label *label = aa_get_task_label_subj(p);
> + *secid = label->secid;
> + aa_put_label(label);
> +}
> +
> +static void apparmor_task_getsecid_obj(struct task_struct *p, u32 *secid)
> +{
> + struct aa_label *label = aa_get_task_label_obj(p);
> *secid = label->secid;
> aa_put_label(label);
> }
> @@ -750,7 +757,7 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo
> * Dealing with USB IO specific behavior
> */
> cl = aa_get_newest_cred_label(cred);
> - tl = aa_get_task_label(target);
> + tl = aa_get_task_label_obj(target);
> error = aa_may_signal(cl, tl, sig);
> aa_put_label(cl);
> aa_put_label(tl);
> @@ -758,7 +765,7 @@ static int apparmor_task_kill(struct task_struct *target, struct kernel_siginfo
> }
>
> cl = __begin_current_label_crit_section();
> - tl = aa_get_task_label(target);
> + tl = aa_get_task_label_obj(target);
> error = aa_may_signal(cl, tl, sig);
> aa_put_label(tl);
> __end_current_label_crit_section(cl);
> @@ -1243,8 +1250,8 @@ static struct security_hook_list apparmor_hooks[] __lsm_ro_after_init = {
>
> LSM_HOOK_INIT(task_free, apparmor_task_free),
> LSM_HOOK_INIT(task_alloc, apparmor_task_alloc),
> - LSM_HOOK_INIT(task_getsecid_subj, apparmor_task_getsecid),
> - LSM_HOOK_INIT(task_getsecid_obj, apparmor_task_getsecid),
> + LSM_HOOK_INIT(task_getsecid_subj, apparmor_task_getsecid_subj),
> + LSM_HOOK_INIT(task_getsecid_obj, apparmor_task_getsecid_obj),
> LSM_HOOK_INIT(task_setrlimit, apparmor_task_setrlimit),
> LSM_HOOK_INIT(task_kill, apparmor_task_kill),
>
> diff --git a/security/apparmor/task.c b/security/apparmor/task.c
> index d17130ee6795d..c03c8e3928055 100644
> --- a/security/apparmor/task.c
> +++ b/security/apparmor/task.c
> @@ -16,17 +16,34 @@
> #include "include/task.h"
>
> /**
> - * aa_get_task_label - Get another task's label
> + * aa_get_task_label_subj - Get another task's subjective label
> * @task: task to query (NOT NULL)
> *
> * Returns: counted reference to @task's label
> */
> -struct aa_label *aa_get_task_label(struct task_struct *task)
> +struct aa_label *aa_get_task_label_subj(struct task_struct *task)
> {
> struct aa_label *p;
>
> rcu_read_lock();
> - p = aa_get_newest_label(__aa_task_raw_label(task));
> + p = aa_get_newest_label(__aa_task_raw_label_subj(task));
> + rcu_read_unlock();
> +
> + return p;
> +}
> +
> +/**
> + * aa_get_task_label_obj - Get another task's objective label
> + * @task: task to query (NOT NULL)
> + *
> + * Returns: counted reference to @task's label
> + */
> +struct aa_label *aa_get_task_label_obj(struct task_struct *task)
> +{
> + struct aa_label *p;
> +
> + rcu_read_lock();
> + p = aa_get_newest_label(__aa_task_raw_label_obj(task));
> rcu_read_unlock();
>
> return p;
>
--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit
next prev parent reply other threads:[~2021-02-22 15:53 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-19 23:28 [RFC PATCH 0/4] Split security_task_getsecid() into subj and obj variants Paul Moore
2021-02-19 23:29 ` [RFC PATCH 1/4] lsm: separate security_task_getsecid() into subjective and objective variants Paul Moore
2021-02-20 2:55 ` James Morris
2021-02-20 14:44 ` Paul Moore
2021-03-04 10:04 ` Jeffrey Vander Stoep
2021-03-04 23:43 ` Paul Moore
2021-03-10 8:21 ` Jeffrey Vander Stoep
2021-03-11 1:56 ` Paul Moore
2021-02-21 12:51 ` John Johansen
2021-02-21 22:09 ` Paul Moore
2021-03-04 0:44 ` Paul Moore
2021-03-10 0:28 ` Paul Moore
2021-03-10 3:09 ` John Johansen
2021-02-24 16:49 ` Mimi Zohar
2021-03-08 19:25 ` Richard Guy Briggs
2021-03-10 0:23 ` Paul Moore
2021-03-10 1:03 ` John Johansen
2021-03-11 1:55 ` Paul Moore
2021-02-19 23:29 ` [RFC PATCH 2/4] selinux: clarify task subjective and objective credentials Paul Moore
2021-02-21 12:55 ` John Johansen
2021-03-08 19:26 ` Richard Guy Briggs
2021-03-10 3:05 ` John Johansen
2021-03-11 4:32 ` Paul Moore
2021-03-17 22:56 ` Paul Moore
2021-02-19 23:29 ` [RFC PATCH 3/4] smack: differentiate between subjective and objective task credentials Paul Moore
2021-02-21 12:56 ` John Johansen
2021-03-08 19:26 ` Richard Guy Briggs
2021-03-10 1:04 ` John Johansen
2021-02-19 23:29 ` [RFC PATCH 4/4] apparmor: " Paul Moore
2021-02-21 12:57 ` John Johansen [this message]
2021-02-21 22:12 ` Paul Moore
2021-02-20 1:49 ` [RFC PATCH 0/4] Split security_task_getsecid() into subj and obj variants Casey Schaufler
2021-02-20 14:41 ` Paul Moore
2021-02-22 23:58 ` Casey Schaufler
2021-02-23 14:14 ` Mimi Zohar
2021-02-24 0:03 ` Paul Moore
2021-03-04 0:46 ` Paul Moore
2021-03-04 2:21 ` Casey Schaufler
2021-03-04 23:41 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28174118-93d2-e7a5-50fb-004185354625@canonical.com \
--to=john.johansen@canonical.com \
--cc=casey@schaufler-ca.com \
--cc=linux-audit@redhat.com \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).