Skip to content

Commit 19249c0

Browse files
teknoraverkuba-moo
authored andcommitted
net: make net.core.{r,w}mem_{default,max} namespaced
The following sysctl are global and can't be read from a netns: net.core.rmem_default net.core.rmem_max net.core.wmem_default net.core.wmem_max Make the following sysctl parameters available readonly from within a network namespace, allowing a container to read them. Signed-off-by: Matteo Croce <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Shakeel Butt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 165f876 commit 19249c0

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

net/core/sysctl_net_core.c

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -382,38 +382,6 @@ proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write,
382382
#endif
383383

384384
static struct ctl_table net_core_table[] = {
385-
{
386-
.procname = "wmem_max",
387-
.data = &sysctl_wmem_max,
388-
.maxlen = sizeof(int),
389-
.mode = 0644,
390-
.proc_handler = proc_dointvec_minmax,
391-
.extra1 = &min_sndbuf,
392-
},
393-
{
394-
.procname = "rmem_max",
395-
.data = &sysctl_rmem_max,
396-
.maxlen = sizeof(int),
397-
.mode = 0644,
398-
.proc_handler = proc_dointvec_minmax,
399-
.extra1 = &min_rcvbuf,
400-
},
401-
{
402-
.procname = "wmem_default",
403-
.data = &sysctl_wmem_default,
404-
.maxlen = sizeof(int),
405-
.mode = 0644,
406-
.proc_handler = proc_dointvec_minmax,
407-
.extra1 = &min_sndbuf,
408-
},
409-
{
410-
.procname = "rmem_default",
411-
.data = &sysctl_rmem_default,
412-
.maxlen = sizeof(int),
413-
.mode = 0644,
414-
.proc_handler = proc_dointvec_minmax,
415-
.extra1 = &min_rcvbuf,
416-
},
417385
{
418386
.procname = "mem_pcpu_rsv",
419387
.data = &net_hotdata.sysctl_mem_pcpu_rsv,
@@ -697,6 +665,41 @@ static struct ctl_table netns_core_table[] = {
697665
.extra2 = SYSCTL_ONE,
698666
.proc_handler = proc_dou8vec_minmax,
699667
},
668+
/* sysctl_core_net_init() will set the values after this
669+
* to readonly in network namespaces
670+
*/
671+
{
672+
.procname = "wmem_max",
673+
.data = &sysctl_wmem_max,
674+
.maxlen = sizeof(int),
675+
.mode = 0644,
676+
.proc_handler = proc_dointvec_minmax,
677+
.extra1 = &min_sndbuf,
678+
},
679+
{
680+
.procname = "rmem_max",
681+
.data = &sysctl_rmem_max,
682+
.maxlen = sizeof(int),
683+
.mode = 0644,
684+
.proc_handler = proc_dointvec_minmax,
685+
.extra1 = &min_rcvbuf,
686+
},
687+
{
688+
.procname = "wmem_default",
689+
.data = &sysctl_wmem_default,
690+
.maxlen = sizeof(int),
691+
.mode = 0644,
692+
.proc_handler = proc_dointvec_minmax,
693+
.extra1 = &min_sndbuf,
694+
},
695+
{
696+
.procname = "rmem_default",
697+
.data = &sysctl_rmem_default,
698+
.maxlen = sizeof(int),
699+
.mode = 0644,
700+
.proc_handler = proc_dointvec_minmax,
701+
.extra1 = &min_rcvbuf,
702+
},
700703
};
701704

702705
static int __init fb_tunnels_only_for_init_net_sysctl_setup(char *str)
@@ -724,8 +727,14 @@ static __net_init int sysctl_core_net_init(struct net *net)
724727
if (tbl == NULL)
725728
goto err_dup;
726729

727-
for (i = 0; i < table_size; ++i)
730+
for (i = 0; i < table_size; ++i) {
731+
if (tbl[i].data == &sysctl_wmem_max)
732+
break;
733+
728734
tbl[i].data += (char *)net - (char *)&init_net;
735+
}
736+
for (; i < table_size; ++i)
737+
tbl[i].mode &= ~0222;
729738
}
730739

731740
net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl, table_size);

0 commit comments

Comments
 (0)