sctp: check the rto_min and rto_max in setsockopt
When we set 0 to rto_min or rto_max, just not change the value. Also we should check the rto_min > rto_max. 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>
This commit is contained in:
parent
ce7a3bdf18
commit
85f935d41a
|
@ -2815,6 +2815,8 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne
|
||||||
{
|
{
|
||||||
struct sctp_rtoinfo rtoinfo;
|
struct sctp_rtoinfo rtoinfo;
|
||||||
struct sctp_association *asoc;
|
struct sctp_association *asoc;
|
||||||
|
unsigned long rto_min, rto_max;
|
||||||
|
struct sctp_sock *sp = sctp_sk(sk);
|
||||||
|
|
||||||
if (optlen != sizeof (struct sctp_rtoinfo))
|
if (optlen != sizeof (struct sctp_rtoinfo))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -2828,26 +2830,36 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigne
|
||||||
if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
|
if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
rto_max = rtoinfo.srto_max;
|
||||||
|
rto_min = rtoinfo.srto_min;
|
||||||
|
|
||||||
|
if (rto_max)
|
||||||
|
rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max;
|
||||||
|
else
|
||||||
|
rto_max = asoc ? asoc->rto_max : sp->rtoinfo.srto_max;
|
||||||
|
|
||||||
|
if (rto_min)
|
||||||
|
rto_min = asoc ? msecs_to_jiffies(rto_min) : rto_min;
|
||||||
|
else
|
||||||
|
rto_min = asoc ? asoc->rto_min : sp->rtoinfo.srto_min;
|
||||||
|
|
||||||
|
if (rto_min > rto_max)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
if (asoc) {
|
if (asoc) {
|
||||||
if (rtoinfo.srto_initial != 0)
|
if (rtoinfo.srto_initial != 0)
|
||||||
asoc->rto_initial =
|
asoc->rto_initial =
|
||||||
msecs_to_jiffies(rtoinfo.srto_initial);
|
msecs_to_jiffies(rtoinfo.srto_initial);
|
||||||
if (rtoinfo.srto_max != 0)
|
asoc->rto_max = rto_max;
|
||||||
asoc->rto_max = msecs_to_jiffies(rtoinfo.srto_max);
|
asoc->rto_min = rto_min;
|
||||||
if (rtoinfo.srto_min != 0)
|
|
||||||
asoc->rto_min = msecs_to_jiffies(rtoinfo.srto_min);
|
|
||||||
} else {
|
} else {
|
||||||
/* If there is no association or the association-id = 0
|
/* If there is no association or the association-id = 0
|
||||||
* set the values to the endpoint.
|
* set the values to the endpoint.
|
||||||
*/
|
*/
|
||||||
struct sctp_sock *sp = sctp_sk(sk);
|
|
||||||
|
|
||||||
if (rtoinfo.srto_initial != 0)
|
if (rtoinfo.srto_initial != 0)
|
||||||
sp->rtoinfo.srto_initial = rtoinfo.srto_initial;
|
sp->rtoinfo.srto_initial = rtoinfo.srto_initial;
|
||||||
if (rtoinfo.srto_max != 0)
|
sp->rtoinfo.srto_max = rto_max;
|
||||||
sp->rtoinfo.srto_max = rtoinfo.srto_max;
|
sp->rtoinfo.srto_min = rto_min;
|
||||||
if (rtoinfo.srto_min != 0)
|
|
||||||
sp->rtoinfo.srto_min = rtoinfo.srto_min;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue