]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
tcp: Add TCP_USER_TIMEOUT negative value check
authorHangbin Liu <liuhangbin@gmail.com>
Thu, 26 Jul 2012 22:52:21 +0000 (22:52 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 27 Jul 2012 20:45:50 +0000 (13:45 -0700)
TCP_USER_TIMEOUT is a TCP level socket option that takes an unsigned int. But
patch "tcp: Add TCP_USER_TIMEOUT socket option"(dca43c75) didn't check the negative
values. If a user assign -1 to it, the socket will set successfully and wait
for 4294967295 miliseconds. This patch add a negative value check to avoid
this issue.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/tcp.c

index 581ecf02c6b5c06f473e89c1d644cf5744410402..e7e6eeae49c0123d392fa16c7687c333b30b79b8 100644 (file)
@@ -2681,7 +2681,10 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
                /* Cap the max timeout in ms TCP will retry/retrans
                 * before giving up and aborting (ETIMEDOUT) a connection.
                 */
-               icsk->icsk_user_timeout = msecs_to_jiffies(val);
+               if (val < 0)
+                       err = -EINVAL;
+               else
+                       icsk->icsk_user_timeout = msecs_to_jiffies(val);
                break;
        default:
                err = -ENOPROTOOPT;