aboutsummaryrefslogtreecommitdiffstats
path: root/security/yama/yama_lsm.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-08-12 14:36:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-08-12 14:36:13 -0400
commitc8dfbf48d3dd4e96044f2fa04fb5f58239e44c31 (patch)
tree822ae29c1572f7e95fd4726c3effd8389a79b336 /security/yama/yama_lsm.c
parente4e139bebd9cc2c867950ad8ea6814e542dbcc6f (diff)
parent9d8dad742ad1c74d7e7210ee05d0b44961d5ea16 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull a security subsystem fix from James Morris "This fixes an issue in the Yama LSM" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: Yama: higher restrictions should block PTRACE_TRACEME
Diffstat (limited to 'security/yama/yama_lsm.c')
-rw-r--r--security/yama/yama_lsm.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
index 83554ee8a587..d51b7c76c37d 100644
--- a/security/yama/yama_lsm.c
+++ b/security/yama/yama_lsm.c
@@ -290,10 +290,51 @@ static int yama_ptrace_access_check(struct task_struct *child,
290 return rc; 290 return rc;
291} 291}
292 292
293/**
294 * yama_ptrace_traceme - validate PTRACE_TRACEME calls
295 * @parent: task that will become the ptracer of the current task
296 *
297 * Returns 0 if following the ptrace is allowed, -ve on error.
298 */
299static int yama_ptrace_traceme(struct task_struct *parent)
300{
301 int rc;
302
303 /* If standard caps disallows it, so does Yama. We should
304 * only tighten restrictions further.
305 */
306 rc = cap_ptrace_traceme(parent);
307 if (rc)
308 return rc;
309
310 /* Only disallow PTRACE_TRACEME on more aggressive settings. */
311 switch (ptrace_scope) {
312 case YAMA_SCOPE_CAPABILITY:
313 if (!ns_capable(task_user_ns(parent), CAP_SYS_PTRACE))
314 rc = -EPERM;
315 break;
316 case YAMA_SCOPE_NO_ATTACH:
317 rc = -EPERM;
318 break;
319 }
320
321 if (rc) {
322 char name[sizeof(current->comm)];
323 printk_ratelimited(KERN_NOTICE
324 "ptraceme of pid %d was attempted by: %s (pid %d)\n",
325 current->pid,
326 get_task_comm(name, parent),
327 parent->pid);
328 }
329
330 return rc;
331}
332
293static struct security_operations yama_ops = { 333static struct security_operations yama_ops = {
294 .name = "yama", 334 .name = "yama",
295 335
296 .ptrace_access_check = yama_ptrace_access_check, 336 .ptrace_access_check = yama_ptrace_access_check,
337 .ptrace_traceme = yama_ptrace_traceme,
297 .task_prctl = yama_task_prctl, 338 .task_prctl = yama_task_prctl,
298 .task_free = yama_task_free, 339 .task_free = yama_task_free,
299}; 340};