hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/net/core/sysctl_net_core.c
....@@ -22,9 +22,8 @@
2222 #include <net/busy_poll.h>
2323 #include <net/pkt_sched.h>
2424
25
-static int zero = 0;
26
-static int one = 1;
27
-static int two __maybe_unused = 2;
25
+static int two = 2;
26
+static int three = 3;
2827 static int min_sndbuf = SOCK_MIN_SNDBUF;
2928 static int min_rcvbuf = SOCK_MIN_RCVBUF;
3029 static int max_skb_frags = MAX_SKB_FRAGS;
....@@ -36,9 +35,19 @@
3635 int sysctl_fb_tunnels_only_for_init_net __read_mostly = 0;
3736 EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
3837
38
+/* 0 - Keep current behavior:
39
+ * IPv4: inherit all current settings from init_net
40
+ * IPv6: reset all settings to default
41
+ * 1 - Both inherit all current settings from init_net
42
+ * 2 - Both reset all settings to default
43
+ * 3 - Both inherit all settings from current netns
44
+ */
45
+int sysctl_devconf_inherit_init_net __read_mostly;
46
+EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
47
+
3948 #ifdef CONFIG_RPS
4049 static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
41
- void __user *buffer, size_t *lenp, loff_t *ppos)
50
+ void *buffer, size_t *lenp, loff_t *ppos)
4251 {
4352 unsigned int orig_size, size;
4453 int ret, i;
....@@ -86,12 +95,12 @@
8695 if (sock_table != orig_sock_table) {
8796 rcu_assign_pointer(rps_sock_flow_table, sock_table);
8897 if (sock_table) {
89
- static_key_slow_inc(&rps_needed);
90
- static_key_slow_inc(&rfs_needed);
98
+ static_branch_inc(&rps_needed);
99
+ static_branch_inc(&rfs_needed);
91100 }
92101 if (orig_sock_table) {
93
- static_key_slow_dec(&rps_needed);
94
- static_key_slow_dec(&rfs_needed);
102
+ static_branch_dec(&rps_needed);
103
+ static_branch_dec(&rfs_needed);
95104 synchronize_rcu();
96105 vfree(orig_sock_table);
97106 }
....@@ -108,8 +117,7 @@
108117 static DEFINE_MUTEX(flow_limit_update_mutex);
109118
110119 static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
111
- void __user *buffer, size_t *lenp,
112
- loff_t *ppos)
120
+ void *buffer, size_t *lenp, loff_t *ppos)
113121 {
114122 struct sd_flow_limit *cur;
115123 struct softnet_data *sd;
....@@ -120,7 +128,7 @@
120128 return -ENOMEM;
121129
122130 if (write) {
123
- ret = cpumask_parse_user(buffer, *lenp, mask);
131
+ ret = cpumask_parse(buffer, mask);
124132 if (ret)
125133 goto done;
126134
....@@ -173,10 +181,7 @@
173181 }
174182 if (len < *lenp)
175183 kbuf[len++] = '\n';
176
- if (copy_to_user(buffer, kbuf, len)) {
177
- ret = -EFAULT;
178
- goto done;
179
- }
184
+ memcpy(buffer, kbuf, len);
180185 *lenp = len;
181186 *ppos += len;
182187 }
....@@ -187,8 +192,7 @@
187192 }
188193
189194 static int flow_limit_table_len_sysctl(struct ctl_table *table, int write,
190
- void __user *buffer, size_t *lenp,
191
- loff_t *ppos)
195
+ void *buffer, size_t *lenp, loff_t *ppos)
192196 {
193197 unsigned int old, *ptr;
194198 int ret;
....@@ -210,7 +214,7 @@
210214
211215 #ifdef CONFIG_NET_SCHED
212216 static int set_default_qdisc(struct ctl_table *table, int write,
213
- void __user *buffer, size_t *lenp, loff_t *ppos)
217
+ void *buffer, size_t *lenp, loff_t *ppos)
214218 {
215219 char id[IFNAMSIZ];
216220 struct ctl_table tbl = {
....@@ -229,23 +233,25 @@
229233 #endif
230234
231235 static int proc_do_dev_weight(struct ctl_table *table, int write,
232
- void __user *buffer, size_t *lenp, loff_t *ppos)
236
+ void *buffer, size_t *lenp, loff_t *ppos)
233237 {
234
- int ret;
238
+ static DEFINE_MUTEX(dev_weight_mutex);
239
+ int ret, weight;
235240
241
+ mutex_lock(&dev_weight_mutex);
236242 ret = proc_dointvec(table, write, buffer, lenp, ppos);
237
- if (ret != 0)
238
- return ret;
239
-
240
- dev_rx_weight = weight_p * dev_weight_rx_bias;
241
- dev_tx_weight = weight_p * dev_weight_tx_bias;
243
+ if (!ret && write) {
244
+ weight = READ_ONCE(weight_p);
245
+ WRITE_ONCE(dev_rx_weight, weight * dev_weight_rx_bias);
246
+ WRITE_ONCE(dev_tx_weight, weight * dev_weight_tx_bias);
247
+ }
248
+ mutex_unlock(&dev_weight_mutex);
242249
243250 return ret;
244251 }
245252
246
-#ifdef CONFIG_ETHTOOL
247253 static int proc_do_rss_key(struct ctl_table *table, int write,
248
- void __user *buffer, size_t *lenp, loff_t *ppos)
254
+ void *buffer, size_t *lenp, loff_t *ppos)
249255 {
250256 struct ctl_table fake_table;
251257 char buf[NETDEV_RSS_KEY_LEN * 3];
....@@ -255,11 +261,10 @@
255261 fake_table.maxlen = sizeof(buf);
256262 return proc_dostring(&fake_table, write, buffer, lenp, ppos);
257263 }
258
-#endif
259264
260265 #ifdef CONFIG_BPF_JIT
261266 static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write,
262
- void __user *buffer, size_t *lenp,
267
+ void *buffer, size_t *lenp,
263268 loff_t *ppos)
264269 {
265270 int ret, jit_enable = *(int *)table->data;
....@@ -286,8 +291,7 @@
286291 # ifdef CONFIG_HAVE_EBPF_JIT
287292 static int
288293 proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write,
289
- void __user *buffer, size_t *lenp,
290
- loff_t *ppos)
294
+ void *buffer, size_t *lenp, loff_t *ppos)
291295 {
292296 if (!capable(CAP_SYS_ADMIN))
293297 return -EPERM;
....@@ -298,8 +302,7 @@
298302
299303 static int
300304 proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write,
301
- void __user *buffer, size_t *lenp,
302
- loff_t *ppos)
305
+ void *buffer, size_t *lenp, loff_t *ppos)
303306 {
304307 if (!capable(CAP_SYS_ADMIN))
305308 return -EPERM;
....@@ -370,7 +373,6 @@
370373 .mode = 0644,
371374 .proc_handler = proc_dointvec
372375 },
373
-#ifdef CONFIG_ETHTOOL
374376 {
375377 .procname = "netdev_rss_key",
376378 .data = &netdev_rss_key,
....@@ -378,7 +380,6 @@
378380 .mode = 0444,
379381 .proc_handler = proc_do_rss_key,
380382 },
381
-#endif
382383 #ifdef CONFIG_BPF_JIT
383384 {
384385 .procname = "bpf_jit_enable",
....@@ -387,10 +388,10 @@
387388 .mode = 0644,
388389 .proc_handler = proc_dointvec_minmax_bpf_enable,
389390 # ifdef CONFIG_BPF_JIT_ALWAYS_ON
390
- .extra1 = &one,
391
- .extra2 = &one,
391
+ .extra1 = SYSCTL_ONE,
392
+ .extra2 = SYSCTL_ONE,
392393 # else
393
- .extra1 = &zero,
394
+ .extra1 = SYSCTL_ZERO,
394395 .extra2 = &two,
395396 # endif
396397 },
....@@ -401,7 +402,7 @@
401402 .maxlen = sizeof(int),
402403 .mode = 0600,
403404 .proc_handler = proc_dointvec_minmax_bpf_restricted,
404
- .extra1 = &zero,
405
+ .extra1 = SYSCTL_ZERO,
405406 .extra2 = &two,
406407 },
407408 {
....@@ -410,8 +411,8 @@
410411 .maxlen = sizeof(int),
411412 .mode = 0600,
412413 .proc_handler = proc_dointvec_minmax_bpf_restricted,
413
- .extra1 = &zero,
414
- .extra2 = &one,
414
+ .extra1 = SYSCTL_ZERO,
415
+ .extra2 = SYSCTL_ONE,
415416 },
416417 # endif
417418 {
....@@ -458,8 +459,8 @@
458459 .maxlen = sizeof(int),
459460 .mode = 0644,
460461 .proc_handler = proc_dointvec_minmax,
461
- .extra1 = &zero,
462
- .extra2 = &one
462
+ .extra1 = SYSCTL_ZERO,
463
+ .extra2 = SYSCTL_ONE
463464 },
464465 #ifdef CONFIG_RPS
465466 {
....@@ -490,7 +491,7 @@
490491 .maxlen = sizeof(unsigned int),
491492 .mode = 0644,
492493 .proc_handler = proc_dointvec_minmax,
493
- .extra1 = &zero,
494
+ .extra1 = SYSCTL_ZERO,
494495 },
495496 {
496497 .procname = "busy_read",
....@@ -498,7 +499,7 @@
498499 .maxlen = sizeof(unsigned int),
499500 .mode = 0644,
500501 .proc_handler = proc_dointvec_minmax,
501
- .extra1 = &zero,
502
+ .extra1 = SYSCTL_ZERO,
502503 },
503504 #endif
504505 #ifdef CONFIG_NET_SCHED
....@@ -530,7 +531,7 @@
530531 .maxlen = sizeof(int),
531532 .mode = 0644,
532533 .proc_handler = proc_dointvec_minmax,
533
- .extra1 = &one,
534
+ .extra1 = SYSCTL_ONE,
534535 .extra2 = &max_skb_frags,
535536 },
536537 {
....@@ -539,7 +540,7 @@
539540 .maxlen = sizeof(unsigned int),
540541 .mode = 0644,
541542 .proc_handler = proc_dointvec_minmax,
542
- .extra1 = &zero,
543
+ .extra1 = SYSCTL_ZERO,
543544 },
544545 {
545546 .procname = "fb_tunnels_only_for_init_net",
....@@ -547,8 +548,32 @@
547548 .maxlen = sizeof(int),
548549 .mode = 0644,
549550 .proc_handler = proc_dointvec_minmax,
550
- .extra1 = &zero,
551
- .extra2 = &one,
551
+ .extra1 = SYSCTL_ZERO,
552
+ .extra2 = &two,
553
+ },
554
+ {
555
+ .procname = "devconf_inherit_init_net",
556
+ .data = &sysctl_devconf_inherit_init_net,
557
+ .maxlen = sizeof(int),
558
+ .mode = 0644,
559
+ .proc_handler = proc_dointvec_minmax,
560
+ .extra1 = SYSCTL_ZERO,
561
+ .extra2 = &three,
562
+ },
563
+ {
564
+ .procname = "high_order_alloc_disable",
565
+ .data = &net_high_order_alloc_disable_key.key,
566
+ .maxlen = sizeof(net_high_order_alloc_disable_key),
567
+ .mode = 0644,
568
+ .proc_handler = proc_do_static_key,
569
+ },
570
+ {
571
+ .procname = "gro_normal_batch",
572
+ .data = &gro_normal_batch,
573
+ .maxlen = sizeof(unsigned int),
574
+ .mode = 0644,
575
+ .proc_handler = proc_dointvec_minmax,
576
+ .extra1 = SYSCTL_ONE,
552577 },
553578 { }
554579 };
....@@ -559,12 +584,25 @@
559584 .data = &init_net.core.sysctl_somaxconn,
560585 .maxlen = sizeof(int),
561586 .mode = 0644,
562
- .extra1 = &zero,
587
+ .extra1 = SYSCTL_ZERO,
563588 .proc_handler = proc_dointvec_minmax
564589 },
565590 { }
566591 };
567592
593
+static int __init fb_tunnels_only_for_init_net_sysctl_setup(char *str)
594
+{
595
+ /* fallback tunnels for initns only */
596
+ if (!strncmp(str, "initns", 6))
597
+ sysctl_fb_tunnels_only_for_init_net = 1;
598
+ /* no fallback tunnels anywhere */
599
+ else if (!strncmp(str, "none", 4))
600
+ sysctl_fb_tunnels_only_for_init_net = 2;
601
+
602
+ return 1;
603
+}
604
+__setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup);
605
+
568606 static __net_init int sysctl_core_net_init(struct net *net)
569607 {
570608 struct ctl_table *tbl;