Skip to content

Commit

Permalink
[NET]: "wrong timeout value" in sk_wait_data() v2
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Vasily Averin authored and davem330 committed May 24, 2007
1 parent c883f21 commit ba78073
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ba78073

Please sign in to comment.