Skip to content

Commit ca57aad

Browse files
author
Xin Long
committed
sctp: sysctl: make extra pointers netns aware
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160516 Tested: compile only commit da05cec Author: Firo Yang <firo.yang@suse.com> Date: Fri Dec 9 13:48:54 2022 +0800 sctp: sysctl: make extra pointers netns aware Recently, a customer reported that from their container whose net namespace is different to the host's init_net, they can't set the container's net.sctp.rto_max to any value smaller than init_net.sctp.rto_min. For instance, Host: sudo sysctl net.sctp.rto_min net.sctp.rto_min = 1000 Container: echo 100 > /mnt/proc-net/sctp/rto_min echo 400 > /mnt/proc-net/sctp/rto_max echo: write error: Invalid argument This is caused by the check made from this'commit 4f3fdf3 ("sctp: add check rto_min and rto_max in sysctl")' When validating the input value, it's always referring the boundary value set for the init_net namespace. Having container's rto_max smaller than host's init_net.sctp.rto_min does make sense. Consider that the rto between two containers on the same host is very likely smaller than it for two hosts. So to fix this problem, as suggested by Marcelo, this patch makes the extra pointers of rto_min, rto_max, pf_retrans, and ps_retrans point to the corresponding variables from the newly created net namespace while the new net namespace is being registered in sctp_sysctl_net_register. Fixes: 4f3fdf3 ("sctp: add check rto_min and rto_max in sysctl") Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: Firo Yang <firo.yang@suse.com> Link: https://lore.kernel.org/r/20221209054854.23889-1-firo.yang@suse.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Xin Long <lxin@redhat.com>
1 parent 3db271c commit ca57aad

File tree

1 file changed

+44
-29
lines changed

1 file changed

+44
-29
lines changed

net/sctp/sysctl.c

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,18 @@ static struct ctl_table sctp_table[] = {
8484
{ /* sentinel */ }
8585
};
8686

87+
/* The following index defines are used in sctp_sysctl_net_register().
88+
* If you add new items to the sctp_net_table, please ensure that
89+
* the index values of these defines hold the same meaning indicated by
90+
* their macro names when they appear in sctp_net_table.
91+
*/
92+
#define SCTP_RTO_MIN_IDX 0
93+
#define SCTP_RTO_MAX_IDX 1
94+
#define SCTP_PF_RETRANS_IDX 2
95+
#define SCTP_PS_RETRANS_IDX 3
96+
8797
static struct ctl_table sctp_net_table[] = {
88-
{
89-
.procname = "rto_initial",
90-
.data = &init_net.sctp.rto_initial,
91-
.maxlen = sizeof(unsigned int),
92-
.mode = 0644,
93-
.proc_handler = proc_dointvec_minmax,
94-
.extra1 = SYSCTL_ONE,
95-
.extra2 = &timer_max
96-
},
97-
{
98+
[SCTP_RTO_MIN_IDX] = {
9899
.procname = "rto_min",
99100
.data = &init_net.sctp.rto_min,
100101
.maxlen = sizeof(unsigned int),
@@ -103,7 +104,7 @@ static struct ctl_table sctp_net_table[] = {
103104
.extra1 = SYSCTL_ONE,
104105
.extra2 = &init_net.sctp.rto_max
105106
},
106-
{
107+
[SCTP_RTO_MAX_IDX] = {
107108
.procname = "rto_max",
108109
.data = &init_net.sctp.rto_max,
109110
.maxlen = sizeof(unsigned int),
@@ -112,6 +113,33 @@ static struct ctl_table sctp_net_table[] = {
112113
.extra1 = &init_net.sctp.rto_min,
113114
.extra2 = &timer_max
114115
},
116+
[SCTP_PF_RETRANS_IDX] = {
117+
.procname = "pf_retrans",
118+
.data = &init_net.sctp.pf_retrans,
119+
.maxlen = sizeof(int),
120+
.mode = 0644,
121+
.proc_handler = proc_dointvec_minmax,
122+
.extra1 = SYSCTL_ZERO,
123+
.extra2 = &init_net.sctp.ps_retrans,
124+
},
125+
[SCTP_PS_RETRANS_IDX] = {
126+
.procname = "ps_retrans",
127+
.data = &init_net.sctp.ps_retrans,
128+
.maxlen = sizeof(int),
129+
.mode = 0644,
130+
.proc_handler = proc_dointvec_minmax,
131+
.extra1 = &init_net.sctp.pf_retrans,
132+
.extra2 = &ps_retrans_max,
133+
},
134+
{
135+
.procname = "rto_initial",
136+
.data = &init_net.sctp.rto_initial,
137+
.maxlen = sizeof(unsigned int),
138+
.mode = 0644,
139+
.proc_handler = proc_dointvec_minmax,
140+
.extra1 = SYSCTL_ONE,
141+
.extra2 = &timer_max
142+
},
115143
{
116144
.procname = "rto_alpha_exp_divisor",
117145
.data = &init_net.sctp.rto_alpha,
@@ -207,24 +235,6 @@ static struct ctl_table sctp_net_table[] = {
207235
.extra1 = SYSCTL_ONE,
208236
.extra2 = SYSCTL_INT_MAX,
209237
},
210-
{
211-
.procname = "pf_retrans",
212-
.data = &init_net.sctp.pf_retrans,
213-
.maxlen = sizeof(int),
214-
.mode = 0644,
215-
.proc_handler = proc_dointvec_minmax,
216-
.extra1 = SYSCTL_ZERO,
217-
.extra2 = &init_net.sctp.ps_retrans,
218-
},
219-
{
220-
.procname = "ps_retrans",
221-
.data = &init_net.sctp.ps_retrans,
222-
.maxlen = sizeof(int),
223-
.mode = 0644,
224-
.proc_handler = proc_dointvec_minmax,
225-
.extra1 = &init_net.sctp.pf_retrans,
226-
.extra2 = &ps_retrans_max,
227-
},
228238
{
229239
.procname = "sndbuf_policy",
230240
.data = &init_net.sctp.sndbuf_policy,
@@ -586,6 +596,11 @@ int sctp_sysctl_net_register(struct net *net)
586596
for (i = 0; table[i].data; i++)
587597
table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
588598

599+
table[SCTP_RTO_MIN_IDX].extra2 = &net->sctp.rto_max;
600+
table[SCTP_RTO_MAX_IDX].extra1 = &net->sctp.rto_min;
601+
table[SCTP_PF_RETRANS_IDX].extra2 = &net->sctp.ps_retrans;
602+
table[SCTP_PS_RETRANS_IDX].extra1 = &net->sctp.pf_retrans;
603+
589604
net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
590605
if (net->sctp.sysctl_header == NULL) {
591606
kfree(table);

0 commit comments

Comments
 (0)