summaryrefslogtreecommitdiff
path: root/security/yama/yama_lsm.c
diff options
context:
space:
mode:
authorJames Simmons <jsimmons@infradead.org>2012-11-14 18:15:32 +0000
committerJames Simmons <jsimmons@infradead.org>2012-11-14 18:15:32 +0000
commitb44959f2817032bc4668434bbe1cf9ab28b8cb21 (patch)
treede3bd861b36c836ac9b7b6e8dc179ca1985b6593 /security/yama/yama_lsm.c
parente22956a2faa9cf34cec4a471131d50c6be75b0c2 (diff)
parent2216c9e74fb3baac3cb73952158dbe38b703997e (diff)
Merge branch 'drm-core-next'HEADmaster
Conflicts: drivers/gpu/drm/tdfx/tdfx_drv.c
Diffstat (limited to 'security/yama/yama_lsm.c')
-rw-r--r--security/yama/yama_lsm.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
index 83554ee8a58..0cc99a3ea42 100644
--- a/security/yama/yama_lsm.c
+++ b/security/yama/yama_lsm.c
@@ -279,12 +279,46 @@ static int yama_ptrace_access_check(struct task_struct *child,
}
if (rc) {
- char name[sizeof(current->comm)];
printk_ratelimited(KERN_NOTICE
"ptrace of pid %d was attempted by: %s (pid %d)\n",
- child->pid,
- get_task_comm(name, current),
- current->pid);
+ child->pid, current->comm, current->pid);
+ }
+
+ return rc;
+}
+
+/**
+ * yama_ptrace_traceme - validate PTRACE_TRACEME calls
+ * @parent: task that will become the ptracer of the current task
+ *
+ * Returns 0 if following the ptrace is allowed, -ve on error.
+ */
+static int yama_ptrace_traceme(struct task_struct *parent)
+{
+ int rc;
+
+ /* If standard caps disallows it, so does Yama. We should
+ * only tighten restrictions further.
+ */
+ rc = cap_ptrace_traceme(parent);
+ if (rc)
+ return rc;
+
+ /* Only disallow PTRACE_TRACEME on more aggressive settings. */
+ switch (ptrace_scope) {
+ case YAMA_SCOPE_CAPABILITY:
+ if (!ns_capable(task_user_ns(parent), CAP_SYS_PTRACE))
+ rc = -EPERM;
+ break;
+ case YAMA_SCOPE_NO_ATTACH:
+ rc = -EPERM;
+ break;
+ }
+
+ if (rc) {
+ printk_ratelimited(KERN_NOTICE
+ "ptraceme of pid %d was attempted by: %s (pid %d)\n",
+ current->pid, parent->comm, parent->pid);
}
return rc;
@@ -294,6 +328,7 @@ static struct security_operations yama_ops = {
.name = "yama",
.ptrace_access_check = yama_ptrace_access_check,
+ .ptrace_traceme = yama_ptrace_traceme,
.task_prctl = yama_task_prctl,
.task_free = yama_task_free,
};