OpenVZ Forum


Home » Mailing lists » Devel » [PATCH netdev] "wrong timeout value" in sk_wait_data()
[PATCH netdev] "wrong timeout value" in sk_wait_data() [message #13270] Thu, 24 May 2007 04:22 Go to next message
vaverin is currently offline  vaverin
Messages: 708
Registered: September 2005
Senior Member
sys_setsockopt() do not check properly timeout values for
SO_RCVTIMEO/SO_SNDTIMEO, for example it's possible to set negative timeout
values. POSIX do not defines behaviour for sys_setsockopt in case negative
timeouts, but requires that setsockopt() shall fail with -EDOM if the send and
receive timeout values are too big to fit into the timeout fields in the socket
structure.
In current implementation negative timeout can lead to error messages like
"schedule_timeout: wrong timeout value".

Proposed patch:
- checks tv_usec and returns -EDOM if it is wrong
- do not allows to set negative timeout values (sets 0 instead) and outputs
ratelimited information message about such attempts.

Signed-Off-By: Vasily Averin <vvs@sw.ru>

diff --git a/net/core/sock.c b/net/core/sock.c
index 22183c2..27d7a46 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -206,7 +206,19 @@ static int sock_set_timeout(long *timeo_p, char __user
*optval, int optlen)
return -EINVAL;
if (copy_from_user(&tv, optval, sizeof(tv)))
return -EFAULT;
-
+ if (tv.tv_usec < 0 || tv.tv_usec >= 1000000)
+ return -EDOM;
+
+ if (tv.tv_sec < 0) {
+ static int warned = 0;
+ *timeo_p = 0;
+ if (warned < 10 && net_ratelimit())
+ warned++;
+ printk(KERN_INFO "sock_set_timeout: `%s' (pid %d) "
+ "tries to set negative timeout\n",
+ current->comm, current->pid);
+ return 0;
+ }
*timeo_p = MAX_SCHEDULE_TIMEOUT;
if (tv.tv_sec == 0 && tv.tv_usec == 0)
return 0;
Re: [PATCH netdev] "wrong timeout value" in sk_wait_data() [message #13271 is a reply to message #13270] Thu, 24 May 2007 04:36 Go to previous messageGo to next message
Eric Dumazet is currently offline  Eric Dumazet
Messages: 36
Registered: July 2006
Member
Vasily Averin a écrit :
> sys_setsockopt() do not check properly timeout values for
> SO_RCVTIMEO/SO_SNDTIMEO, for example it's possible to set negative timeout
> values. POSIX do not defines behaviour for sys_setsockopt in case negative
> timeouts, but requires that setsockopt() shall fail with -EDOM if the send and
> receive timeout values are too big to fit into the timeout fields in the socket
> structure.
> In current implementation negative timeout can lead to error messages like
> "schedule_timeout: wrong timeout value".
>
> Proposed patch:
> - checks tv_usec and returns -EDOM if it is wrong
> - do not allows to set negative timeout values (sets 0 instead) and outputs
> ratelimited information message about such attempts.
>
> Signed-Off-By: Vasily Averin <vvs@sw.ru>
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 22183c2..27d7a46 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -206,7 +206,19 @@ static int sock_set_timeout(long *timeo_p, char __user
> *optval, int optlen)
> return -EINVAL;
> if (copy_from_user(&tv, optval, sizeof(tv)))
> return -EFAULT;
> -
> + if (tv.tv_usec < 0 || tv.tv_usec >= 1000000)
> + return -EDOM;

Please use USEC_PER_SEC instead of 1000000

> +
> + if (tv.tv_sec < 0) {
> + static int warned = 0;
> + *timeo_p = 0;
> + if (warned < 10 && net_ratelimit())
> + warned++;
> + printk(KERN_INFO "sock_set_timeout: `%s' (pid %d) "
> + "tries to set negative timeout\n",
> + current->comm, current->pid);
> + return 0;
> + }
> *timeo_p = MAX_SCHEDULE_TIMEOUT;
> if (tv.tv_sec == 0 && tv.tv_usec == 0)
> return 0;
>
[PATCH netdev] "wrong timeout value" in sk_wait_data() v2 [message #13273 is a reply to message #13271] Thu, 24 May 2007 05:23 Go to previous messageGo to next message
vaverin is currently offline  vaverin
Messages: 708
Registered: September 2005
Senior Member
sys_setsockopt() do not check properly timeout values for
SO_RCVTIMEO/SO_SNDTIMEO, for example it's possible to set negative timeout
values. POSIX do not defines behaviour for sys_setsockopt in case negative
timeouts, but requires that setsockopt() shall fail with -EDOM if the send and
receive timeout values are too big to fit into the timeout fields in the socket
structure.
In current implementation negative timeout can lead to error messages like
"schedule_timeout: wrong timeout value".

Proposed patch:
- checks tv_usec and returns -EDOM if it is wrong
- do not allows to set negative timeout values (sets 0 instead) and outputs
ratelimited information message about such attempts.

Signed-Off-By: Vasily Averin <vvs@sw.ru>

diff --git a/net/core/sock.c b/net/core/sock.c
index 22183c2..7e51d3a 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -206,7 +206,19 @@ static int sock_set_timeout(long *timeo_p, char __user
*optval, int optlen)
return -EINVAL;
if (copy_from_user(&tv, optval, sizeof(tv)))
return -EFAULT;
-
+ if (tv.tv_usec < 0 || tv.tv_usec >= USEC_PER_SEC)
+ return -EDOM;
+
+ if (tv.tv_sec < 0) {
+ static int warned = 0;
+ *timeo_p = 0;
+ if (warned < 10 && net_ratelimit())
+ warned++;
+ printk(KERN_INFO "sock_set_timeout: `%s' (pid %d) "
+ "tries to set negative timeout\n",
+ current->comm, current->pid);
+ return 0;
+ }
*timeo_p = MAX_SCHEDULE_TIMEOUT;
if (tv.tv_sec == 0 && tv.tv_usec == 0)
return 0;
Re: [PATCH netdev] "wrong timeout value" in sk_wait_data() v2 [message #13341 is a reply to message #13273] Thu, 24 May 2007 23:59 Go to previous message
davem is currently offline  davem
Messages: 463
Registered: February 2006
Senior Member
From: Vasily Averin <vvs@sw.ru>
Date: Thu, 24 May 2007 09:23:14 +0400

> sys_setsockopt() do not check properly timeout values for
> SO_RCVTIMEO/SO_SNDTIMEO, for example it's possible to set negative timeout
> values. POSIX do not defines behaviour for sys_setsockopt in case negative
> timeouts, but requires that setsockopt() shall fail with -EDOM if the send and
> receive timeout values are too big to fit into the timeout fields in the socket
> structure.
> In current implementation negative timeout can lead to error messages like
> "schedule_timeout: wrong timeout value".
>
> Proposed patch:
> - checks tv_usec and returns -EDOM if it is wrong
> - do not allows to set negative timeout values (sets 0 instead) and outputs
> ratelimited information message about such attempts.
>
> Signed-Off-By: Vasily Averin <vvs@sw.ru>

Thank you for this bug fix, patch applied.
Previous Topic: [RFC][PATCH] Per container statistics
Next Topic: Re: [RFC] [PATCH 0/3] Add group fairness to CFS
Goto Forum:
  


Current Time: Sun Nov 17 02:38:10 GMT 2024

Total time taken to generate the page: 0.03020 seconds