12d514487SKees Cook /* 22d514487SKees Cook * Yama Linux Security Module 32d514487SKees Cook * 42d514487SKees Cook * Author: Kees Cook <keescook@chromium.org> 52d514487SKees Cook * 62d514487SKees Cook * Copyright (C) 2010 Canonical, Ltd. 72d514487SKees Cook * Copyright (C) 2011 The Chromium OS Authors. 82d514487SKees Cook * 92d514487SKees Cook * This program is free software; you can redistribute it and/or modify 102d514487SKees Cook * it under the terms of the GNU General Public License version 2, as 112d514487SKees Cook * published by the Free Software Foundation. 122d514487SKees Cook * 132d514487SKees Cook */ 142d514487SKees Cook 153c4ed7bdSCasey Schaufler #include <linux/lsm_hooks.h> 162d514487SKees Cook #include <linux/sysctl.h> 172d514487SKees Cook #include <linux/ptrace.h> 182d514487SKees Cook #include <linux/prctl.h> 192d514487SKees Cook #include <linux/ratelimit.h> 20235e7527SKees Cook #include <linux/workqueue.h> 218a56038cSKees Cook #include <linux/string_helpers.h> 22*dca6b414SJann Horn #include <linux/task_work.h> 23*dca6b414SJann Horn #include <linux/sched.h> 24*dca6b414SJann Horn #include <linux/spinlock.h> 252d514487SKees Cook 26389da25fSKees Cook #define YAMA_SCOPE_DISABLED 0 27389da25fSKees Cook #define YAMA_SCOPE_RELATIONAL 1 28389da25fSKees Cook #define YAMA_SCOPE_CAPABILITY 2 29389da25fSKees Cook #define YAMA_SCOPE_NO_ATTACH 3 30389da25fSKees Cook 31389da25fSKees Cook static int ptrace_scope = YAMA_SCOPE_RELATIONAL; 322d514487SKees Cook 332d514487SKees Cook /* describe a ptrace relationship for potential exception */ 342d514487SKees Cook struct ptrace_relation { 352d514487SKees Cook struct task_struct *tracer; 362d514487SKees Cook struct task_struct *tracee; 37235e7527SKees Cook bool invalid; 382d514487SKees Cook struct list_head node; 3993b69d43SKees Cook struct rcu_head rcu; 402d514487SKees Cook }; 412d514487SKees Cook 422d514487SKees Cook static LIST_HEAD(ptracer_relations); 432d514487SKees Cook static DEFINE_SPINLOCK(ptracer_relations_lock); 442d514487SKees Cook 45235e7527SKees Cook static void yama_relation_cleanup(struct work_struct *work); 46235e7527SKees Cook static DECLARE_WORK(yama_relation_work, yama_relation_cleanup); 47235e7527SKees Cook 48*dca6b414SJann Horn struct access_report_info { 49*dca6b414SJann Horn struct callback_head work; 50*dca6b414SJann Horn const char *access; 51*dca6b414SJann Horn struct task_struct *target; 52*dca6b414SJann Horn struct task_struct *agent; 53*dca6b414SJann Horn }; 54*dca6b414SJann Horn 55*dca6b414SJann Horn static void __report_access(struct callback_head *work) 568a56038cSKees Cook { 57*dca6b414SJann Horn struct access_report_info *info = 58*dca6b414SJann Horn container_of(work, struct access_report_info, work); 598a56038cSKees Cook char *target_cmd, *agent_cmd; 608a56038cSKees Cook 61*dca6b414SJann Horn target_cmd = kstrdup_quotable_cmdline(info->target, GFP_KERNEL); 62*dca6b414SJann Horn agent_cmd = kstrdup_quotable_cmdline(info->agent, GFP_KERNEL); 638a56038cSKees Cook 648a56038cSKees Cook pr_notice_ratelimited( 658a56038cSKees Cook "ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n", 66*dca6b414SJann Horn info->access, target_cmd, info->target->pid, agent_cmd, 67*dca6b414SJann Horn info->agent->pid); 688a56038cSKees Cook 698a56038cSKees Cook kfree(agent_cmd); 708a56038cSKees Cook kfree(target_cmd); 71*dca6b414SJann Horn 72*dca6b414SJann Horn put_task_struct(info->agent); 73*dca6b414SJann Horn put_task_struct(info->target); 74*dca6b414SJann Horn kfree(info); 75*dca6b414SJann Horn } 76*dca6b414SJann Horn 77*dca6b414SJann Horn /* defers execution because cmdline access can sleep */ 78*dca6b414SJann Horn static void report_access(const char *access, struct task_struct *target, 79*dca6b414SJann Horn struct task_struct *agent) 80*dca6b414SJann Horn { 81*dca6b414SJann Horn struct access_report_info *info; 82*dca6b414SJann Horn char agent_comm[sizeof(agent->comm)]; 83*dca6b414SJann Horn 84*dca6b414SJann Horn assert_spin_locked(&target->alloc_lock); /* for target->comm */ 85*dca6b414SJann Horn 86*dca6b414SJann Horn if (current->flags & PF_KTHREAD) { 87*dca6b414SJann Horn /* I don't think kthreads call task_work_run() before exiting. 88*dca6b414SJann Horn * Imagine angry ranting about procfs here. 89*dca6b414SJann Horn */ 90*dca6b414SJann Horn pr_notice_ratelimited( 91*dca6b414SJann Horn "ptrace %s of \"%s\"[%d] was attempted by \"%s\"[%d]\n", 92*dca6b414SJann Horn access, target->comm, target->pid, 93*dca6b414SJann Horn get_task_comm(agent_comm, agent), agent->pid); 94*dca6b414SJann Horn return; 95*dca6b414SJann Horn } 96*dca6b414SJann Horn 97*dca6b414SJann Horn info = kmalloc(sizeof(*info), GFP_ATOMIC); 98*dca6b414SJann Horn if (!info) 99*dca6b414SJann Horn return; 100*dca6b414SJann Horn init_task_work(&info->work, __report_access); 101*dca6b414SJann Horn get_task_struct(target); 102*dca6b414SJann Horn get_task_struct(agent); 103*dca6b414SJann Horn info->access = access; 104*dca6b414SJann Horn info->target = target; 105*dca6b414SJann Horn info->agent = agent; 106*dca6b414SJann Horn if (task_work_add(current, &info->work, true) == 0) 107*dca6b414SJann Horn return; /* success */ 108*dca6b414SJann Horn 109*dca6b414SJann Horn WARN(1, "report_access called from exiting task"); 110*dca6b414SJann Horn put_task_struct(target); 111*dca6b414SJann Horn put_task_struct(agent); 112*dca6b414SJann Horn kfree(info); 1138a56038cSKees Cook } 1148a56038cSKees Cook 115235e7527SKees Cook /** 116235e7527SKees Cook * yama_relation_cleanup - remove invalid entries from the relation list 117235e7527SKees Cook * 118235e7527SKees Cook */ 119235e7527SKees Cook static void yama_relation_cleanup(struct work_struct *work) 120235e7527SKees Cook { 121235e7527SKees Cook struct ptrace_relation *relation; 122235e7527SKees Cook 123235e7527SKees Cook spin_lock(&ptracer_relations_lock); 124235e7527SKees Cook rcu_read_lock(); 125235e7527SKees Cook list_for_each_entry_rcu(relation, &ptracer_relations, node) { 126235e7527SKees Cook if (relation->invalid) { 127235e7527SKees Cook list_del_rcu(&relation->node); 128235e7527SKees Cook kfree_rcu(relation, rcu); 129235e7527SKees Cook } 130235e7527SKees Cook } 131235e7527SKees Cook rcu_read_unlock(); 132235e7527SKees Cook spin_unlock(&ptracer_relations_lock); 133235e7527SKees Cook } 134235e7527SKees Cook 1352d514487SKees Cook /** 1362d514487SKees Cook * yama_ptracer_add - add/replace an exception for this tracer/tracee pair 1372d514487SKees Cook * @tracer: the task_struct of the process doing the ptrace 1382d514487SKees Cook * @tracee: the task_struct of the process to be ptraced 1392d514487SKees Cook * 1402d514487SKees Cook * Each tracee can have, at most, one tracer registered. Each time this 1412d514487SKees Cook * is called, the prior registered tracer will be replaced for the tracee. 1422d514487SKees Cook * 1432d514487SKees Cook * Returns 0 if relationship was added, -ve on error. 1442d514487SKees Cook */ 1452d514487SKees Cook static int yama_ptracer_add(struct task_struct *tracer, 1462d514487SKees Cook struct task_struct *tracee) 1472d514487SKees Cook { 14893b69d43SKees Cook struct ptrace_relation *relation, *added; 1492d514487SKees Cook 1502d514487SKees Cook added = kmalloc(sizeof(*added), GFP_KERNEL); 1512d514487SKees Cook if (!added) 1522d514487SKees Cook return -ENOMEM; 1532d514487SKees Cook 15493b69d43SKees Cook added->tracee = tracee; 15593b69d43SKees Cook added->tracer = tracer; 156235e7527SKees Cook added->invalid = false; 15793b69d43SKees Cook 158235e7527SKees Cook spin_lock(&ptracer_relations_lock); 15993b69d43SKees Cook rcu_read_lock(); 16093b69d43SKees Cook list_for_each_entry_rcu(relation, &ptracer_relations, node) { 161235e7527SKees Cook if (relation->invalid) 162235e7527SKees Cook continue; 16393b69d43SKees Cook if (relation->tracee == tracee) { 16493b69d43SKees Cook list_replace_rcu(&relation->node, &added->node); 16593b69d43SKees Cook kfree_rcu(relation, rcu); 16693b69d43SKees Cook goto out; 1672d514487SKees Cook } 1682d514487SKees Cook } 1692d514487SKees Cook 17093b69d43SKees Cook list_add_rcu(&added->node, &ptracer_relations); 17193b69d43SKees Cook 17293b69d43SKees Cook out: 17393b69d43SKees Cook rcu_read_unlock(); 174235e7527SKees Cook spin_unlock(&ptracer_relations_lock); 17593b69d43SKees Cook return 0; 1762d514487SKees Cook } 1772d514487SKees Cook 1782d514487SKees Cook /** 1792d514487SKees Cook * yama_ptracer_del - remove exceptions related to the given tasks 1802d514487SKees Cook * @tracer: remove any relation where tracer task matches 1812d514487SKees Cook * @tracee: remove any relation where tracee task matches 1822d514487SKees Cook */ 1832d514487SKees Cook static void yama_ptracer_del(struct task_struct *tracer, 1842d514487SKees Cook struct task_struct *tracee) 1852d514487SKees Cook { 18693b69d43SKees Cook struct ptrace_relation *relation; 187235e7527SKees Cook bool marked = false; 1882d514487SKees Cook 18993b69d43SKees Cook rcu_read_lock(); 19093b69d43SKees Cook list_for_each_entry_rcu(relation, &ptracer_relations, node) { 191235e7527SKees Cook if (relation->invalid) 192235e7527SKees Cook continue; 1932d514487SKees Cook if (relation->tracee == tracee || 194bf06189eSKees Cook (tracer && relation->tracer == tracer)) { 195235e7527SKees Cook relation->invalid = true; 196235e7527SKees Cook marked = true; 1972d514487SKees Cook } 19893b69d43SKees Cook } 19993b69d43SKees Cook rcu_read_unlock(); 200235e7527SKees Cook 201235e7527SKees Cook if (marked) 202235e7527SKees Cook schedule_work(&yama_relation_work); 2032d514487SKees Cook } 2042d514487SKees Cook 2052d514487SKees Cook /** 2062d514487SKees Cook * yama_task_free - check for task_pid to remove from exception list 2072d514487SKees Cook * @task: task being removed 2082d514487SKees Cook */ 209c6993e4aSKees Cook void yama_task_free(struct task_struct *task) 2102d514487SKees Cook { 2112d514487SKees Cook yama_ptracer_del(task, task); 2122d514487SKees Cook } 2132d514487SKees Cook 2142d514487SKees Cook /** 2152d514487SKees Cook * yama_task_prctl - check for Yama-specific prctl operations 2162d514487SKees Cook * @option: operation 2172d514487SKees Cook * @arg2: argument 2182d514487SKees Cook * @arg3: argument 2192d514487SKees Cook * @arg4: argument 2202d514487SKees Cook * @arg5: argument 2212d514487SKees Cook * 2222d514487SKees Cook * Return 0 on success, -ve on error. -ENOSYS is returned when Yama 2232d514487SKees Cook * does not handle the given option. 2242d514487SKees Cook */ 225c6993e4aSKees Cook int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3, 2262d514487SKees Cook unsigned long arg4, unsigned long arg5) 2272d514487SKees Cook { 228b1d9e6b0SCasey Schaufler int rc = -ENOSYS; 2292d514487SKees Cook struct task_struct *myself = current; 2302d514487SKees Cook 2312d514487SKees Cook switch (option) { 2322d514487SKees Cook case PR_SET_PTRACER: 2332d514487SKees Cook /* Since a thread can call prctl(), find the group leader 2342d514487SKees Cook * before calling _add() or _del() on it, since we want 2352d514487SKees Cook * process-level granularity of control. The tracer group 2362d514487SKees Cook * leader checking is handled later when walking the ancestry 2372d514487SKees Cook * at the time of PTRACE_ATTACH check. 2382d514487SKees Cook */ 2392d514487SKees Cook rcu_read_lock(); 2402d514487SKees Cook if (!thread_group_leader(myself)) 2412d514487SKees Cook myself = rcu_dereference(myself->group_leader); 2422d514487SKees Cook get_task_struct(myself); 2432d514487SKees Cook rcu_read_unlock(); 2442d514487SKees Cook 2452d514487SKees Cook if (arg2 == 0) { 2462d514487SKees Cook yama_ptracer_del(NULL, myself); 2472d514487SKees Cook rc = 0; 2482e4930ebSKees Cook } else if (arg2 == PR_SET_PTRACER_ANY || (int)arg2 == -1) { 249bf06189eSKees Cook rc = yama_ptracer_add(NULL, myself); 2502d514487SKees Cook } else { 2512d514487SKees Cook struct task_struct *tracer; 2522d514487SKees Cook 2532d514487SKees Cook rcu_read_lock(); 2542d514487SKees Cook tracer = find_task_by_vpid(arg2); 2552d514487SKees Cook if (tracer) 2562d514487SKees Cook get_task_struct(tracer); 2572d514487SKees Cook else 2582d514487SKees Cook rc = -EINVAL; 2592d514487SKees Cook rcu_read_unlock(); 2602d514487SKees Cook 2612d514487SKees Cook if (tracer) { 2622d514487SKees Cook rc = yama_ptracer_add(tracer, myself); 2632d514487SKees Cook put_task_struct(tracer); 2642d514487SKees Cook } 2652d514487SKees Cook } 2662d514487SKees Cook 2672d514487SKees Cook put_task_struct(myself); 2682d514487SKees Cook break; 2692d514487SKees Cook } 2702d514487SKees Cook 2712d514487SKees Cook return rc; 2722d514487SKees Cook } 2732d514487SKees Cook 2742d514487SKees Cook /** 2752d514487SKees Cook * task_is_descendant - walk up a process family tree looking for a match 2762d514487SKees Cook * @parent: the process to compare against while walking up from child 2772d514487SKees Cook * @child: the process to start from while looking upwards for parent 2782d514487SKees Cook * 2792d514487SKees Cook * Returns 1 if child is a descendant of parent, 0 if not. 2802d514487SKees Cook */ 2812d514487SKees Cook static int task_is_descendant(struct task_struct *parent, 2822d514487SKees Cook struct task_struct *child) 2832d514487SKees Cook { 2842d514487SKees Cook int rc = 0; 2852d514487SKees Cook struct task_struct *walker = child; 2862d514487SKees Cook 2872d514487SKees Cook if (!parent || !child) 2882d514487SKees Cook return 0; 2892d514487SKees Cook 2902d514487SKees Cook rcu_read_lock(); 2912d514487SKees Cook if (!thread_group_leader(parent)) 2922d514487SKees Cook parent = rcu_dereference(parent->group_leader); 2932d514487SKees Cook while (walker->pid > 0) { 2942d514487SKees Cook if (!thread_group_leader(walker)) 2952d514487SKees Cook walker = rcu_dereference(walker->group_leader); 2962d514487SKees Cook if (walker == parent) { 2972d514487SKees Cook rc = 1; 2982d514487SKees Cook break; 2992d514487SKees Cook } 3002d514487SKees Cook walker = rcu_dereference(walker->real_parent); 3012d514487SKees Cook } 3022d514487SKees Cook rcu_read_unlock(); 3032d514487SKees Cook 3042d514487SKees Cook return rc; 3052d514487SKees Cook } 3062d514487SKees Cook 3072d514487SKees Cook /** 3082d514487SKees Cook * ptracer_exception_found - tracer registered as exception for this tracee 3092d514487SKees Cook * @tracer: the task_struct of the process attempting ptrace 3102d514487SKees Cook * @tracee: the task_struct of the process to be ptraced 3112d514487SKees Cook * 3122d514487SKees Cook * Returns 1 if tracer has is ptracer exception ancestor for tracee. 3132d514487SKees Cook */ 3142d514487SKees Cook static int ptracer_exception_found(struct task_struct *tracer, 3152d514487SKees Cook struct task_struct *tracee) 3162d514487SKees Cook { 3172d514487SKees Cook int rc = 0; 3182d514487SKees Cook struct ptrace_relation *relation; 3192d514487SKees Cook struct task_struct *parent = NULL; 320bf06189eSKees Cook bool found = false; 3212d514487SKees Cook 3222d514487SKees Cook rcu_read_lock(); 3232d514487SKees Cook if (!thread_group_leader(tracee)) 3242d514487SKees Cook tracee = rcu_dereference(tracee->group_leader); 325235e7527SKees Cook list_for_each_entry_rcu(relation, &ptracer_relations, node) { 326235e7527SKees Cook if (relation->invalid) 327235e7527SKees Cook continue; 3282d514487SKees Cook if (relation->tracee == tracee) { 3292d514487SKees Cook parent = relation->tracer; 330bf06189eSKees Cook found = true; 3312d514487SKees Cook break; 3322d514487SKees Cook } 333235e7527SKees Cook } 3342d514487SKees Cook 335bf06189eSKees Cook if (found && (parent == NULL || task_is_descendant(parent, tracer))) 3362d514487SKees Cook rc = 1; 3372d514487SKees Cook rcu_read_unlock(); 3382d514487SKees Cook 3392d514487SKees Cook return rc; 3402d514487SKees Cook } 3412d514487SKees Cook 3422d514487SKees Cook /** 3432d514487SKees Cook * yama_ptrace_access_check - validate PTRACE_ATTACH calls 3442d514487SKees Cook * @child: task that current task is attempting to ptrace 3452d514487SKees Cook * @mode: ptrace attach mode 3462d514487SKees Cook * 3472d514487SKees Cook * Returns 0 if following the ptrace is allowed, -ve on error. 3482d514487SKees Cook */ 349b1d9e6b0SCasey Schaufler static int yama_ptrace_access_check(struct task_struct *child, 3502d514487SKees Cook unsigned int mode) 3512d514487SKees Cook { 352b1d9e6b0SCasey Schaufler int rc = 0; 3532d514487SKees Cook 3542d514487SKees Cook /* require ptrace target be a child of ptracer on attach */ 3553dfb7d8cSJann Horn if (mode & PTRACE_MODE_ATTACH) { 356389da25fSKees Cook switch (ptrace_scope) { 357389da25fSKees Cook case YAMA_SCOPE_DISABLED: 358389da25fSKees Cook /* No additional restrictions. */ 359389da25fSKees Cook break; 360389da25fSKees Cook case YAMA_SCOPE_RELATIONAL: 3614c44aaafSEric W. Biederman rcu_read_lock(); 362389da25fSKees Cook if (!task_is_descendant(current, child) && 3632d514487SKees Cook !ptracer_exception_found(current, child) && 3644c44aaafSEric W. Biederman !ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE)) 3652d514487SKees Cook rc = -EPERM; 3664c44aaafSEric W. Biederman rcu_read_unlock(); 367389da25fSKees Cook break; 368389da25fSKees Cook case YAMA_SCOPE_CAPABILITY: 3694c44aaafSEric W. Biederman rcu_read_lock(); 3704c44aaafSEric W. Biederman if (!ns_capable(__task_cred(child)->user_ns, CAP_SYS_PTRACE)) 371389da25fSKees Cook rc = -EPERM; 3724c44aaafSEric W. Biederman rcu_read_unlock(); 373389da25fSKees Cook break; 374389da25fSKees Cook case YAMA_SCOPE_NO_ATTACH: 375389da25fSKees Cook default: 376389da25fSKees Cook rc = -EPERM; 377389da25fSKees Cook break; 378389da25fSKees Cook } 379389da25fSKees Cook } 3802d514487SKees Cook 3818a56038cSKees Cook if (rc && (mode & PTRACE_MODE_NOAUDIT) == 0) 3828a56038cSKees Cook report_access("attach", child, current); 3832d514487SKees Cook 3842d514487SKees Cook return rc; 3852d514487SKees Cook } 3862d514487SKees Cook 3879d8dad74SKees Cook /** 3889d8dad74SKees Cook * yama_ptrace_traceme - validate PTRACE_TRACEME calls 3899d8dad74SKees Cook * @parent: task that will become the ptracer of the current task 3909d8dad74SKees Cook * 3919d8dad74SKees Cook * Returns 0 if following the ptrace is allowed, -ve on error. 3929d8dad74SKees Cook */ 393c6993e4aSKees Cook int yama_ptrace_traceme(struct task_struct *parent) 3949d8dad74SKees Cook { 395b1d9e6b0SCasey Schaufler int rc = 0; 3969d8dad74SKees Cook 3979d8dad74SKees Cook /* Only disallow PTRACE_TRACEME on more aggressive settings. */ 3989d8dad74SKees Cook switch (ptrace_scope) { 3999d8dad74SKees Cook case YAMA_SCOPE_CAPABILITY: 400eddc0a3aSEric W. Biederman if (!has_ns_capability(parent, current_user_ns(), CAP_SYS_PTRACE)) 4019d8dad74SKees Cook rc = -EPERM; 4029d8dad74SKees Cook break; 4039d8dad74SKees Cook case YAMA_SCOPE_NO_ATTACH: 4049d8dad74SKees Cook rc = -EPERM; 4059d8dad74SKees Cook break; 4069d8dad74SKees Cook } 4079d8dad74SKees Cook 408*dca6b414SJann Horn if (rc) { 409*dca6b414SJann Horn task_lock(current); 4108a56038cSKees Cook report_access("traceme", current, parent); 411*dca6b414SJann Horn task_unlock(current); 412*dca6b414SJann Horn } 4139d8dad74SKees Cook 4149d8dad74SKees Cook return rc; 4159d8dad74SKees Cook } 4169d8dad74SKees Cook 417b1d9e6b0SCasey Schaufler static struct security_hook_list yama_hooks[] = { 418e20b043aSCasey Schaufler LSM_HOOK_INIT(ptrace_access_check, yama_ptrace_access_check), 419e20b043aSCasey Schaufler LSM_HOOK_INIT(ptrace_traceme, yama_ptrace_traceme), 420e20b043aSCasey Schaufler LSM_HOOK_INIT(task_prctl, yama_task_prctl), 421e20b043aSCasey Schaufler LSM_HOOK_INIT(task_free, yama_task_free), 4222d514487SKees Cook }; 423b1d9e6b0SCasey Schaufler 4242d514487SKees Cook #ifdef CONFIG_SYSCTL 425389da25fSKees Cook static int yama_dointvec_minmax(struct ctl_table *table, int write, 426389da25fSKees Cook void __user *buffer, size_t *lenp, loff_t *ppos) 427389da25fSKees Cook { 42841a4695cSKees Cook struct ctl_table table_copy; 429389da25fSKees Cook 430389da25fSKees Cook if (write && !capable(CAP_SYS_PTRACE)) 431389da25fSKees Cook return -EPERM; 432389da25fSKees Cook 433389da25fSKees Cook /* Lock the max value if it ever gets set. */ 43441a4695cSKees Cook table_copy = *table; 43541a4695cSKees Cook if (*(int *)table_copy.data == *(int *)table_copy.extra2) 43641a4695cSKees Cook table_copy.extra1 = table_copy.extra2; 437389da25fSKees Cook 43841a4695cSKees Cook return proc_dointvec_minmax(&table_copy, write, buffer, lenp, ppos); 439389da25fSKees Cook } 440389da25fSKees Cook 4412d514487SKees Cook static int zero; 442389da25fSKees Cook static int max_scope = YAMA_SCOPE_NO_ATTACH; 4432d514487SKees Cook 4442d514487SKees Cook struct ctl_path yama_sysctl_path[] = { 4452d514487SKees Cook { .procname = "kernel", }, 4462d514487SKees Cook { .procname = "yama", }, 4472d514487SKees Cook { } 4482d514487SKees Cook }; 4492d514487SKees Cook 4502d514487SKees Cook static struct ctl_table yama_sysctl_table[] = { 4512d514487SKees Cook { 4522d514487SKees Cook .procname = "ptrace_scope", 4532d514487SKees Cook .data = &ptrace_scope, 4542d514487SKees Cook .maxlen = sizeof(int), 4552d514487SKees Cook .mode = 0644, 456389da25fSKees Cook .proc_handler = yama_dointvec_minmax, 4572d514487SKees Cook .extra1 = &zero, 458389da25fSKees Cook .extra2 = &max_scope, 4592d514487SKees Cook }, 4602d514487SKees Cook { } 4612d514487SKees Cook }; 462730daa16SKees Cook static void __init yama_init_sysctl(void) 4632d514487SKees Cook { 4642d514487SKees Cook if (!register_sysctl_paths(yama_sysctl_path, yama_sysctl_table)) 4652d514487SKees Cook panic("Yama: sysctl registration failed.\n"); 4662d514487SKees Cook } 467730daa16SKees Cook #else 468730daa16SKees Cook static inline void yama_init_sysctl(void) { } 469730daa16SKees Cook #endif /* CONFIG_SYSCTL */ 4702d514487SKees Cook 471730daa16SKees Cook void __init yama_add_hooks(void) 472730daa16SKees Cook { 473730daa16SKees Cook pr_info("Yama: becoming mindful.\n"); 474730daa16SKees Cook security_add_hooks(yama_hooks, ARRAY_SIZE(yama_hooks)); 475730daa16SKees Cook yama_init_sysctl(); 476730daa16SKees Cook } 477