diff options
Diffstat (limited to 'security')
| -rw-r--r-- | security/yama/yama_lsm.c | 41 |
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 | */ | ||
| 299 | static 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 | |||
| 293 | static struct security_operations yama_ops = { | 333 | static 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 | }; |
