1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/stat.h>
3 #include <linux/sysctl.h>
4 #include "../fs/xfs/xfs_sysctl.h"
5 #include <linux/sunrpc/debug.h>
6 #include <linux/string.h>
7 #include <linux/syscalls.h>
8 #include <linux/namei.h>
9 #include <linux/mount.h>
10 #include <linux/fs.h>
11 #include <linux/nsproxy.h>
12 #include <linux/pid_namespace.h>
13 #include <linux/file.h>
14 #include <linux/ctype.h>
15 #include <linux/netdevice.h>
16 #include <linux/kernel.h>
17 #include <linux/uuid.h>
18 #include <linux/slab.h>
19 #include <linux/compat.h>
20 
21 #ifdef CONFIG_SYSCTL_SYSCALL
22 
23 struct bin_table;
24 typedef ssize_t bin_convert_t(struct file *file,
25 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen);
26 
27 static bin_convert_t bin_dir;
28 static bin_convert_t bin_string;
29 static bin_convert_t bin_intvec;
30 static bin_convert_t bin_ulongvec;
31 static bin_convert_t bin_uuid;
32 static bin_convert_t bin_dn_node_address;
33 
34 #define CTL_DIR   bin_dir
35 #define CTL_STR   bin_string
36 #define CTL_INT   bin_intvec
37 #define CTL_ULONG bin_ulongvec
38 #define CTL_UUID  bin_uuid
39 #define CTL_DNADR bin_dn_node_address
40 
41 #define BUFSZ 256
42 
43 struct bin_table {
44 	bin_convert_t		*convert;
45 	int			ctl_name;
46 	const char		*procname;
47 	const struct bin_table	*child;
48 };
49 
50 static const struct bin_table bin_random_table[] = {
51 	{ CTL_INT,	RANDOM_POOLSIZE,	"poolsize" },
52 	{ CTL_INT,	RANDOM_ENTROPY_COUNT,	"entropy_avail" },
53 	{ CTL_INT,	RANDOM_READ_THRESH,	"read_wakeup_threshold" },
54 	{ CTL_INT,	RANDOM_WRITE_THRESH,	"write_wakeup_threshold" },
55 	{ CTL_UUID,	RANDOM_BOOT_ID,		"boot_id" },
56 	{ CTL_UUID,	RANDOM_UUID,		"uuid" },
57 	{}
58 };
59 
60 static const struct bin_table bin_pty_table[] = {
61 	{ CTL_INT,	PTY_MAX,	"max" },
62 	{ CTL_INT,	PTY_NR,		"nr" },
63 	{}
64 };
65 
66 static const struct bin_table bin_kern_table[] = {
67 	{ CTL_STR,	KERN_OSTYPE,			"ostype" },
68 	{ CTL_STR,	KERN_OSRELEASE,			"osrelease" },
69 	/* KERN_OSREV not used */
70 	{ CTL_STR,	KERN_VERSION,			"version" },
71 	/* KERN_SECUREMASK not used */
72 	/* KERN_PROF not used */
73 	{ CTL_STR,	KERN_NODENAME,			"hostname" },
74 	{ CTL_STR,	KERN_DOMAINNAME,		"domainname" },
75 
76 	{ CTL_INT,	KERN_PANIC,			"panic" },
77 	{ CTL_INT,	KERN_REALROOTDEV,		"real-root-dev" },
78 
79 	{ CTL_STR,	KERN_SPARC_REBOOT,		"reboot-cmd" },
80 	{ CTL_INT,	KERN_CTLALTDEL,			"ctrl-alt-del" },
81 	{ CTL_INT,	KERN_PRINTK,			"printk" },
82 
83 	/* KERN_NAMETRANS not used */
84 	/* KERN_PPC_HTABRECLAIM not used */
85 	/* KERN_PPC_ZEROPAGED not used */
86 	{ CTL_INT,	KERN_PPC_POWERSAVE_NAP,		"powersave-nap" },
87 
88 	{ CTL_STR,	KERN_MODPROBE,			"modprobe" },
89 	{ CTL_INT,	KERN_SG_BIG_BUFF,		"sg-big-buff" },
90 	{ CTL_INT,	KERN_ACCT,			"acct" },
91 	/* KERN_PPC_L2CR "l2cr" no longer used */
92 
93 	/* KERN_RTSIGNR not used */
94 	/* KERN_RTSIGMAX not used */
95 
96 	{ CTL_ULONG,	KERN_SHMMAX,			"shmmax" },
97 	{ CTL_INT,	KERN_MSGMAX,			"msgmax" },
98 	{ CTL_INT,	KERN_MSGMNB,			"msgmnb" },
99 	/* KERN_MSGPOOL not used*/
100 	{ CTL_INT,	KERN_SYSRQ,			"sysrq" },
101 	{ CTL_INT,	KERN_MAX_THREADS,		"threads-max" },
102 	{ CTL_DIR,	KERN_RANDOM,			"random",	bin_random_table },
103 	{ CTL_ULONG,	KERN_SHMALL,			"shmall" },
104 	{ CTL_INT,	KERN_MSGMNI,			"msgmni" },
105 	{ CTL_INT,	KERN_SEM,			"sem" },
106 	{ CTL_INT,	KERN_SPARC_STOP_A,		"stop-a" },
107 	{ CTL_INT,	KERN_SHMMNI,			"shmmni" },
108 
109 	{ CTL_INT,	KERN_OVERFLOWUID,		"overflowuid" },
110 	{ CTL_INT,	KERN_OVERFLOWGID,		"overflowgid" },
111 
112 	{ CTL_STR,	KERN_HOTPLUG,			"hotplug", },
113 	{ CTL_INT,	KERN_IEEE_EMULATION_WARNINGS,	"ieee_emulation_warnings" },
114 
115 	{ CTL_INT,	KERN_S390_USER_DEBUG_LOGGING,	"userprocess_debug" },
116 	{ CTL_INT,	KERN_CORE_USES_PID,		"core_uses_pid" },
117 	/* KERN_TAINTED "tainted" no longer used */
118 	{ CTL_INT,	KERN_CADPID,			"cad_pid" },
119 	{ CTL_INT,	KERN_PIDMAX,			"pid_max" },
120 	{ CTL_STR,	KERN_CORE_PATTERN,		"core_pattern" },
121 	{ CTL_INT,	KERN_PANIC_ON_OOPS,		"panic_on_oops" },
122 	{ CTL_INT,	KERN_HPPA_PWRSW,		"soft-power" },
123 	{ CTL_INT,	KERN_HPPA_UNALIGNED,		"unaligned-trap" },
124 
125 	{ CTL_INT,	KERN_PRINTK_RATELIMIT,		"printk_ratelimit" },
126 	{ CTL_INT,	KERN_PRINTK_RATELIMIT_BURST,	"printk_ratelimit_burst" },
127 
128 	{ CTL_DIR,	KERN_PTY,			"pty",		bin_pty_table },
129 	{ CTL_INT,	KERN_NGROUPS_MAX,		"ngroups_max" },
130 	{ CTL_INT,	KERN_SPARC_SCONS_PWROFF,	"scons-poweroff" },
131 	/* KERN_HZ_TIMER "hz_timer" no longer used */
132 	{ CTL_INT,	KERN_UNKNOWN_NMI_PANIC,		"unknown_nmi_panic" },
133 	{ CTL_INT,	KERN_BOOTLOADER_TYPE,		"bootloader_type" },
134 	{ CTL_INT,	KERN_RANDOMIZE,			"randomize_va_space" },
135 
136 	{ CTL_INT,	KERN_SPIN_RETRY,		"spin_retry" },
137 	/* KERN_ACPI_VIDEO_FLAGS "acpi_video_flags" no longer used */
138 	{ CTL_INT,	KERN_IA64_UNALIGNED,		"ignore-unaligned-usertrap" },
139 	{ CTL_INT,	KERN_COMPAT_LOG,		"compat-log" },
140 	{ CTL_INT,	KERN_MAX_LOCK_DEPTH,		"max_lock_depth" },
141 	{ CTL_INT,	KERN_PANIC_ON_NMI,		"panic_on_unrecovered_nmi" },
142 	{ CTL_INT,	KERN_PANIC_ON_WARN,		"panic_on_warn" },
143 	{ CTL_ULONG,	KERN_PANIC_PRINT,		"panic_print" },
144 	{}
145 };
146 
147 static const struct bin_table bin_vm_table[] = {
148 	{ CTL_INT,	VM_OVERCOMMIT_MEMORY,		"overcommit_memory" },
149 	{ CTL_INT,	VM_PAGE_CLUSTER,		"page-cluster" },
150 	{ CTL_INT,	VM_DIRTY_BACKGROUND,		"dirty_background_ratio" },
151 	{ CTL_INT,	VM_DIRTY_RATIO,			"dirty_ratio" },
152 	/* VM_DIRTY_WB_CS "dirty_writeback_centisecs" no longer used */
153 	/* VM_DIRTY_EXPIRE_CS "dirty_expire_centisecs" no longer used */
154 	/* VM_NR_PDFLUSH_THREADS "nr_pdflush_threads" no longer used */
155 	{ CTL_INT,	VM_OVERCOMMIT_RATIO,		"overcommit_ratio" },
156 	/* VM_PAGEBUF unused */
157 	/* VM_HUGETLB_PAGES "nr_hugepages" no longer used */
158 	{ CTL_INT,	VM_SWAPPINESS,			"swappiness" },
159 	{ CTL_INT,	VM_LOWMEM_RESERVE_RATIO,	"lowmem_reserve_ratio" },
160 	{ CTL_INT,	VM_MIN_FREE_KBYTES,		"min_free_kbytes" },
161 	{ CTL_INT,	VM_MAX_MAP_COUNT,		"max_map_count" },
162 	{ CTL_INT,	VM_LAPTOP_MODE,			"laptop_mode" },
163 	{ CTL_INT,	VM_BLOCK_DUMP,			"block_dump" },
164 	{ CTL_INT,	VM_HUGETLB_GROUP,		"hugetlb_shm_group" },
165 	{ CTL_INT,	VM_VFS_CACHE_PRESSURE,	"vfs_cache_pressure" },
166 	{ CTL_INT,	VM_LEGACY_VA_LAYOUT,		"legacy_va_layout" },
167 	/* VM_SWAP_TOKEN_TIMEOUT unused */
168 	{ CTL_INT,	VM_DROP_PAGECACHE,		"drop_caches" },
169 	{ CTL_INT,	VM_PERCPU_PAGELIST_FRACTION,	"percpu_pagelist_fraction" },
170 	{ CTL_INT,	VM_ZONE_RECLAIM_MODE,		"zone_reclaim_mode" },
171 	{ CTL_INT,	VM_MIN_UNMAPPED,		"min_unmapped_ratio" },
172 	{ CTL_INT,	VM_PANIC_ON_OOM,		"panic_on_oom" },
173 	{ CTL_INT,	VM_VDSO_ENABLED,		"vdso_enabled" },
174 	{ CTL_INT,	VM_MIN_SLAB,			"min_slab_ratio" },
175 
176 	{}
177 };
178 
179 static const struct bin_table bin_net_core_table[] = {
180 	{ CTL_INT,	NET_CORE_WMEM_MAX,	"wmem_max" },
181 	{ CTL_INT,	NET_CORE_RMEM_MAX,	"rmem_max" },
182 	{ CTL_INT,	NET_CORE_WMEM_DEFAULT,	"wmem_default" },
183 	{ CTL_INT,	NET_CORE_RMEM_DEFAULT,	"rmem_default" },
184 	/* NET_CORE_DESTROY_DELAY unused */
185 	{ CTL_INT,	NET_CORE_MAX_BACKLOG,	"netdev_max_backlog" },
186 	/* NET_CORE_FASTROUTE unused */
187 	{ CTL_INT,	NET_CORE_MSG_COST,	"message_cost" },
188 	{ CTL_INT,	NET_CORE_MSG_BURST,	"message_burst" },
189 	{ CTL_INT,	NET_CORE_OPTMEM_MAX,	"optmem_max" },
190 	/* NET_CORE_HOT_LIST_LENGTH unused */
191 	/* NET_CORE_DIVERT_VERSION unused */
192 	/* NET_CORE_NO_CONG_THRESH unused */
193 	/* NET_CORE_NO_CONG unused */
194 	/* NET_CORE_LO_CONG unused */
195 	/* NET_CORE_MOD_CONG unused */
196 	{ CTL_INT,	NET_CORE_DEV_WEIGHT,	"dev_weight" },
197 	{ CTL_INT,	NET_CORE_SOMAXCONN,	"somaxconn" },
198 	{ CTL_INT,	NET_CORE_BUDGET,	"netdev_budget" },
199 	{ CTL_INT,	NET_CORE_AEVENT_ETIME,	"xfrm_aevent_etime" },
200 	{ CTL_INT,	NET_CORE_AEVENT_RSEQTH,	"xfrm_aevent_rseqth" },
201 	{ CTL_INT,	NET_CORE_WARNINGS,	"warnings" },
202 	{},
203 };
204 
205 static const struct bin_table bin_net_unix_table[] = {
206 	/* NET_UNIX_DESTROY_DELAY unused */
207 	/* NET_UNIX_DELETE_DELAY unused */
208 	{ CTL_INT,	NET_UNIX_MAX_DGRAM_QLEN,	"max_dgram_qlen" },
209 	{}
210 };
211 
212 static const struct bin_table bin_net_ipv4_route_table[] = {
213 	{ CTL_INT,	NET_IPV4_ROUTE_FLUSH,			"flush" },
214 	/* NET_IPV4_ROUTE_MIN_DELAY "min_delay" no longer used */
215 	/* NET_IPV4_ROUTE_MAX_DELAY "max_delay" no longer used */
216 	{ CTL_INT,	NET_IPV4_ROUTE_GC_THRESH,		"gc_thresh" },
217 	{ CTL_INT,	NET_IPV4_ROUTE_MAX_SIZE,		"max_size" },
218 	{ CTL_INT,	NET_IPV4_ROUTE_GC_MIN_INTERVAL,		"gc_min_interval" },
219 	{ CTL_INT,	NET_IPV4_ROUTE_GC_MIN_INTERVAL_MS,	"gc_min_interval_ms" },
220 	{ CTL_INT,	NET_IPV4_ROUTE_GC_TIMEOUT,		"gc_timeout" },
221 	/* NET_IPV4_ROUTE_GC_INTERVAL "gc_interval" no longer used */
222 	{ CTL_INT,	NET_IPV4_ROUTE_REDIRECT_LOAD,		"redirect_load" },
223 	{ CTL_INT,	NET_IPV4_ROUTE_REDIRECT_NUMBER,		"redirect_number" },
224 	{ CTL_INT,	NET_IPV4_ROUTE_REDIRECT_SILENCE,	"redirect_silence" },
225 	{ CTL_INT,	NET_IPV4_ROUTE_ERROR_COST,		"error_cost" },
226 	{ CTL_INT,	NET_IPV4_ROUTE_ERROR_BURST,		"error_burst" },
227 	{ CTL_INT,	NET_IPV4_ROUTE_GC_ELASTICITY,		"gc_elasticity" },
228 	{ CTL_INT,	NET_IPV4_ROUTE_MTU_EXPIRES,		"mtu_expires" },
229 	{ CTL_INT,	NET_IPV4_ROUTE_MIN_PMTU,		"min_pmtu" },
230 	{ CTL_INT,	NET_IPV4_ROUTE_MIN_ADVMSS,		"min_adv_mss" },
231 	{}
232 };
233 
234 static const struct bin_table bin_net_ipv4_conf_vars_table[] = {
235 	{ CTL_INT,	NET_IPV4_CONF_FORWARDING,		"forwarding" },
236 	{ CTL_INT,	NET_IPV4_CONF_MC_FORWARDING,		"mc_forwarding" },
237 
238 	{ CTL_INT,	NET_IPV4_CONF_ACCEPT_REDIRECTS,		"accept_redirects" },
239 	{ CTL_INT,	NET_IPV4_CONF_SECURE_REDIRECTS,		"secure_redirects" },
240 	{ CTL_INT,	NET_IPV4_CONF_SEND_REDIRECTS,		"send_redirects" },
241 	{ CTL_INT,	NET_IPV4_CONF_SHARED_MEDIA,		"shared_media" },
242 	{ CTL_INT,	NET_IPV4_CONF_RP_FILTER,		"rp_filter" },
243 	{ CTL_INT,	NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE,	"accept_source_route" },
244 	{ CTL_INT,	NET_IPV4_CONF_PROXY_ARP,		"proxy_arp" },
245 	{ CTL_INT,	NET_IPV4_CONF_MEDIUM_ID,		"medium_id" },
246 	{ CTL_INT,	NET_IPV4_CONF_BOOTP_RELAY,		"bootp_relay" },
247 	{ CTL_INT,	NET_IPV4_CONF_LOG_MARTIANS,		"log_martians" },
248 	{ CTL_INT,	NET_IPV4_CONF_TAG,			"tag" },
249 	{ CTL_INT,	NET_IPV4_CONF_ARPFILTER,		"arp_filter" },
250 	{ CTL_INT,	NET_IPV4_CONF_ARP_ANNOUNCE,		"arp_announce" },
251 	{ CTL_INT,	NET_IPV4_CONF_ARP_IGNORE,		"arp_ignore" },
252 	{ CTL_INT,	NET_IPV4_CONF_ARP_ACCEPT,		"arp_accept" },
253 	{ CTL_INT,	NET_IPV4_CONF_ARP_NOTIFY,		"arp_notify" },
254 
255 	{ CTL_INT,	NET_IPV4_CONF_NOXFRM,			"disable_xfrm" },
256 	{ CTL_INT,	NET_IPV4_CONF_NOPOLICY,			"disable_policy" },
257 	{ CTL_INT,	NET_IPV4_CONF_FORCE_IGMP_VERSION,	"force_igmp_version" },
258 	{ CTL_INT,	NET_IPV4_CONF_PROMOTE_SECONDARIES,	"promote_secondaries" },
259 	{}
260 };
261 
262 static const struct bin_table bin_net_ipv4_conf_table[] = {
263 	{ CTL_DIR,	NET_PROTO_CONF_ALL,	"all",		bin_net_ipv4_conf_vars_table },
264 	{ CTL_DIR,	NET_PROTO_CONF_DEFAULT,	"default",	bin_net_ipv4_conf_vars_table },
265 	{ CTL_DIR,	0, NULL, bin_net_ipv4_conf_vars_table },
266 	{}
267 };
268 
269 static const struct bin_table bin_net_neigh_vars_table[] = {
270 	{ CTL_INT,	NET_NEIGH_MCAST_SOLICIT,	"mcast_solicit" },
271 	{ CTL_INT,	NET_NEIGH_UCAST_SOLICIT,	"ucast_solicit" },
272 	{ CTL_INT,	NET_NEIGH_APP_SOLICIT,		"app_solicit" },
273 	/* NET_NEIGH_RETRANS_TIME "retrans_time" no longer used */
274 	{ CTL_INT,	NET_NEIGH_REACHABLE_TIME,	"base_reachable_time" },
275 	{ CTL_INT,	NET_NEIGH_DELAY_PROBE_TIME,	"delay_first_probe_time" },
276 	{ CTL_INT,	NET_NEIGH_GC_STALE_TIME,	"gc_stale_time" },
277 	{ CTL_INT,	NET_NEIGH_UNRES_QLEN,		"unres_qlen" },
278 	{ CTL_INT,	NET_NEIGH_PROXY_QLEN,		"proxy_qlen" },
279 	/* NET_NEIGH_ANYCAST_DELAY "anycast_delay" no longer used */
280 	/* NET_NEIGH_PROXY_DELAY "proxy_delay" no longer used */
281 	/* NET_NEIGH_LOCKTIME "locktime" no longer used */
282 	{ CTL_INT,	NET_NEIGH_GC_INTERVAL,		"gc_interval" },
283 	{ CTL_INT,	NET_NEIGH_GC_THRESH1,		"gc_thresh1" },
284 	{ CTL_INT,	NET_NEIGH_GC_THRESH2,		"gc_thresh2" },
285 	{ CTL_INT,	NET_NEIGH_GC_THRESH3,		"gc_thresh3" },
286 	{ CTL_INT,	NET_NEIGH_RETRANS_TIME_MS,	"retrans_time_ms" },
287 	{ CTL_INT,	NET_NEIGH_REACHABLE_TIME_MS,	"base_reachable_time_ms" },
288 	{}
289 };
290 
291 static const struct bin_table bin_net_neigh_table[] = {
292 	{ CTL_DIR,	NET_PROTO_CONF_DEFAULT, "default", bin_net_neigh_vars_table },
293 	{ CTL_DIR,	0, NULL, bin_net_neigh_vars_table },
294 	{}
295 };
296 
297 static const struct bin_table bin_net_ipv4_netfilter_table[] = {
298 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_MAX,		"ip_conntrack_max" },
299 
300 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT "ip_conntrack_tcp_timeout_syn_sent" no longer used */
301 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV "ip_conntrack_tcp_timeout_syn_recv" no longer used */
302 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED "ip_conntrack_tcp_timeout_established" no longer used */
303 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT "ip_conntrack_tcp_timeout_fin_wait" no longer used */
304 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT	"ip_conntrack_tcp_timeout_close_wait" no longer used */
305 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK "ip_conntrack_tcp_timeout_last_ack" no longer used */
306 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT "ip_conntrack_tcp_timeout_time_wait" no longer used */
307 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE "ip_conntrack_tcp_timeout_close" no longer used */
308 
309 	/* NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT "ip_conntrack_udp_timeout" no longer used */
310 	/* NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM "ip_conntrack_udp_timeout_stream" no longer used */
311 	/* NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT "ip_conntrack_icmp_timeout" no longer used */
312 	/* NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT "ip_conntrack_generic_timeout" no longer used */
313 
314 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_BUCKETS,		"ip_conntrack_buckets" },
315 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_LOG_INVALID,	"ip_conntrack_log_invalid" },
316 	/* NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS "ip_conntrack_tcp_timeout_max_retrans" no longer used */
317 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_TCP_LOOSE,	"ip_conntrack_tcp_loose" },
318 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_TCP_BE_LIBERAL,	"ip_conntrack_tcp_be_liberal" },
319 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_TCP_MAX_RETRANS,	"ip_conntrack_tcp_max_retrans" },
320 
321 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_CLOSED "ip_conntrack_sctp_timeout_closed" no longer used */
322 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_COOKIE_WAIT "ip_conntrack_sctp_timeout_cookie_wait" no longer used */
323 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_COOKIE_ECHOED "ip_conntrack_sctp_timeout_cookie_echoed" no longer used */
324 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_ESTABLISHED "ip_conntrack_sctp_timeout_established" no longer used */
325 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_SENT "ip_conntrack_sctp_timeout_shutdown_sent" no longer used */
326 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_RECD "ip_conntrack_sctp_timeout_shutdown_recd" no longer used */
327 	/* NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_ACK_SENT "ip_conntrack_sctp_timeout_shutdown_ack_sent" no longer used */
328 
329 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_COUNT,		"ip_conntrack_count" },
330 	{ CTL_INT,	NET_IPV4_NF_CONNTRACK_CHECKSUM,		"ip_conntrack_checksum" },
331 	{}
332 };
333 
334 static const struct bin_table bin_net_ipv4_table[] = {
335 	{CTL_INT,	NET_IPV4_FORWARD,			"ip_forward" },
336 
337 	{ CTL_DIR,	NET_IPV4_CONF,		"conf",		bin_net_ipv4_conf_table },
338 	{ CTL_DIR,	NET_IPV4_NEIGH,		"neigh",	bin_net_neigh_table },
339 	{ CTL_DIR,	NET_IPV4_ROUTE,		"route",	bin_net_ipv4_route_table },
340 	/* NET_IPV4_FIB_HASH unused */
341 	{ CTL_DIR,	NET_IPV4_NETFILTER,	"netfilter",	bin_net_ipv4_netfilter_table },
342 
343 	{ CTL_INT,	NET_IPV4_TCP_TIMESTAMPS,		"tcp_timestamps" },
344 	{ CTL_INT,	NET_IPV4_TCP_WINDOW_SCALING,		"tcp_window_scaling" },
345 	{ CTL_INT,	NET_IPV4_TCP_SACK,			"tcp_sack" },
346 	{ CTL_INT,	NET_IPV4_TCP_RETRANS_COLLAPSE,		"tcp_retrans_collapse" },
347 	{ CTL_INT,	NET_IPV4_DEFAULT_TTL,			"ip_default_ttl" },
348 	/* NET_IPV4_AUTOCONFIG unused */
349 	{ CTL_INT,	NET_IPV4_NO_PMTU_DISC,			"ip_no_pmtu_disc" },
350 	{ CTL_INT,	NET_IPV4_NONLOCAL_BIND,			"ip_nonlocal_bind" },
351 	{ CTL_INT,	NET_IPV4_TCP_SYN_RETRIES,		"tcp_syn_retries" },
352 	{ CTL_INT,	NET_TCP_SYNACK_RETRIES,			"tcp_synack_retries" },
353 	{ CTL_INT,	NET_TCP_MAX_ORPHANS,			"tcp_max_orphans" },
354 	{ CTL_INT,	NET_TCP_MAX_TW_BUCKETS,			"tcp_max_tw_buckets" },
355 	{ CTL_INT,	NET_IPV4_DYNADDR,			"ip_dynaddr" },
356 	{ CTL_INT,	NET_IPV4_TCP_KEEPALIVE_TIME,		"tcp_keepalive_time" },
357 	{ CTL_INT,	NET_IPV4_TCP_KEEPALIVE_PROBES,		"tcp_keepalive_probes" },
358 	{ CTL_INT,	NET_IPV4_TCP_KEEPALIVE_INTVL,		"tcp_keepalive_intvl" },
359 	{ CTL_INT,	NET_IPV4_TCP_RETRIES1,			"tcp_retries1" },
360 	{ CTL_INT,	NET_IPV4_TCP_RETRIES2,			"tcp_retries2" },
361 	{ CTL_INT,	NET_IPV4_TCP_FIN_TIMEOUT,		"tcp_fin_timeout" },
362 	{ CTL_INT,	NET_TCP_SYNCOOKIES,			"tcp_syncookies" },
363 	{ CTL_INT,	NET_TCP_TW_RECYCLE,			"tcp_tw_recycle" },
364 	{ CTL_INT,	NET_TCP_ABORT_ON_OVERFLOW,		"tcp_abort_on_overflow" },
365 	{ CTL_INT,	NET_TCP_STDURG,				"tcp_stdurg" },
366 	{ CTL_INT,	NET_TCP_RFC1337,			"tcp_rfc1337" },
367 	{ CTL_INT,	NET_TCP_MAX_SYN_BACKLOG,		"tcp_max_syn_backlog" },
368 	{ CTL_INT,	NET_IPV4_LOCAL_PORT_RANGE,		"ip_local_port_range" },
369 	{ CTL_INT,	NET_IPV4_IGMP_MAX_MEMBERSHIPS,		"igmp_max_memberships" },
370 	{ CTL_INT,	NET_IPV4_IGMP_MAX_MSF,			"igmp_max_msf" },
371 	{ CTL_INT,	NET_IPV4_INET_PEER_THRESHOLD,		"inet_peer_threshold" },
372 	{ CTL_INT,	NET_IPV4_INET_PEER_MINTTL,		"inet_peer_minttl" },
373 	{ CTL_INT,	NET_IPV4_INET_PEER_MAXTTL,		"inet_peer_maxttl" },
374 	{ CTL_INT,	NET_IPV4_INET_PEER_GC_MINTIME,		"inet_peer_gc_mintime" },
375 	{ CTL_INT,	NET_IPV4_INET_PEER_GC_MAXTIME,		"inet_peer_gc_maxtime" },
376 	{ CTL_INT,	NET_TCP_ORPHAN_RETRIES,			"tcp_orphan_retries" },
377 	{ CTL_INT,	NET_TCP_FACK,				"tcp_fack" },
378 	{ CTL_INT,	NET_TCP_REORDERING,			"tcp_reordering" },
379 	{ CTL_INT,	NET_TCP_ECN,				"tcp_ecn" },
380 	{ CTL_INT,	NET_TCP_DSACK,				"tcp_dsack" },
381 	{ CTL_INT,	NET_TCP_MEM,				"tcp_mem" },
382 	{ CTL_INT,	NET_TCP_WMEM,				"tcp_wmem" },
383 	{ CTL_INT,	NET_TCP_RMEM,				"tcp_rmem" },
384 	{ CTL_INT,	NET_TCP_APP_WIN,			"tcp_app_win" },
385 	{ CTL_INT,	NET_TCP_ADV_WIN_SCALE,			"tcp_adv_win_scale" },
386 	{ CTL_INT,	NET_TCP_TW_REUSE,			"tcp_tw_reuse" },
387 	{ CTL_INT,	NET_TCP_FRTO,				"tcp_frto" },
388 	{ CTL_INT,	NET_TCP_FRTO_RESPONSE,			"tcp_frto_response" },
389 	{ CTL_INT,	NET_TCP_LOW_LATENCY,			"tcp_low_latency" },
390 	{ CTL_INT,	NET_TCP_NO_METRICS_SAVE,		"tcp_no_metrics_save" },
391 	{ CTL_INT,	NET_TCP_MODERATE_RCVBUF,		"tcp_moderate_rcvbuf" },
392 	{ CTL_INT,	NET_TCP_TSO_WIN_DIVISOR,		"tcp_tso_win_divisor" },
393 	{ CTL_STR,	NET_TCP_CONG_CONTROL,			"tcp_congestion_control" },
394 	{ CTL_INT,	NET_TCP_MTU_PROBING,			"tcp_mtu_probing" },
395 	{ CTL_INT,	NET_TCP_BASE_MSS,			"tcp_base_mss" },
396 	{ CTL_INT,	NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS,	"tcp_workaround_signed_windows" },
397 	{ CTL_INT,	NET_TCP_SLOW_START_AFTER_IDLE,		"tcp_slow_start_after_idle" },
398 	{ CTL_INT,	NET_CIPSOV4_CACHE_ENABLE,		"cipso_cache_enable" },
399 	{ CTL_INT,	NET_CIPSOV4_CACHE_BUCKET_SIZE,		"cipso_cache_bucket_size" },
400 	{ CTL_INT,	NET_CIPSOV4_RBM_OPTFMT,			"cipso_rbm_optfmt" },
401 	{ CTL_INT,	NET_CIPSOV4_RBM_STRICTVALID,		"cipso_rbm_strictvalid" },
402 	/* NET_TCP_AVAIL_CONG_CONTROL "tcp_available_congestion_control" no longer used */
403 	{ CTL_STR,	NET_TCP_ALLOWED_CONG_CONTROL,		"tcp_allowed_congestion_control" },
404 	{ CTL_INT,	NET_TCP_MAX_SSTHRESH,			"tcp_max_ssthresh" },
405 
406 	{ CTL_INT,	NET_IPV4_ICMP_ECHO_IGNORE_ALL,		"icmp_echo_ignore_all" },
407 	{ CTL_INT,	NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS,	"icmp_echo_ignore_broadcasts" },
408 	{ CTL_INT,	NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES,	"icmp_ignore_bogus_error_responses" },
409 	{ CTL_INT,	NET_IPV4_ICMP_ERRORS_USE_INBOUND_IFADDR,	"icmp_errors_use_inbound_ifaddr" },
410 	{ CTL_INT,	NET_IPV4_ICMP_RATELIMIT,		"icmp_ratelimit" },
411 	{ CTL_INT,	NET_IPV4_ICMP_RATEMASK,			"icmp_ratemask" },
412 
413 	{ CTL_INT,	NET_IPV4_IPFRAG_HIGH_THRESH,		"ipfrag_high_thresh" },
414 	{ CTL_INT,	NET_IPV4_IPFRAG_LOW_THRESH,		"ipfrag_low_thresh" },
415 	{ CTL_INT,	NET_IPV4_IPFRAG_TIME,			"ipfrag_time" },
416 
417 	{ CTL_INT,	NET_IPV4_IPFRAG_SECRET_INTERVAL,	"ipfrag_secret_interval" },
418 	/* NET_IPV4_IPFRAG_MAX_DIST "ipfrag_max_dist" no longer used */
419 
420 	{ CTL_INT,	2088 /* NET_IPQ_QMAX */,		"ip_queue_maxlen" },
421 
422 	/* NET_TCP_DEFAULT_WIN_SCALE unused */
423 	/* NET_TCP_BIC_BETA unused */
424 	/* NET_IPV4_TCP_MAX_KA_PROBES unused */
425 	/* NET_IPV4_IP_MASQ_DEBUG unused */
426 	/* NET_TCP_SYN_TAILDROP unused */
427 	/* NET_IPV4_ICMP_SOURCEQUENCH_RATE unused */
428 	/* NET_IPV4_ICMP_DESTUNREACH_RATE unused */
429 	/* NET_IPV4_ICMP_TIMEEXCEED_RATE unused */
430 	/* NET_IPV4_ICMP_PARAMPROB_RATE unused */
431 	/* NET_IPV4_ICMP_ECHOREPLY_RATE unused */
432 	/* NET_IPV4_ALWAYS_DEFRAG unused */
433 	{}
434 };
435 
436 static const struct bin_table bin_net_ipx_table[] = {
437 	{ CTL_INT,	NET_IPX_PPROP_BROADCASTING,	"ipx_pprop_broadcasting" },
438 	/* NET_IPX_FORWARDING unused */
439 	{}
440 };
441 
442 static const struct bin_table bin_net_atalk_table[] = {
443 	{ CTL_INT,	NET_ATALK_AARP_EXPIRY_TIME,		"aarp-expiry-time" },
444 	{ CTL_INT,	NET_ATALK_AARP_TICK_TIME,		"aarp-tick-time" },
445 	{ CTL_INT,	NET_ATALK_AARP_RETRANSMIT_LIMIT,	"aarp-retransmit-limit" },
446 	{ CTL_INT,	NET_ATALK_AARP_RESOLVE_TIME,		"aarp-resolve-time" },
447 	{},
448 };
449 
450 static const struct bin_table bin_net_netrom_table[] = {
451 	{ CTL_INT,	NET_NETROM_DEFAULT_PATH_QUALITY,		"default_path_quality" },
452 	{ CTL_INT,	NET_NETROM_OBSOLESCENCE_COUNT_INITIALISER,	"obsolescence_count_initialiser" },
453 	{ CTL_INT,	NET_NETROM_NETWORK_TTL_INITIALISER,		"network_ttl_initialiser" },
454 	{ CTL_INT,	NET_NETROM_TRANSPORT_TIMEOUT,			"transport_timeout" },
455 	{ CTL_INT,	NET_NETROM_TRANSPORT_MAXIMUM_TRIES,		"transport_maximum_tries" },
456 	{ CTL_INT,	NET_NETROM_TRANSPORT_ACKNOWLEDGE_DELAY,		"transport_acknowledge_delay" },
457 	{ CTL_INT,	NET_NETROM_TRANSPORT_BUSY_DELAY,		"transport_busy_delay" },
458 	{ CTL_INT,	NET_NETROM_TRANSPORT_REQUESTED_WINDOW_SIZE,	"transport_requested_window_size" },
459 	{ CTL_INT,	NET_NETROM_TRANSPORT_NO_ACTIVITY_TIMEOUT,	"transport_no_activity_timeout" },
460 	{ CTL_INT,	NET_NETROM_ROUTING_CONTROL,			"routing_control" },
461 	{ CTL_INT,	NET_NETROM_LINK_FAILS_COUNT,			"link_fails_count" },
462 	{ CTL_INT,	NET_NETROM_RESET,				"reset" },
463 	{}
464 };
465 
466 static const struct bin_table bin_net_ax25_param_table[] = {
467 	{ CTL_INT,	NET_AX25_IP_DEFAULT_MODE,	"ip_default_mode" },
468 	{ CTL_INT,	NET_AX25_DEFAULT_MODE,		"ax25_default_mode" },
469 	{ CTL_INT,	NET_AX25_BACKOFF_TYPE,		"backoff_type" },
470 	{ CTL_INT,	NET_AX25_CONNECT_MODE,		"connect_mode" },
471 	{ CTL_INT,	NET_AX25_STANDARD_WINDOW,	"standard_window_size" },
472 	{ CTL_INT,	NET_AX25_EXTENDED_WINDOW,	"extended_window_size" },
473 	{ CTL_INT,	NET_AX25_T1_TIMEOUT,		"t1_timeout" },
474 	{ CTL_INT,	NET_AX25_T2_TIMEOUT,		"t2_timeout" },
475 	{ CTL_INT,	NET_AX25_T3_TIMEOUT,		"t3_timeout" },
476 	{ CTL_INT,	NET_AX25_IDLE_TIMEOUT,		"idle_timeout" },
477 	{ CTL_INT,	NET_AX25_N2,			"maximum_retry_count" },
478 	{ CTL_INT,	NET_AX25_PACLEN,		"maximum_packet_length" },
479 	{ CTL_INT,	NET_AX25_PROTOCOL,		"protocol" },
480 	{ CTL_INT,	NET_AX25_DAMA_SLAVE_TIMEOUT,	"dama_slave_timeout" },
481 	{}
482 };
483 
484 static const struct bin_table bin_net_ax25_table[] = {
485 	{ CTL_DIR,	0, NULL, bin_net_ax25_param_table },
486 	{}
487 };
488 
489 static const struct bin_table bin_net_rose_table[] = {
490 	{ CTL_INT,	NET_ROSE_RESTART_REQUEST_TIMEOUT,	"restart_request_timeout" },
491 	{ CTL_INT,	NET_ROSE_CALL_REQUEST_TIMEOUT,		"call_request_timeout" },
492 	{ CTL_INT,	NET_ROSE_RESET_REQUEST_TIMEOUT,		"reset_request_timeout" },
493 	{ CTL_INT,	NET_ROSE_CLEAR_REQUEST_TIMEOUT,		"clear_request_timeout" },
494 	{ CTL_INT,	NET_ROSE_ACK_HOLD_BACK_TIMEOUT,		"acknowledge_hold_back_timeout" },
495 	{ CTL_INT,	NET_ROSE_ROUTING_CONTROL,		"routing_control" },
496 	{ CTL_INT,	NET_ROSE_LINK_FAIL_TIMEOUT,		"link_fail_timeout" },
497 	{ CTL_INT,	NET_ROSE_MAX_VCS,			"maximum_virtual_circuits" },
498 	{ CTL_INT,	NET_ROSE_WINDOW_SIZE,			"window_size" },
499 	{ CTL_INT,	NET_ROSE_NO_ACTIVITY_TIMEOUT,		"no_activity_timeout" },
500 	{}
501 };
502 
503 static const struct bin_table bin_net_ipv6_conf_var_table[] = {
504 	{ CTL_INT,	NET_IPV6_FORWARDING,			"forwarding" },
505 	{ CTL_INT,	NET_IPV6_HOP_LIMIT,			"hop_limit" },
506 	{ CTL_INT,	NET_IPV6_MTU,				"mtu" },
507 	{ CTL_INT,	NET_IPV6_ACCEPT_RA,			"accept_ra" },
508 	{ CTL_INT,	NET_IPV6_ACCEPT_REDIRECTS,		"accept_redirects" },
509 	{ CTL_INT,	NET_IPV6_AUTOCONF,			"autoconf" },
510 	{ CTL_INT,	NET_IPV6_DAD_TRANSMITS,			"dad_transmits" },
511 	{ CTL_INT,	NET_IPV6_RTR_SOLICITS,			"router_solicitations" },
512 	{ CTL_INT,	NET_IPV6_RTR_SOLICIT_INTERVAL,		"router_solicitation_interval" },
513 	{ CTL_INT,	NET_IPV6_RTR_SOLICIT_DELAY,		"router_solicitation_delay" },
514 	{ CTL_INT,	NET_IPV6_USE_TEMPADDR,			"use_tempaddr" },
515 	{ CTL_INT,	NET_IPV6_TEMP_VALID_LFT,		"temp_valid_lft" },
516 	{ CTL_INT,	NET_IPV6_TEMP_PREFERED_LFT,		"temp_prefered_lft" },
517 	{ CTL_INT,	NET_IPV6_REGEN_MAX_RETRY,		"regen_max_retry" },
518 	{ CTL_INT,	NET_IPV6_MAX_DESYNC_FACTOR,		"max_desync_factor" },
519 	{ CTL_INT,	NET_IPV6_MAX_ADDRESSES,			"max_addresses" },
520 	{ CTL_INT,	NET_IPV6_FORCE_MLD_VERSION,		"force_mld_version" },
521 	{ CTL_INT,	NET_IPV6_ACCEPT_RA_DEFRTR,		"accept_ra_defrtr" },
522 	{ CTL_INT,	NET_IPV6_ACCEPT_RA_PINFO,		"accept_ra_pinfo" },
523 	{ CTL_INT,	NET_IPV6_ACCEPT_RA_RTR_PREF,		"accept_ra_rtr_pref" },
524 	{ CTL_INT,	NET_IPV6_RTR_PROBE_INTERVAL,		"router_probe_interval" },
525 	{ CTL_INT,	NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN,	"accept_ra_rt_info_max_plen" },
526 	{ CTL_INT,	NET_IPV6_PROXY_NDP,			"proxy_ndp" },
527 	{ CTL_INT,	NET_IPV6_ACCEPT_SOURCE_ROUTE,		"accept_source_route" },
528 	{ CTL_INT,	NET_IPV6_ACCEPT_RA_FROM_LOCAL,		"accept_ra_from_local" },
529 	{}
530 };
531 
532 static const struct bin_table bin_net_ipv6_conf_table[] = {
533 	{ CTL_DIR,	NET_PROTO_CONF_ALL,		"all",	bin_net_ipv6_conf_var_table },
534 	{ CTL_DIR,	NET_PROTO_CONF_DEFAULT, 	"default", bin_net_ipv6_conf_var_table },
535 	{ CTL_DIR,	0, NULL, bin_net_ipv6_conf_var_table },
536 	{}
537 };
538 
539 static const struct bin_table bin_net_ipv6_route_table[] = {
540 	/* NET_IPV6_ROUTE_FLUSH	"flush"  no longer used */
541 	{ CTL_INT,	NET_IPV6_ROUTE_GC_THRESH,		"gc_thresh" },
542 	{ CTL_INT,	NET_IPV6_ROUTE_MAX_SIZE,		"max_size" },
543 	{ CTL_INT,	NET_IPV6_ROUTE_GC_MIN_INTERVAL,		"gc_min_interval" },
544 	{ CTL_INT,	NET_IPV6_ROUTE_GC_TIMEOUT,		"gc_timeout" },
545 	{ CTL_INT,	NET_IPV6_ROUTE_GC_INTERVAL,		"gc_interval" },
546 	{ CTL_INT,	NET_IPV6_ROUTE_GC_ELASTICITY,		"gc_elasticity" },
547 	{ CTL_INT,	NET_IPV6_ROUTE_MTU_EXPIRES,		"mtu_expires" },
548 	{ CTL_INT,	NET_IPV6_ROUTE_MIN_ADVMSS,		"min_adv_mss" },
549 	{ CTL_INT,	NET_IPV6_ROUTE_GC_MIN_INTERVAL_MS,	"gc_min_interval_ms" },
550 	{}
551 };
552 
553 static const struct bin_table bin_net_ipv6_icmp_table[] = {
554 	{ CTL_INT,	NET_IPV6_ICMP_RATELIMIT,	"ratelimit" },
555 	{}
556 };
557 
558 static const struct bin_table bin_net_ipv6_table[] = {
559 	{ CTL_DIR,	NET_IPV6_CONF,		"conf",		bin_net_ipv6_conf_table },
560 	{ CTL_DIR,	NET_IPV6_NEIGH,		"neigh",	bin_net_neigh_table },
561 	{ CTL_DIR,	NET_IPV6_ROUTE,		"route",	bin_net_ipv6_route_table },
562 	{ CTL_DIR,	NET_IPV6_ICMP,		"icmp",		bin_net_ipv6_icmp_table },
563 	{ CTL_INT,	NET_IPV6_BINDV6ONLY,		"bindv6only" },
564 	{ CTL_INT,	NET_IPV6_IP6FRAG_HIGH_THRESH,	"ip6frag_high_thresh" },
565 	{ CTL_INT,	NET_IPV6_IP6FRAG_LOW_THRESH,	"ip6frag_low_thresh" },
566 	{ CTL_INT,	NET_IPV6_IP6FRAG_TIME,		"ip6frag_time" },
567 	{ CTL_INT,	NET_IPV6_IP6FRAG_SECRET_INTERVAL,	"ip6frag_secret_interval" },
568 	{ CTL_INT,	NET_IPV6_MLD_MAX_MSF,		"mld_max_msf" },
569 	{ CTL_INT,	2088 /* IPQ_QMAX */,		"ip6_queue_maxlen" },
570 	{}
571 };
572 
573 static const struct bin_table bin_net_x25_table[] = {
574 	{ CTL_INT,	NET_X25_RESTART_REQUEST_TIMEOUT,	"restart_request_timeout" },
575 	{ CTL_INT,	NET_X25_CALL_REQUEST_TIMEOUT,		"call_request_timeout" },
576 	{ CTL_INT,	NET_X25_RESET_REQUEST_TIMEOUT,	"reset_request_timeout" },
577 	{ CTL_INT,	NET_X25_CLEAR_REQUEST_TIMEOUT,	"clear_request_timeout" },
578 	{ CTL_INT,	NET_X25_ACK_HOLD_BACK_TIMEOUT,	"acknowledgement_hold_back_timeout" },
579 	{ CTL_INT,	NET_X25_FORWARD,			"x25_forward" },
580 	{}
581 };
582 
583 static const struct bin_table bin_net_tr_table[] = {
584 	{ CTL_INT,	NET_TR_RIF_TIMEOUT,	"rif_timeout" },
585 	{}
586 };
587 
588 
589 static const struct bin_table bin_net_decnet_conf_vars[] = {
590 	{ CTL_INT,	NET_DECNET_CONF_DEV_FORWARDING,	"forwarding" },
591 	{ CTL_INT,	NET_DECNET_CONF_DEV_PRIORITY,	"priority" },
592 	{ CTL_INT,	NET_DECNET_CONF_DEV_T2,		"t2" },
593 	{ CTL_INT,	NET_DECNET_CONF_DEV_T3,		"t3" },
594 	{}
595 };
596 
597 static const struct bin_table bin_net_decnet_conf[] = {
598 	{ CTL_DIR, NET_DECNET_CONF_ETHER,    "ethernet", bin_net_decnet_conf_vars },
599 	{ CTL_DIR, NET_DECNET_CONF_GRE,	     "ipgre",    bin_net_decnet_conf_vars },
600 	{ CTL_DIR, NET_DECNET_CONF_X25,	     "x25",      bin_net_decnet_conf_vars },
601 	{ CTL_DIR, NET_DECNET_CONF_PPP,	     "ppp",      bin_net_decnet_conf_vars },
602 	{ CTL_DIR, NET_DECNET_CONF_DDCMP,    "ddcmp",    bin_net_decnet_conf_vars },
603 	{ CTL_DIR, NET_DECNET_CONF_LOOPBACK, "loopback", bin_net_decnet_conf_vars },
604 	{ CTL_DIR, 0,			     NULL,	 bin_net_decnet_conf_vars },
605 	{}
606 };
607 
608 static const struct bin_table bin_net_decnet_table[] = {
609 	{ CTL_DIR,	NET_DECNET_CONF,		"conf",	bin_net_decnet_conf },
610 	{ CTL_DNADR,	NET_DECNET_NODE_ADDRESS,	"node_address" },
611 	{ CTL_STR,	NET_DECNET_NODE_NAME,		"node_name" },
612 	{ CTL_STR,	NET_DECNET_DEFAULT_DEVICE,	"default_device" },
613 	{ CTL_INT,	NET_DECNET_TIME_WAIT,		"time_wait" },
614 	{ CTL_INT,	NET_DECNET_DN_COUNT,		"dn_count" },
615 	{ CTL_INT,	NET_DECNET_DI_COUNT,		"di_count" },
616 	{ CTL_INT,	NET_DECNET_DR_COUNT,		"dr_count" },
617 	{ CTL_INT,	NET_DECNET_DST_GC_INTERVAL,	"dst_gc_interval" },
618 	{ CTL_INT,	NET_DECNET_NO_FC_MAX_CWND,	"no_fc_max_cwnd" },
619 	{ CTL_INT,	NET_DECNET_MEM,		"decnet_mem" },
620 	{ CTL_INT,	NET_DECNET_RMEM,		"decnet_rmem" },
621 	{ CTL_INT,	NET_DECNET_WMEM,		"decnet_wmem" },
622 	{ CTL_INT,	NET_DECNET_DEBUG_LEVEL,	"debug" },
623 	{}
624 };
625 
626 static const struct bin_table bin_net_sctp_table[] = {
627 	{ CTL_INT,	NET_SCTP_RTO_INITIAL,		"rto_initial" },
628 	{ CTL_INT,	NET_SCTP_RTO_MIN,		"rto_min" },
629 	{ CTL_INT,	NET_SCTP_RTO_MAX,		"rto_max" },
630 	{ CTL_INT,	NET_SCTP_RTO_ALPHA,		"rto_alpha_exp_divisor" },
631 	{ CTL_INT,	NET_SCTP_RTO_BETA,		"rto_beta_exp_divisor" },
632 	{ CTL_INT,	NET_SCTP_VALID_COOKIE_LIFE,	"valid_cookie_life" },
633 	{ CTL_INT,	NET_SCTP_ASSOCIATION_MAX_RETRANS,	"association_max_retrans" },
634 	{ CTL_INT,	NET_SCTP_PATH_MAX_RETRANS,	"path_max_retrans" },
635 	{ CTL_INT,	NET_SCTP_MAX_INIT_RETRANSMITS,	"max_init_retransmits" },
636 	{ CTL_INT,	NET_SCTP_HB_INTERVAL,		"hb_interval" },
637 	{ CTL_INT,	NET_SCTP_PRESERVE_ENABLE,	"cookie_preserve_enable" },
638 	{ CTL_INT,	NET_SCTP_MAX_BURST,		"max_burst" },
639 	{ CTL_INT,	NET_SCTP_ADDIP_ENABLE,		"addip_enable" },
640 	{ CTL_INT,	NET_SCTP_PRSCTP_ENABLE,		"prsctp_enable" },
641 	{ CTL_INT,	NET_SCTP_SNDBUF_POLICY,		"sndbuf_policy" },
642 	{ CTL_INT,	NET_SCTP_SACK_TIMEOUT,		"sack_timeout" },
643 	{ CTL_INT,	NET_SCTP_RCVBUF_POLICY,		"rcvbuf_policy" },
644 	{}
645 };
646 
647 static const struct bin_table bin_net_llc_llc2_timeout_table[] = {
648 	{ CTL_INT,	NET_LLC2_ACK_TIMEOUT,	"ack" },
649 	{ CTL_INT,	NET_LLC2_P_TIMEOUT,	"p" },
650 	{ CTL_INT,	NET_LLC2_REJ_TIMEOUT,	"rej" },
651 	{ CTL_INT,	NET_LLC2_BUSY_TIMEOUT,	"busy" },
652 	{}
653 };
654 
655 static const struct bin_table bin_net_llc_station_table[] = {
656 	{ CTL_INT,	NET_LLC_STATION_ACK_TIMEOUT,	"ack_timeout" },
657 	{}
658 };
659 
660 static const struct bin_table bin_net_llc_llc2_table[] = {
661 	{ CTL_DIR,	NET_LLC2,		"timeout",	bin_net_llc_llc2_timeout_table },
662 	{}
663 };
664 
665 static const struct bin_table bin_net_llc_table[] = {
666 	{ CTL_DIR,	NET_LLC2,		"llc2",		bin_net_llc_llc2_table },
667 	{ CTL_DIR,	NET_LLC_STATION,	"station",	bin_net_llc_station_table },
668 	{}
669 };
670 
671 static const struct bin_table bin_net_netfilter_table[] = {
672 	{ CTL_INT,	NET_NF_CONNTRACK_MAX,			"nf_conntrack_max" },
673 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT "nf_conntrack_tcp_timeout_syn_sent" no longer used */
674 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV "nf_conntrack_tcp_timeout_syn_recv" no longer used */
675 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED "nf_conntrack_tcp_timeout_established" no longer used */
676 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT "nf_conntrack_tcp_timeout_fin_wait" no longer used */
677 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT "nf_conntrack_tcp_timeout_close_wait" no longer used */
678 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK "nf_conntrack_tcp_timeout_last_ack" no longer used */
679 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT "nf_conntrack_tcp_timeout_time_wait" no longer used */
680 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_CLOSE "nf_conntrack_tcp_timeout_close" no longer used */
681 	/* NET_NF_CONNTRACK_UDP_TIMEOUT	"nf_conntrack_udp_timeout" no longer used */
682 	/* NET_NF_CONNTRACK_UDP_TIMEOUT_STREAM "nf_conntrack_udp_timeout_stream" no longer used */
683 	/* NET_NF_CONNTRACK_ICMP_TIMEOUT "nf_conntrack_icmp_timeout" no longer used */
684 	/* NET_NF_CONNTRACK_GENERIC_TIMEOUT "nf_conntrack_generic_timeout" no longer used */
685 	{ CTL_INT,	NET_NF_CONNTRACK_BUCKETS,		"nf_conntrack_buckets" },
686 	{ CTL_INT,	NET_NF_CONNTRACK_LOG_INVALID,		"nf_conntrack_log_invalid" },
687 	/* NET_NF_CONNTRACK_TCP_TIMEOUT_MAX_RETRANS "nf_conntrack_tcp_timeout_max_retrans" no longer used */
688 	{ CTL_INT,	NET_NF_CONNTRACK_TCP_LOOSE,		"nf_conntrack_tcp_loose" },
689 	{ CTL_INT,	NET_NF_CONNTRACK_TCP_BE_LIBERAL,	"nf_conntrack_tcp_be_liberal" },
690 	{ CTL_INT,	NET_NF_CONNTRACK_TCP_MAX_RETRANS,	"nf_conntrack_tcp_max_retrans" },
691 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_CLOSED "nf_conntrack_sctp_timeout_closed" no longer used */
692 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_COOKIE_WAIT "nf_conntrack_sctp_timeout_cookie_wait" no longer used */
693 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_COOKIE_ECHOED "nf_conntrack_sctp_timeout_cookie_echoed" no longer used */
694 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_ESTABLISHED "nf_conntrack_sctp_timeout_established" no longer used */
695 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_SENT "nf_conntrack_sctp_timeout_shutdown_sent" no longer used */
696 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_RECD "nf_conntrack_sctp_timeout_shutdown_recd" no longer used */
697 	/* NET_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_ACK_SENT "nf_conntrack_sctp_timeout_shutdown_ack_sent" no longer used */
698 	{ CTL_INT,	NET_NF_CONNTRACK_COUNT,			"nf_conntrack_count" },
699 	/* NET_NF_CONNTRACK_ICMPV6_TIMEOUT "nf_conntrack_icmpv6_timeout" no longer used */
700 	/* NET_NF_CONNTRACK_FRAG6_TIMEOUT "nf_conntrack_frag6_timeout" no longer used */
701 	{ CTL_INT,	NET_NF_CONNTRACK_FRAG6_LOW_THRESH,	"nf_conntrack_frag6_low_thresh" },
702 	{ CTL_INT,	NET_NF_CONNTRACK_FRAG6_HIGH_THRESH,	"nf_conntrack_frag6_high_thresh" },
703 	{ CTL_INT,	NET_NF_CONNTRACK_CHECKSUM,		"nf_conntrack_checksum" },
704 
705 	{}
706 };
707 
708 static const struct bin_table bin_net_table[] = {
709 	{ CTL_DIR,	NET_CORE,		"core",		bin_net_core_table },
710 	/* NET_ETHER not used */
711 	/* NET_802 not used */
712 	{ CTL_DIR,	NET_UNIX,		"unix",		bin_net_unix_table },
713 	{ CTL_DIR,	NET_IPV4,		"ipv4",		bin_net_ipv4_table },
714 	{ CTL_DIR,	NET_IPX,		"ipx",		bin_net_ipx_table },
715 	{ CTL_DIR,	NET_ATALK,		"appletalk",	bin_net_atalk_table },
716 	{ CTL_DIR,	NET_NETROM,		"netrom",	bin_net_netrom_table },
717 	{ CTL_DIR,	NET_AX25,		"ax25",		bin_net_ax25_table },
718 	/*  NET_BRIDGE "bridge" no longer used */
719 	{ CTL_DIR,	NET_ROSE,		"rose",		bin_net_rose_table },
720 	{ CTL_DIR,	NET_IPV6,		"ipv6",		bin_net_ipv6_table },
721 	{ CTL_DIR,	NET_X25,		"x25",		bin_net_x25_table },
722 	{ CTL_DIR,	NET_TR,			"token-ring",	bin_net_tr_table },
723 	{ CTL_DIR,	NET_DECNET,		"decnet",	bin_net_decnet_table },
724 	/*  NET_ECONET not used */
725 	{ CTL_DIR,	NET_SCTP,		"sctp",		bin_net_sctp_table },
726 	{ CTL_DIR,	NET_LLC,		"llc",		bin_net_llc_table },
727 	{ CTL_DIR,	NET_NETFILTER,		"netfilter",	bin_net_netfilter_table },
728 	/* NET_DCCP "dccp" no longer used */
729 	/* NET_IRDA "irda" no longer used */
730 	{ CTL_INT,	2089,			"nf_conntrack_max" },
731 	{}
732 };
733 
734 static const struct bin_table bin_fs_quota_table[] = {
735 	{ CTL_INT,	FS_DQ_LOOKUPS,		"lookups" },
736 	{ CTL_INT,	FS_DQ_DROPS,		"drops" },
737 	{ CTL_INT,	FS_DQ_READS,		"reads" },
738 	{ CTL_INT,	FS_DQ_WRITES,		"writes" },
739 	{ CTL_INT,	FS_DQ_CACHE_HITS,	"cache_hits" },
740 	{ CTL_INT,	FS_DQ_ALLOCATED,	"allocated_dquots" },
741 	{ CTL_INT,	FS_DQ_FREE,		"free_dquots" },
742 	{ CTL_INT,	FS_DQ_SYNCS,		"syncs" },
743 	{ CTL_INT,	FS_DQ_WARNINGS,		"warnings" },
744 	{}
745 };
746 
747 static const struct bin_table bin_fs_xfs_table[] = {
748 	{ CTL_INT,	XFS_SGID_INHERIT,	"irix_sgid_inherit" },
749 	{ CTL_INT,	XFS_SYMLINK_MODE,	"irix_symlink_mode" },
750 	{ CTL_INT,	XFS_PANIC_MASK,		"panic_mask" },
751 
752 	{ CTL_INT,	XFS_ERRLEVEL,		"error_level" },
753 	{ CTL_INT,	XFS_SYNCD_TIMER,	"xfssyncd_centisecs" },
754 	{ CTL_INT,	XFS_INHERIT_SYNC,	"inherit_sync" },
755 	{ CTL_INT,	XFS_INHERIT_NODUMP,	"inherit_nodump" },
756 	{ CTL_INT,	XFS_INHERIT_NOATIME,	"inherit_noatime" },
757 	{ CTL_INT,	XFS_BUF_TIMER,		"xfsbufd_centisecs" },
758 	{ CTL_INT,	XFS_BUF_AGE,		"age_buffer_centisecs" },
759 	{ CTL_INT,	XFS_INHERIT_NOSYM,	"inherit_nosymlinks" },
760 	{ CTL_INT,	XFS_ROTORSTEP,	"rotorstep" },
761 	{ CTL_INT,	XFS_INHERIT_NODFRG,	"inherit_nodefrag" },
762 	{ CTL_INT,	XFS_FILESTREAM_TIMER,	"filestream_centisecs" },
763 	{ CTL_INT,	XFS_STATS_CLEAR,	"stats_clear" },
764 	{}
765 };
766 
767 static const struct bin_table bin_fs_ocfs2_nm_table[] = {
768 	{ CTL_STR,	1, "hb_ctl_path" },
769 	{}
770 };
771 
772 static const struct bin_table bin_fs_ocfs2_table[] = {
773 	{ CTL_DIR,	1,	"nm",	bin_fs_ocfs2_nm_table },
774 	{}
775 };
776 
777 static const struct bin_table bin_inotify_table[] = {
778 	{ CTL_INT,	INOTIFY_MAX_USER_INSTANCES,	"max_user_instances" },
779 	{ CTL_INT,	INOTIFY_MAX_USER_WATCHES,	"max_user_watches" },
780 	{ CTL_INT,	INOTIFY_MAX_QUEUED_EVENTS,	"max_queued_events" },
781 	{}
782 };
783 
784 static const struct bin_table bin_fs_table[] = {
785 	{ CTL_INT,	FS_NRINODE,		"inode-nr" },
786 	{ CTL_INT,	FS_STATINODE,		"inode-state" },
787 	/* FS_MAXINODE unused */
788 	/* FS_NRDQUOT unused */
789 	/* FS_MAXDQUOT unused */
790 	/* FS_NRFILE "file-nr" no longer used */
791 	{ CTL_INT,	FS_MAXFILE,		"file-max" },
792 	{ CTL_INT,	FS_DENTRY,		"dentry-state" },
793 	/* FS_NRSUPER unused */
794 	/* FS_MAXUPSER unused */
795 	{ CTL_INT,	FS_OVERFLOWUID,		"overflowuid" },
796 	{ CTL_INT,	FS_OVERFLOWGID,		"overflowgid" },
797 	{ CTL_INT,	FS_LEASES,		"leases-enable" },
798 	{ CTL_INT,	FS_DIR_NOTIFY,		"dir-notify-enable" },
799 	{ CTL_INT,	FS_LEASE_TIME,		"lease-break-time" },
800 	{ CTL_DIR,	FS_DQSTATS,		"quota",	bin_fs_quota_table },
801 	{ CTL_DIR,	FS_XFS,			"xfs",		bin_fs_xfs_table },
802 	{ CTL_ULONG,	FS_AIO_NR,		"aio-nr" },
803 	{ CTL_ULONG,	FS_AIO_MAX_NR,		"aio-max-nr" },
804 	{ CTL_DIR,	FS_INOTIFY,		"inotify",	bin_inotify_table },
805 	{ CTL_DIR,	FS_OCFS2,		"ocfs2",	bin_fs_ocfs2_table },
806 	{ CTL_INT,	KERN_SETUID_DUMPABLE,	"suid_dumpable" },
807 	{}
808 };
809 
810 static const struct bin_table bin_ipmi_table[] = {
811 	{ CTL_INT,	DEV_IPMI_POWEROFF_POWERCYCLE,	"poweroff_powercycle" },
812 	{}
813 };
814 
815 static const struct bin_table bin_mac_hid_files[] = {
816 	/* DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES unused */
817 	/* DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES unused */
818 	{ CTL_INT,	DEV_MAC_HID_MOUSE_BUTTON_EMULATION,	"mouse_button_emulation" },
819 	{ CTL_INT,	DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE,	"mouse_button2_keycode" },
820 	{ CTL_INT,	DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE,	"mouse_button3_keycode" },
821 	/* DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES unused */
822 	{}
823 };
824 
825 static const struct bin_table bin_raid_table[] = {
826 	{ CTL_INT,	DEV_RAID_SPEED_LIMIT_MIN,	"speed_limit_min" },
827 	{ CTL_INT,	DEV_RAID_SPEED_LIMIT_MAX,	"speed_limit_max" },
828 	{}
829 };
830 
831 static const struct bin_table bin_scsi_table[] = {
832 	{ CTL_INT, DEV_SCSI_LOGGING_LEVEL, "logging_level" },
833 	{}
834 };
835 
836 static const struct bin_table bin_dev_table[] = {
837 	/* DEV_CDROM	"cdrom" no longer used */
838 	/* DEV_HWMON unused */
839 	/* DEV_PARPORT	"parport" no longer used */
840 	{ CTL_DIR,	DEV_RAID,	"raid",		bin_raid_table },
841 	{ CTL_DIR,	DEV_MAC_HID,	"mac_hid",	bin_mac_hid_files },
842 	{ CTL_DIR,	DEV_SCSI,	"scsi",		bin_scsi_table },
843 	{ CTL_DIR,	DEV_IPMI,	"ipmi",		bin_ipmi_table },
844 	{}
845 };
846 
847 static const struct bin_table bin_bus_isa_table[] = {
848 	{ CTL_INT,	BUS_ISA_MEM_BASE,	"membase" },
849 	{ CTL_INT,	BUS_ISA_PORT_BASE,	"portbase" },
850 	{ CTL_INT,	BUS_ISA_PORT_SHIFT,	"portshift" },
851 	{}
852 };
853 
854 static const struct bin_table bin_bus_table[] = {
855 	{ CTL_DIR,	CTL_BUS_ISA,	"isa",	bin_bus_isa_table },
856 	{}
857 };
858 
859 
860 static const struct bin_table bin_s390dbf_table[] = {
861 	{ CTL_INT,	5678 /* CTL_S390DBF_STOPPABLE */, "debug_stoppable" },
862 	{ CTL_INT,	5679 /* CTL_S390DBF_ACTIVE */,	  "debug_active" },
863 	{}
864 };
865 
866 static const struct bin_table bin_sunrpc_table[] = {
867 	/* CTL_RPCDEBUG	"rpc_debug"  no longer used */
868 	/* CTL_NFSDEBUG "nfs_debug"  no longer used */
869 	/* CTL_NFSDDEBUG "nfsd_debug" no longer used  */
870 	/* CTL_NLMDEBUG "nlm_debug" no longer used */
871 
872 	{ CTL_INT,	CTL_SLOTTABLE_UDP,	"udp_slot_table_entries" },
873 	{ CTL_INT,	CTL_SLOTTABLE_TCP,	"tcp_slot_table_entries" },
874 	{ CTL_INT,	CTL_MIN_RESVPORT,	"min_resvport" },
875 	{ CTL_INT,	CTL_MAX_RESVPORT,	"max_resvport" },
876 	{}
877 };
878 
879 static const struct bin_table bin_pm_table[] = {
880 	/* frv specific */
881 	/* 1 == CTL_PM_SUSPEND	"suspend"  no longer used" */
882 	{ CTL_INT,	2 /* CTL_PM_CMODE */,		"cmode" },
883 	{ CTL_INT,	3 /* CTL_PM_P0 */,		"p0" },
884 	{ CTL_INT,	4 /* CTL_PM_CM */,		"cm" },
885 	{}
886 };
887 
888 static const struct bin_table bin_root_table[] = {
889 	{ CTL_DIR,	CTL_KERN,	"kernel",	bin_kern_table },
890 	{ CTL_DIR,	CTL_VM,		"vm",		bin_vm_table },
891 	{ CTL_DIR,	CTL_NET,	"net",		bin_net_table },
892 	/* CTL_PROC not used */
893 	{ CTL_DIR,	CTL_FS,		"fs",		bin_fs_table },
894 	/* CTL_DEBUG "debug" no longer used */
895 	{ CTL_DIR,	CTL_DEV,	"dev",		bin_dev_table },
896 	{ CTL_DIR,	CTL_BUS,	"bus",		bin_bus_table },
897 	{ CTL_DIR,	CTL_ABI,	"abi" },
898 	/* CTL_CPU not used */
899 	/* CTL_ARLAN "arlan" no longer used */
900 	{ CTL_DIR,	CTL_S390DBF,	"s390dbf",	bin_s390dbf_table },
901 	{ CTL_DIR,	CTL_SUNRPC,	"sunrpc",	bin_sunrpc_table },
902 	{ CTL_DIR,	CTL_PM,		"pm",		bin_pm_table },
903 	{}
904 };
905 
bin_dir(struct file * file,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)906 static ssize_t bin_dir(struct file *file,
907 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
908 {
909 	return -ENOTDIR;
910 }
911 
912 
bin_string(struct file * file,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)913 static ssize_t bin_string(struct file *file,
914 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
915 {
916 	ssize_t result, copied = 0;
917 
918 	if (oldval && oldlen) {
919 		char __user *lastp;
920 		loff_t pos = 0;
921 		int ch;
922 
923 		result = vfs_read(file, oldval, oldlen, &pos);
924 		if (result < 0)
925 			goto out;
926 
927 		copied = result;
928 		lastp = oldval + copied - 1;
929 
930 		result = -EFAULT;
931 		if (get_user(ch, lastp))
932 			goto out;
933 
934 		/* Trim off the trailing newline */
935 		if (ch == '\n') {
936 			result = -EFAULT;
937 			if (put_user('\0', lastp))
938 				goto out;
939 			copied -= 1;
940 		}
941 	}
942 
943 	if (newval && newlen) {
944 		loff_t pos = 0;
945 
946 		result = vfs_write(file, newval, newlen, &pos);
947 		if (result < 0)
948 			goto out;
949 	}
950 
951 	result = copied;
952 out:
953 	return result;
954 }
955 
bin_intvec(struct file * file,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)956 static ssize_t bin_intvec(struct file *file,
957 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
958 {
959 	ssize_t copied = 0;
960 	char *buffer;
961 	ssize_t result;
962 
963 	result = -ENOMEM;
964 	buffer = kmalloc(BUFSZ, GFP_KERNEL);
965 	if (!buffer)
966 		goto out;
967 
968 	if (oldval && oldlen) {
969 		unsigned __user *vec = oldval;
970 		size_t length = oldlen / sizeof(*vec);
971 		char *str, *end;
972 		int i;
973 		loff_t pos = 0;
974 
975 		result = kernel_read(file, buffer, BUFSZ - 1, &pos);
976 		if (result < 0)
977 			goto out_kfree;
978 
979 		str = buffer;
980 		end = str + result;
981 		*end++ = '\0';
982 		for (i = 0; i < length; i++) {
983 			unsigned long value;
984 
985 			value = simple_strtoul(str, &str, 10);
986 			while (isspace(*str))
987 				str++;
988 
989 			result = -EFAULT;
990 			if (put_user(value, vec + i))
991 				goto out_kfree;
992 
993 			copied += sizeof(*vec);
994 			if (!isdigit(*str))
995 				break;
996 		}
997 	}
998 
999 	if (newval && newlen) {
1000 		unsigned __user *vec = newval;
1001 		size_t length = newlen / sizeof(*vec);
1002 		char *str, *end;
1003 		int i;
1004 		loff_t pos = 0;
1005 
1006 		str = buffer;
1007 		end = str + BUFSZ;
1008 		for (i = 0; i < length; i++) {
1009 			unsigned long value;
1010 
1011 			result = -EFAULT;
1012 			if (get_user(value, vec + i))
1013 				goto out_kfree;
1014 
1015 			str += scnprintf(str, end - str, "%lu\t", value);
1016 		}
1017 
1018 		result = kernel_write(file, buffer, str - buffer, &pos);
1019 		if (result < 0)
1020 			goto out_kfree;
1021 	}
1022 	result = copied;
1023 out_kfree:
1024 	kfree(buffer);
1025 out:
1026 	return result;
1027 }
1028 
bin_ulongvec(struct file * file,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)1029 static ssize_t bin_ulongvec(struct file *file,
1030 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
1031 {
1032 	ssize_t copied = 0;
1033 	char *buffer;
1034 	ssize_t result;
1035 
1036 	result = -ENOMEM;
1037 	buffer = kmalloc(BUFSZ, GFP_KERNEL);
1038 	if (!buffer)
1039 		goto out;
1040 
1041 	if (oldval && oldlen) {
1042 		unsigned long __user *vec = oldval;
1043 		size_t length = oldlen / sizeof(*vec);
1044 		char *str, *end;
1045 		int i;
1046 		loff_t pos = 0;
1047 
1048 		result = kernel_read(file, buffer, BUFSZ - 1, &pos);
1049 		if (result < 0)
1050 			goto out_kfree;
1051 
1052 		str = buffer;
1053 		end = str + result;
1054 		*end++ = '\0';
1055 		for (i = 0; i < length; i++) {
1056 			unsigned long value;
1057 
1058 			value = simple_strtoul(str, &str, 10);
1059 			while (isspace(*str))
1060 				str++;
1061 
1062 			result = -EFAULT;
1063 			if (put_user(value, vec + i))
1064 				goto out_kfree;
1065 
1066 			copied += sizeof(*vec);
1067 			if (!isdigit(*str))
1068 				break;
1069 		}
1070 	}
1071 
1072 	if (newval && newlen) {
1073 		unsigned long __user *vec = newval;
1074 		size_t length = newlen / sizeof(*vec);
1075 		char *str, *end;
1076 		int i;
1077 		loff_t pos = 0;
1078 
1079 		str = buffer;
1080 		end = str + BUFSZ;
1081 		for (i = 0; i < length; i++) {
1082 			unsigned long value;
1083 
1084 			result = -EFAULT;
1085 			if (get_user(value, vec + i))
1086 				goto out_kfree;
1087 
1088 			str += scnprintf(str, end - str, "%lu\t", value);
1089 		}
1090 
1091 		result = kernel_write(file, buffer, str - buffer, &pos);
1092 		if (result < 0)
1093 			goto out_kfree;
1094 	}
1095 	result = copied;
1096 out_kfree:
1097 	kfree(buffer);
1098 out:
1099 	return result;
1100 }
1101 
bin_uuid(struct file * file,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)1102 static ssize_t bin_uuid(struct file *file,
1103 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
1104 {
1105 	ssize_t result, copied = 0;
1106 
1107 	/* Only supports reads */
1108 	if (oldval && oldlen) {
1109 		char buf[UUID_STRING_LEN + 1];
1110 		uuid_t uuid;
1111 		loff_t pos = 0;
1112 
1113 		result = kernel_read(file, buf, sizeof(buf) - 1, &pos);
1114 		if (result < 0)
1115 			goto out;
1116 
1117 		buf[result] = '\0';
1118 
1119 		result = -EIO;
1120 		if (uuid_parse(buf, &uuid))
1121 			goto out;
1122 
1123 		if (oldlen > 16)
1124 			oldlen = 16;
1125 
1126 		result = -EFAULT;
1127 		if (copy_to_user(oldval, &uuid, oldlen))
1128 			goto out;
1129 
1130 		copied = oldlen;
1131 	}
1132 	result = copied;
1133 out:
1134 	return result;
1135 }
1136 
bin_dn_node_address(struct file * file,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)1137 static ssize_t bin_dn_node_address(struct file *file,
1138 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
1139 {
1140 	ssize_t result, copied = 0;
1141 
1142 	if (oldval && oldlen) {
1143 		char buf[15], *nodep;
1144 		unsigned long area, node;
1145 		__le16 dnaddr;
1146 		loff_t pos = 0;
1147 
1148 		result = kernel_read(file, buf, sizeof(buf) - 1, &pos);
1149 		if (result < 0)
1150 			goto out;
1151 
1152 		buf[result] = '\0';
1153 
1154 		/* Convert the decnet address to binary */
1155 		result = -EIO;
1156 		nodep = strchr(buf, '.');
1157 		if (!nodep)
1158 			goto out;
1159 		++nodep;
1160 
1161 		area = simple_strtoul(buf, NULL, 10);
1162 		node = simple_strtoul(nodep, NULL, 10);
1163 
1164 		result = -EIO;
1165 		if ((area > 63)||(node > 1023))
1166 			goto out;
1167 
1168 		dnaddr = cpu_to_le16((area << 10) | node);
1169 
1170 		result = -EFAULT;
1171 		if (put_user(dnaddr, (__le16 __user *)oldval))
1172 			goto out;
1173 
1174 		copied = sizeof(dnaddr);
1175 	}
1176 
1177 	if (newval && newlen) {
1178 		__le16 dnaddr;
1179 		char buf[15];
1180 		int len;
1181 		loff_t pos = 0;
1182 
1183 		result = -EINVAL;
1184 		if (newlen != sizeof(dnaddr))
1185 			goto out;
1186 
1187 		result = -EFAULT;
1188 		if (get_user(dnaddr, (__le16 __user *)newval))
1189 			goto out;
1190 
1191 		len = scnprintf(buf, sizeof(buf), "%hu.%hu",
1192 				le16_to_cpu(dnaddr) >> 10,
1193 				le16_to_cpu(dnaddr) & 0x3ff);
1194 
1195 		result = kernel_write(file, buf, len, &pos);
1196 		if (result < 0)
1197 			goto out;
1198 	}
1199 
1200 	result = copied;
1201 out:
1202 	return result;
1203 }
1204 
get_sysctl(const int * name,int nlen,char * path)1205 static const struct bin_table *get_sysctl(const int *name, int nlen, char *path)
1206 {
1207 	const struct bin_table *table = &bin_root_table[0];
1208 	int ctl_name;
1209 
1210 	/* The binary sysctl tables have a small maximum depth so
1211 	 * there is no danger of overflowing our path as it PATH_MAX
1212 	 * bytes long.
1213 	 */
1214 	memcpy(path, "sys/", 4);
1215 	path += 4;
1216 
1217 repeat:
1218 	if (!nlen)
1219 		return ERR_PTR(-ENOTDIR);
1220 	ctl_name = *name;
1221 	name++;
1222 	nlen--;
1223 	for ( ; table->convert; table++) {
1224 		int len = 0;
1225 
1226 		/*
1227 		 * For a wild card entry map from ifindex to network
1228 		 * device name.
1229 		 */
1230 		if (!table->ctl_name) {
1231 #ifdef CONFIG_NET
1232 			struct net *net = current->nsproxy->net_ns;
1233 			struct net_device *dev;
1234 			dev = dev_get_by_index(net, ctl_name);
1235 			if (dev) {
1236 				len = strlen(dev->name);
1237 				memcpy(path, dev->name, len);
1238 				dev_put(dev);
1239 			}
1240 #endif
1241 		/* Use the well known sysctl number to proc name mapping */
1242 		} else if (ctl_name == table->ctl_name) {
1243 			len = strlen(table->procname);
1244 			memcpy(path, table->procname, len);
1245 		}
1246 		if (len) {
1247 			path += len;
1248 			if (table->child) {
1249 				*path++ = '/';
1250 				table = table->child;
1251 				goto repeat;
1252 			}
1253 			*path = '\0';
1254 			return table;
1255 		}
1256 	}
1257 	return ERR_PTR(-ENOTDIR);
1258 }
1259 
sysctl_getname(const int * name,int nlen,const struct bin_table ** tablep)1260 static char *sysctl_getname(const int *name, int nlen, const struct bin_table **tablep)
1261 {
1262 	char *tmp, *result;
1263 
1264 	result = ERR_PTR(-ENOMEM);
1265 	tmp = __getname();
1266 	if (tmp) {
1267 		const struct bin_table *table = get_sysctl(name, nlen, tmp);
1268 		result = tmp;
1269 		*tablep = table;
1270 		if (IS_ERR(table)) {
1271 			__putname(tmp);
1272 			result = ERR_CAST(table);
1273 		}
1274 	}
1275 	return result;
1276 }
1277 
binary_sysctl(const int * name,int nlen,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)1278 static ssize_t binary_sysctl(const int *name, int nlen,
1279 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
1280 {
1281 	const struct bin_table *table = NULL;
1282 	struct vfsmount *mnt;
1283 	struct file *file;
1284 	ssize_t result;
1285 	char *pathname;
1286 	int flags;
1287 
1288 	pathname = sysctl_getname(name, nlen, &table);
1289 	result = PTR_ERR(pathname);
1290 	if (IS_ERR(pathname))
1291 		goto out;
1292 
1293 	/* How should the sysctl be accessed? */
1294 	if (oldval && oldlen && newval && newlen) {
1295 		flags = O_RDWR;
1296 	} else if (newval && newlen) {
1297 		flags = O_WRONLY;
1298 	} else if (oldval && oldlen) {
1299 		flags = O_RDONLY;
1300 	} else {
1301 		result = 0;
1302 		goto out_putname;
1303 	}
1304 
1305 	mnt = task_active_pid_ns(current)->proc_mnt;
1306 	file = file_open_root(mnt->mnt_root, mnt, pathname, flags, 0);
1307 	result = PTR_ERR(file);
1308 	if (IS_ERR(file))
1309 		goto out_putname;
1310 
1311 	result = table->convert(file, oldval, oldlen, newval, newlen);
1312 
1313 	fput(file);
1314 out_putname:
1315 	__putname(pathname);
1316 out:
1317 	return result;
1318 }
1319 
1320 
1321 #else /* CONFIG_SYSCTL_SYSCALL */
1322 
binary_sysctl(const int * name,int nlen,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)1323 static ssize_t binary_sysctl(const int *name, int nlen,
1324 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
1325 {
1326 	return -ENOSYS;
1327 }
1328 
1329 #endif /* CONFIG_SYSCTL_SYSCALL */
1330 
1331 
deprecated_sysctl_warning(const int * name,int nlen)1332 static void deprecated_sysctl_warning(const int *name, int nlen)
1333 {
1334 	int i;
1335 
1336 	/*
1337 	 * CTL_KERN/KERN_VERSION is used by older glibc and cannot
1338 	 * ever go away.
1339 	 */
1340 	if (nlen >= 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION)
1341 		return;
1342 
1343 	if (printk_ratelimit()) {
1344 		printk(KERN_INFO
1345 			"warning: process `%s' used the deprecated sysctl "
1346 			"system call with ", current->comm);
1347 		for (i = 0; i < nlen; i++)
1348 			printk(KERN_CONT "%d.", name[i]);
1349 		printk(KERN_CONT "\n");
1350 	}
1351 	return;
1352 }
1353 
1354 #define WARN_ONCE_HASH_BITS 8
1355 #define WARN_ONCE_HASH_SIZE (1<<WARN_ONCE_HASH_BITS)
1356 
1357 static DECLARE_BITMAP(warn_once_bitmap, WARN_ONCE_HASH_SIZE);
1358 
1359 #define FNV32_OFFSET 2166136261U
1360 #define FNV32_PRIME 0x01000193
1361 
1362 /*
1363  * Print each legacy sysctl (approximately) only once.
1364  * To avoid making the tables non-const use a external
1365  * hash-table instead.
1366  * Worst case hash collision: 6, but very rarely.
1367  * NOTE! We don't use the SMP-safe bit tests. We simply
1368  * don't care enough.
1369  */
warn_on_bintable(const int * name,int nlen)1370 static void warn_on_bintable(const int *name, int nlen)
1371 {
1372 	int i;
1373 	u32 hash = FNV32_OFFSET;
1374 
1375 	for (i = 0; i < nlen; i++)
1376 		hash = (hash ^ name[i]) * FNV32_PRIME;
1377 	hash %= WARN_ONCE_HASH_SIZE;
1378 	if (__test_and_set_bit(hash, warn_once_bitmap))
1379 		return;
1380 	deprecated_sysctl_warning(name, nlen);
1381 }
1382 
do_sysctl(int __user * args_name,int nlen,void __user * oldval,size_t oldlen,void __user * newval,size_t newlen)1383 static ssize_t do_sysctl(int __user *args_name, int nlen,
1384 	void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
1385 {
1386 	int name[CTL_MAXNAME];
1387 	int i;
1388 
1389 	/* Check args->nlen. */
1390 	if (nlen < 0 || nlen > CTL_MAXNAME)
1391 		return -ENOTDIR;
1392 	/* Read in the sysctl name for simplicity */
1393 	for (i = 0; i < nlen; i++)
1394 		if (get_user(name[i], args_name + i))
1395 			return -EFAULT;
1396 
1397 	warn_on_bintable(name, nlen);
1398 
1399 	return binary_sysctl(name, nlen, oldval, oldlen, newval, newlen);
1400 }
1401 
SYSCALL_DEFINE1(sysctl,struct __sysctl_args __user *,args)1402 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1403 {
1404 	struct __sysctl_args tmp;
1405 	size_t oldlen = 0;
1406 	ssize_t result;
1407 
1408 	if (copy_from_user(&tmp, args, sizeof(tmp)))
1409 		return -EFAULT;
1410 
1411 	if (tmp.oldval && !tmp.oldlenp)
1412 		return -EFAULT;
1413 
1414 	if (tmp.oldlenp && get_user(oldlen, tmp.oldlenp))
1415 		return -EFAULT;
1416 
1417 	result = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, oldlen,
1418 			   tmp.newval, tmp.newlen);
1419 
1420 	if (result >= 0) {
1421 		oldlen = result;
1422 		result = 0;
1423 	}
1424 
1425 	if (tmp.oldlenp && put_user(oldlen, tmp.oldlenp))
1426 		return -EFAULT;
1427 
1428 	return result;
1429 }
1430 
1431 
1432 #ifdef CONFIG_COMPAT
1433 
1434 struct compat_sysctl_args {
1435 	compat_uptr_t	name;
1436 	int		nlen;
1437 	compat_uptr_t	oldval;
1438 	compat_uptr_t	oldlenp;
1439 	compat_uptr_t	newval;
1440 	compat_size_t	newlen;
1441 	compat_ulong_t	__unused[4];
1442 };
1443 
COMPAT_SYSCALL_DEFINE1(sysctl,struct compat_sysctl_args __user *,args)1444 COMPAT_SYSCALL_DEFINE1(sysctl, struct compat_sysctl_args __user *, args)
1445 {
1446 	struct compat_sysctl_args tmp;
1447 	compat_size_t __user *compat_oldlenp;
1448 	size_t oldlen = 0;
1449 	ssize_t result;
1450 
1451 	if (copy_from_user(&tmp, args, sizeof(tmp)))
1452 		return -EFAULT;
1453 
1454 	if (tmp.oldval && !tmp.oldlenp)
1455 		return -EFAULT;
1456 
1457 	compat_oldlenp = compat_ptr(tmp.oldlenp);
1458 	if (compat_oldlenp && get_user(oldlen, compat_oldlenp))
1459 		return -EFAULT;
1460 
1461 	result = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
1462 			   compat_ptr(tmp.oldval), oldlen,
1463 			   compat_ptr(tmp.newval), tmp.newlen);
1464 
1465 	if (result >= 0) {
1466 		oldlen = result;
1467 		result = 0;
1468 	}
1469 
1470 	if (compat_oldlenp && put_user(oldlen, compat_oldlenp))
1471 		return -EFAULT;
1472 
1473 	return result;
1474 }
1475 
1476 #endif /* CONFIG_COMPAT */
1477