1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * sysctl.c: General linux system control interface
4 */
5
6 #include <linux/printk.h>
7 #include <linux/capability.h>
8 #include <linux/ratelimit.h>
9 #include "internal.h"
10
11 static const int ten_thousand = 10000;
12
proc_dointvec_minmax_sysadmin(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)13 static int proc_dointvec_minmax_sysadmin(const struct ctl_table *table, int write,
14 void *buffer, size_t *lenp, loff_t *ppos)
15 {
16 if (write && !capable(CAP_SYS_ADMIN))
17 return -EPERM;
18
19 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
20 }
21
22 static const struct ctl_table printk_sysctls[] = {
23 {
24 .procname = "printk",
25 .data = &console_loglevel,
26 .maxlen = 4*sizeof(int),
27 .mode = 0644,
28 .proc_handler = proc_dointvec,
29 },
30 {
31 .procname = "printk_ratelimit",
32 .data = &printk_ratelimit_state.interval,
33 .maxlen = sizeof(int),
34 .mode = 0644,
35 .proc_handler = proc_dointvec_jiffies,
36 },
37 {
38 .procname = "printk_ratelimit_burst",
39 .data = &printk_ratelimit_state.burst,
40 .maxlen = sizeof(int),
41 .mode = 0644,
42 .proc_handler = proc_dointvec,
43 },
44 {
45 .procname = "printk_delay",
46 .data = &printk_delay_msec,
47 .maxlen = sizeof(int),
48 .mode = 0644,
49 .proc_handler = proc_dointvec_minmax,
50 .extra1 = SYSCTL_ZERO,
51 .extra2 = (void *)&ten_thousand,
52 },
53 {
54 .procname = "printk_devkmsg",
55 .data = devkmsg_log_str,
56 .maxlen = DEVKMSG_STR_MAX_SIZE,
57 .mode = 0644,
58 .proc_handler = devkmsg_sysctl_set_loglvl,
59 },
60 {
61 .procname = "dmesg_restrict",
62 .data = &dmesg_restrict,
63 .maxlen = sizeof(int),
64 .mode = 0644,
65 .proc_handler = proc_dointvec_minmax_sysadmin,
66 .extra1 = SYSCTL_ZERO,
67 .extra2 = SYSCTL_ONE,
68 },
69 {
70 .procname = "kptr_restrict",
71 .data = &kptr_restrict,
72 .maxlen = sizeof(int),
73 .mode = 0644,
74 .proc_handler = proc_dointvec_minmax_sysadmin,
75 .extra1 = SYSCTL_ZERO,
76 .extra2 = SYSCTL_TWO,
77 },
78 };
79
printk_sysctl_init(void)80 void __init printk_sysctl_init(void)
81 {
82 register_sysctl_init("kernel", printk_sysctls);
83 }
84