Commit 4f3fdf3bc59cafd14c3bc2c2369efad34c7aa8b5
Committed by
David S. Miller
1 parent
85f935d41a
sctp: add check rto_min and rto_max in sysctl
rto_min should be smaller than rto_max while rto_max should be larger than rto_min. Add two proc_handler for the checking. Suggested-by: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: Wang Weidong <wangweidong1@huawei.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 65 additions and 4 deletions Side-by-side Diff
net/sctp/sysctl.c
... | ... | @@ -61,6 +61,13 @@ |
61 | 61 | void __user *buffer, size_t *lenp, |
62 | 62 | |
63 | 63 | loff_t *ppos); |
64 | +static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write, | |
65 | + void __user *buffer, size_t *lenp, | |
66 | + loff_t *ppos); | |
67 | +static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, | |
68 | + void __user *buffer, size_t *lenp, | |
69 | + loff_t *ppos); | |
70 | + | |
64 | 71 | static struct ctl_table sctp_table[] = { |
65 | 72 | { |
66 | 73 | .procname = "sctp_mem", |
67 | 74 | |
68 | 75 | |
... | ... | @@ -102,17 +109,17 @@ |
102 | 109 | .data = &init_net.sctp.rto_min, |
103 | 110 | .maxlen = sizeof(unsigned int), |
104 | 111 | .mode = 0644, |
105 | - .proc_handler = proc_dointvec_minmax, | |
112 | + .proc_handler = proc_sctp_do_rto_min, | |
106 | 113 | .extra1 = &one, |
107 | - .extra2 = &timer_max | |
114 | + .extra2 = &init_net.sctp.rto_max | |
108 | 115 | }, |
109 | 116 | { |
110 | 117 | .procname = "rto_max", |
111 | 118 | .data = &init_net.sctp.rto_max, |
112 | 119 | .maxlen = sizeof(unsigned int), |
113 | 120 | .mode = 0644, |
114 | - .proc_handler = proc_dointvec_minmax, | |
115 | - .extra1 = &one, | |
121 | + .proc_handler = proc_sctp_do_rto_max, | |
122 | + .extra1 = &init_net.sctp.rto_min, | |
116 | 123 | .extra2 = &timer_max |
117 | 124 | }, |
118 | 125 | { |
... | ... | @@ -339,6 +346,60 @@ |
339 | 346 | ret = -EINVAL; |
340 | 347 | } |
341 | 348 | |
349 | + return ret; | |
350 | +} | |
351 | + | |
352 | +static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write, | |
353 | + void __user *buffer, size_t *lenp, | |
354 | + loff_t *ppos) | |
355 | +{ | |
356 | + struct net *net = current->nsproxy->net_ns; | |
357 | + int new_value; | |
358 | + struct ctl_table tbl; | |
359 | + unsigned int min = *(unsigned int *) ctl->extra1; | |
360 | + unsigned int max = *(unsigned int *) ctl->extra2; | |
361 | + int ret; | |
362 | + | |
363 | + memset(&tbl, 0, sizeof(struct ctl_table)); | |
364 | + tbl.maxlen = sizeof(unsigned int); | |
365 | + | |
366 | + if (write) | |
367 | + tbl.data = &new_value; | |
368 | + else | |
369 | + tbl.data = &net->sctp.rto_min; | |
370 | + ret = proc_dointvec(&tbl, write, buffer, lenp, ppos); | |
371 | + if (write) { | |
372 | + if (ret || new_value > max || new_value < min) | |
373 | + return -EINVAL; | |
374 | + net->sctp.rto_min = new_value; | |
375 | + } | |
376 | + return ret; | |
377 | +} | |
378 | + | |
379 | +static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, | |
380 | + void __user *buffer, size_t *lenp, | |
381 | + loff_t *ppos) | |
382 | +{ | |
383 | + struct net *net = current->nsproxy->net_ns; | |
384 | + int new_value; | |
385 | + struct ctl_table tbl; | |
386 | + unsigned int min = *(unsigned int *) ctl->extra1; | |
387 | + unsigned int max = *(unsigned int *) ctl->extra2; | |
388 | + int ret; | |
389 | + | |
390 | + memset(&tbl, 0, sizeof(struct ctl_table)); | |
391 | + tbl.maxlen = sizeof(unsigned int); | |
392 | + | |
393 | + if (write) | |
394 | + tbl.data = &new_value; | |
395 | + else | |
396 | + tbl.data = &net->sctp.rto_max; | |
397 | + ret = proc_dointvec(&tbl, write, buffer, lenp, ppos); | |
398 | + if (write) { | |
399 | + if (ret || new_value > max || new_value < min) | |
400 | + return -EINVAL; | |
401 | + net->sctp.rto_max = new_value; | |
402 | + } | |
342 | 403 | return ret; |
343 | 404 | } |
344 | 405 |