diff options
Diffstat (limited to 'security/apparmor')
-rw-r--r-- | security/apparmor/audit.c | 14 | ||||
-rw-r--r-- | security/apparmor/capability.c | 15 | ||||
-rw-r--r-- | security/apparmor/domain.c | 16 | ||||
-rw-r--r-- | security/apparmor/include/audit.h | 1 | ||||
-rw-r--r-- | security/apparmor/include/capability.h | 5 | ||||
-rw-r--r-- | security/apparmor/include/ipc.h | 4 | ||||
-rw-r--r-- | security/apparmor/ipc.c | 9 | ||||
-rw-r--r-- | security/apparmor/lsm.c | 2 |
8 files changed, 44 insertions, 22 deletions
diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c index 89c7865..031d2d9 100644 --- a/security/apparmor/audit.c +++ b/security/apparmor/audit.c @@ -111,6 +111,7 @@ static const char *const aa_audit_type[] = { static void audit_pre(struct audit_buffer *ab, void *ca) { struct common_audit_data *sa = ca; + struct task_struct *tsk = sa->aad->tsk ? sa->aad->tsk : current; if (aa_g_audit_header) { audit_log_format(ab, "apparmor="); @@ -131,6 +132,11 @@ static void audit_pre(struct audit_buffer *ab, void *ca) if (sa->aad->profile) { struct aa_profile *profile = sa->aad->profile; + pid_t pid; + rcu_read_lock(); + pid = rcu_dereference(tsk->real_parent)->pid; + rcu_read_unlock(); + audit_log_format(ab, " parent=%d", pid); if (profile->ns != root_ns) { audit_log_format(ab, " namespace="); audit_log_untrustedstring(ab, profile->ns->base.hname); @@ -143,6 +149,12 @@ static void audit_pre(struct audit_buffer *ab, void *ca) audit_log_format(ab, " name="); audit_log_untrustedstring(ab, sa->aad->name); } + + if (sa->aad->tsk) { + audit_log_format(ab, " pid=%d comm=", tsk->pid); + audit_log_untrustedstring(ab, tsk->comm); + } + } /** @@ -200,7 +212,7 @@ int aa_audit(int type, struct aa_profile *profile, gfp_t gfp, if (sa->aad->type == AUDIT_APPARMOR_KILL) (void)send_sig_info(SIGKILL, NULL, - sa->u.tsk ? sa->u.tsk : current); + sa->aad->tsk ? sa->aad->tsk : current); if (sa->aad->type == AUDIT_APPARMOR_ALLOWED) return complain_error(sa->aad->error); diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c index 1101c6f..84d1f5f 100644 --- a/security/apparmor/capability.c +++ b/security/apparmor/capability.c @@ -53,7 +53,8 @@ static void audit_cb(struct audit_buffer *ab, void *va) /** * audit_caps - audit a capability - * @profile: profile being tested for confinement (NOT NULL) + * @profile: profile confining task (NOT NULL) + * @task: task capability test was performed against (NOT NULL) * @cap: capability tested * @error: error code returned by test * @@ -62,7 +63,8 @@ static void audit_cb(struct audit_buffer *ab, void *va) * * Returns: 0 or sa->error on success, error code on failure */ -static int audit_caps(struct aa_profile *profile, int cap, int error) +static int audit_caps(struct aa_profile *profile, struct task_struct *task, + int cap, int error) { struct audit_cache *ent; int type = AUDIT_APPARMOR_AUTO; @@ -71,6 +73,7 @@ static int audit_caps(struct aa_profile *profile, int cap, int error) sa.type = LSM_AUDIT_DATA_CAP; sa.aad = &aad; sa.u.cap = cap; + sa.aad->tsk = task; sa.aad->op = OP_CAPABLE; sa.aad->error = error; @@ -121,7 +124,8 @@ static int profile_capable(struct aa_profile *profile, int cap) /** * aa_capable - test permission to use capability - * @profile: profile being tested against (NOT NULL) + * @task: task doing capability test against (NOT NULL) + * @profile: profile confining @task (NOT NULL) * @cap: capability to be tested * @audit: whether an audit record should be generated * @@ -129,7 +133,8 @@ static int profile_capable(struct aa_profile *profile, int cap) * * Returns: 0 on success, or else an error code. */ -int aa_capable(struct aa_profile *profile, int cap, int audit) +int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap, + int audit) { int error = profile_capable(profile, cap); @@ -139,5 +144,5 @@ int aa_capable(struct aa_profile *profile, int cap, int audit) return error; } - return audit_caps(profile, cap, error); + return audit_caps(profile, task, cap, error); } diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c index 452567d..26c607c 100644 --- a/security/apparmor/domain.c +++ b/security/apparmor/domain.c @@ -50,21 +50,23 @@ void aa_free_domain_entries(struct aa_domain *domain) /** * may_change_ptraced_domain - check if can change profile on ptraced task + * @task: task we want to change profile of (NOT NULL) * @to_profile: profile to change to (NOT NULL) * - * Check if current is ptraced and if so if the tracing task is allowed + * Check if the task is ptraced and if so if the tracing task is allowed * to trace the new domain * * Returns: %0 or error if change not allowed */ -static int may_change_ptraced_domain(struct aa_profile *to_profile) +static int may_change_ptraced_domain(struct task_struct *task, + struct aa_profile *to_profile) { struct task_struct *tracer; struct aa_profile *tracerp = NULL; int error = 0; rcu_read_lock(); - tracer = ptrace_parent(current); + tracer = ptrace_parent(task); if (tracer) /* released below */ tracerp = aa_get_task_profile(tracer); @@ -73,7 +75,7 @@ static int may_change_ptraced_domain(struct aa_profile *to_profile) if (!tracer || unconfined(tracerp)) goto out; - error = aa_may_ptrace(tracerp, to_profile, PTRACE_MODE_ATTACH); + error = aa_may_ptrace(tracer, tracerp, to_profile, PTRACE_MODE_ATTACH); out: rcu_read_unlock(); @@ -475,7 +477,7 @@ int apparmor_bprm_set_creds(struct linux_binprm *bprm) } if (bprm->unsafe & (LSM_UNSAFE_PTRACE | LSM_UNSAFE_PTRACE_CAP)) { - error = may_change_ptraced_domain(new_profile); + error = may_change_ptraced_domain(current, new_profile); if (error) { aa_put_profile(new_profile); goto audit; @@ -688,7 +690,7 @@ int aa_change_hat(const char *hats[], int count, u64 token, bool permtest) } } - error = may_change_ptraced_domain(hat); + error = may_change_ptraced_domain(current, hat); if (error) { info = "ptraced"; error = -EPERM; @@ -827,7 +829,7 @@ int aa_change_profile(const char *ns_name, const char *hname, bool onexec, } /* check if tracing task is allowed to trace target domain */ - error = may_change_ptraced_domain(target); + error = may_change_ptraced_domain(current, target); if (error) { info = "ptrace prevents transition"; goto audit; diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h index ba3dfd1..30e8d76 100644 --- a/security/apparmor/include/audit.h +++ b/security/apparmor/include/audit.h @@ -109,6 +109,7 @@ struct apparmor_audit_data { void *profile; const char *name; const char *info; + struct task_struct *tsk; union { void *target; struct { diff --git a/security/apparmor/include/capability.h b/security/apparmor/include/capability.h index fc3fa38..2e7c9d6 100644 --- a/security/apparmor/include/capability.h +++ b/security/apparmor/include/capability.h @@ -4,7 +4,7 @@ * This file contains AppArmor capability mediation definitions. * * Copyright (C) 1998-2008 Novell/SUSE - * Copyright 2009-2013 Canonical Ltd. + * Copyright 2009-2010 Canonical Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -38,7 +38,8 @@ struct aa_caps { extern struct aa_fs_entry aa_fs_entry_caps[]; -int aa_capable(struct aa_profile *profile, int cap, int audit); +int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap, + int audit); static inline void aa_free_cap_rules(struct aa_caps *caps) { diff --git a/security/apparmor/include/ipc.h b/security/apparmor/include/ipc.h index 288ca76..aeda0fb 100644 --- a/security/apparmor/include/ipc.h +++ b/security/apparmor/include/ipc.h @@ -19,8 +19,8 @@ struct aa_profile; -int aa_may_ptrace(struct aa_profile *tracer, struct aa_profile *tracee, - unsigned int mode); +int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer, + struct aa_profile *tracee, unsigned int mode); int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee, unsigned int mode); diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c index 777ac1c..c51d226 100644 --- a/security/apparmor/ipc.c +++ b/security/apparmor/ipc.c @@ -54,14 +54,15 @@ static int aa_audit_ptrace(struct aa_profile *profile, /** * aa_may_ptrace - test if tracer task can trace the tracee + * @tracer_task: task who will do the tracing (NOT NULL) * @tracer: profile of the task doing the tracing (NOT NULL) * @tracee: task to be traced * @mode: whether PTRACE_MODE_READ || PTRACE_MODE_ATTACH * * Returns: %0 else error code if permission denied or error */ -int aa_may_ptrace(struct aa_profile *tracer, struct aa_profile *tracee, - unsigned int mode) +int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer, + struct aa_profile *tracee, unsigned int mode) { /* TODO: currently only based on capability, not extended ptrace * rules, @@ -71,7 +72,7 @@ int aa_may_ptrace(struct aa_profile *tracer, struct aa_profile *tracee, if (unconfined(tracer) || tracer == tracee) return 0; /* log this capability request */ - return aa_capable(tracer, CAP_SYS_PTRACE, 1); + return aa_capable(tracer_task, tracer, CAP_SYS_PTRACE, 1); } /** @@ -100,7 +101,7 @@ int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee, if (!unconfined(tracer_p)) { struct aa_profile *tracee_p = aa_get_task_profile(tracee); - error = aa_may_ptrace(tracer_p, tracee_p, mode); + error = aa_may_ptrace(tracer, tracer_p, tracee_p, mode); error = aa_audit_ptrace(tracer_p, tracee_p, error); aa_put_profile(tracee_p); diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 4257b7e..fb99e18 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -145,7 +145,7 @@ static int apparmor_capable(const struct cred *cred, struct user_namespace *ns, if (!error) { profile = aa_cred_profile(cred); if (!unconfined(profile)) - error = aa_capable(profile, cap, audit); + error = aa_capable(current, profile, cap, audit); } return error; } |