16 #include <linux/sysctl.h>
17 #include <linux/ptrace.h>
21 #define YAMA_SCOPE_DISABLED 0
22 #define YAMA_SCOPE_RELATIONAL 1
23 #define YAMA_SCOPE_CAPABILITY 2
24 #define YAMA_SCOPE_NO_ATTACH 3
59 spin_lock_bh(&ptracer_relations_lock);
61 if (entry->tracee == tracee) {
68 list_add(&relation->
node, &ptracer_relations);
72 spin_unlock_bh(&ptracer_relations_lock);
73 if (added != relation)
84 static void yama_ptracer_del(
struct task_struct *tracer,
89 spin_lock_bh(&ptracer_relations_lock);
91 if (relation->tracee == tracee ||
92 (tracer && relation->tracer == tracer)) {
96 spin_unlock_bh(&ptracer_relations_lock);
105 yama_ptracer_del(task, task);
120 unsigned long arg4,
unsigned long arg5)
138 if (!thread_group_leader(myself))
144 yama_ptracer_del(
NULL, myself);
147 rc = yama_ptracer_add(
NULL, myself);
160 rc = yama_ptracer_add(tracer, myself);
161 put_task_struct(tracer);
165 put_task_struct(myself);
185 if (!parent || !child)
189 if (!thread_group_leader(parent))
191 while (walker->
pid > 0) {
192 if (!thread_group_leader(walker))
194 if (walker == parent) {
212 static int ptracer_exception_found(
struct task_struct *tracer,
220 spin_lock_bh(&ptracer_relations_lock);
222 if (!thread_group_leader(tracee))
225 if (relation->tracee == tracee) {
226 parent = relation->
tracer;
231 if (found && (parent ==
NULL || task_is_descendant(parent, tracer)))
234 spin_unlock_bh(&ptracer_relations_lock);
260 switch (ptrace_scope) {
265 if (!task_is_descendant(
current, child) &&
266 !ptracer_exception_found(
current, child) &&
283 "ptrace of pid %d was attempted by: %s (pid %d)\n",
308 switch (ptrace_scope) {
320 "ptraceme of pid %d was attempted by: %s (pid %d)\n",
327 #ifndef CONFIG_SECURITY_YAMA_STACKED
328 static struct security_operations yama_ops = {
340 void __user *
buffer,
size_t *lenp, loff_t *ppos)
352 if (write && *(
int *)table->
data == *(
int *)table->
extra2)
361 struct ctl_path yama_sysctl_path[] = {
363 { .procname =
"yama", },
367 static struct ctl_table yama_sysctl_table[] = {
370 .data = &ptrace_scope,
371 .maxlen =
sizeof(
int),
381 static __init int yama_init(
void)
383 #ifndef CONFIG_SECURITY_YAMA_STACKED
390 #ifndef CONFIG_SECURITY_YAMA_STACKED
392 panic(
"Yama: kernel registration failed.\n");
397 panic(
"Yama: sysctl registration failed.\n");