Skip to content

Commit ff5e92c

Browse files
Daniel Borkmanndavem330
authored andcommitted
net: sctp: propagate sysctl errors from proc_do* properly
sysctl handler proc_sctp_do_hmac_alg(), proc_sctp_do_rto_min() and proc_sctp_do_rto_max() do not properly reflect some error cases when writing values via sysctl from internal proc functions such as proc_dointvec() and proc_dostring(). In all these cases we pass the test for write != 0 and partially do additional work just to notice that additional sanity checks fail and we return with hard-coded -EINVAL while proc_do* functions might also return different errors. So fix this up by simply testing a successful return of proc_do* right after calling it. This also allows to propagate its return value onwards to the user. While touching this, also fix up some minor style issues. Fixes: 4f3fdf3 ("sctp: add check rto_min and rto_max in sysctl") Fixes: 3c68198 ("sctp: Make hmac algorithm selection for cookie generation dynamic") Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d36a4f4 commit ff5e92c

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

‎net/sctp/sysctl.c‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -321,41 +321,40 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
321321
loff_t *ppos)
322322
{
323323
struct net *net = current->nsproxy->net_ns;
324-
char tmp[8];
325324
struct ctl_table tbl;
326-
int ret;
327-
int changed = 0;
325+
bool changed = false;
328326
char *none = "none";
327+
char tmp[8];
328+
int ret;
329329

330330
memset(&tbl, 0, sizeof(struct ctl_table));
331331

332332
if (write) {
333333
tbl.data = tmp;
334-
tbl.maxlen = 8;
334+
tbl.maxlen = sizeof(tmp);
335335
} else {
336336
tbl.data = net->sctp.sctp_hmac_alg ? : none;
337337
tbl.maxlen = strlen(tbl.data);
338338
}
339-
ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
340339

341-
if (write) {
340+
ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
341+
if (write && ret == 0) {
342342
#ifdef CONFIG_CRYPTO_MD5
343343
if (!strncmp(tmp, "md5", 3)) {
344344
net->sctp.sctp_hmac_alg = "md5";
345-
changed = 1;
345+
changed = true;
346346
}
347347
#endif
348348
#ifdef CONFIG_CRYPTO_SHA1
349349
if (!strncmp(tmp, "sha1", 4)) {
350350
net->sctp.sctp_hmac_alg = "sha1";
351-
changed = 1;
351+
changed = true;
352352
}
353353
#endif
354354
if (!strncmp(tmp, "none", 4)) {
355355
net->sctp.sctp_hmac_alg = NULL;
356-
changed = 1;
356+
changed = true;
357357
}
358-
359358
if (!changed)
360359
ret = -EINVAL;
361360
}
@@ -368,11 +367,10 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
368367
loff_t *ppos)
369368
{
370369
struct net *net = current->nsproxy->net_ns;
371-
int new_value;
372-
struct ctl_table tbl;
373370
unsigned int min = *(unsigned int *) ctl->extra1;
374371
unsigned int max = *(unsigned int *) ctl->extra2;
375-
int ret;
372+
struct ctl_table tbl;
373+
int ret, new_value;
376374

377375
memset(&tbl, 0, sizeof(struct ctl_table));
378376
tbl.maxlen = sizeof(unsigned int);
@@ -381,12 +379,15 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
381379
tbl.data = &new_value;
382380
else
383381
tbl.data = &net->sctp.rto_min;
382+
384383
ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
385-
if (write) {
386-
if (ret || new_value > max || new_value < min)
384+
if (write && ret == 0) {
385+
if (new_value > max || new_value < min)
387386
return -EINVAL;
387+
388388
net->sctp.rto_min = new_value;
389389
}
390+
390391
return ret;
391392
}
392393

@@ -395,11 +396,10 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
395396
loff_t *ppos)
396397
{
397398
struct net *net = current->nsproxy->net_ns;
398-
int new_value;
399-
struct ctl_table tbl;
400399
unsigned int min = *(unsigned int *) ctl->extra1;
401400
unsigned int max = *(unsigned int *) ctl->extra2;
402-
int ret;
401+
struct ctl_table tbl;
402+
int ret, new_value;
403403

404404
memset(&tbl, 0, sizeof(struct ctl_table));
405405
tbl.maxlen = sizeof(unsigned int);
@@ -408,12 +408,15 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
408408
tbl.data = &new_value;
409409
else
410410
tbl.data = &net->sctp.rto_max;
411+
411412
ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
412-
if (write) {
413-
if (ret || new_value > max || new_value < min)
413+
if (write && ret == 0) {
414+
if (new_value > max || new_value < min)
414415
return -EINVAL;
416+
415417
net->sctp.rto_max = new_value;
416418
}
419+
417420
return ret;
418421
}
419422

0 commit comments

Comments
 (0)