Skip to content

Commit 4f3fdf3

Browse files
wangweidongdavem330
authored andcommitted
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>
1 parent 85f935d commit 4f3fdf3

1 file changed

Lines changed: 65 additions & 4 deletions

File tree

‎net/sctp/sysctl.c‎

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl,
6161
void __user *buffer, size_t *lenp,
6262

6363
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+
6471
static struct ctl_table sctp_table[] = {
6572
{
6673
.procname = "sctp_mem",
@@ -102,17 +109,17 @@ static struct ctl_table sctp_net_table[] = {
102109
.data = &init_net.sctp.rto_min,
103110
.maxlen = sizeof(unsigned int),
104111
.mode = 0644,
105-
.proc_handler = proc_dointvec_minmax,
112+
.proc_handler = proc_sctp_do_rto_min,
106113
.extra1 = &one,
107-
.extra2 = &timer_max
114+
.extra2 = &init_net.sctp.rto_max
108115
},
109116
{
110117
.procname = "rto_max",
111118
.data = &init_net.sctp.rto_max,
112119
.maxlen = sizeof(unsigned int),
113120
.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,
116123
.extra2 = &timer_max
117124
},
118125
{
@@ -342,6 +349,60 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl,
342349
return ret;
343350
}
344351

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+
}
403+
return ret;
404+
}
405+
345406
int sctp_sysctl_net_register(struct net *net)
346407
{
347408
struct ctl_table *table;

0 commit comments

Comments
 (0)