Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763647AbXEXE12 (ORCPT ); Thu, 24 May 2007 00:27:28 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759532AbXEXE1T (ORCPT ); Thu, 24 May 2007 00:27:19 -0400 Received: from mailhub.sw.ru ([195.214.233.200]:13139 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759198AbXEXE1S (ORCPT ); Thu, 24 May 2007 00:27:18 -0400 Message-ID: <465512EB.4000808@sw.ru> Date: Thu, 24 May 2007 08:22:03 +0400 From: Vasily Averin User-Agent: Thunderbird 1.5.0.10 (X11/20060911) MIME-Version: 1.0 To: "David S. Miller" , netdev@vger.kernel.org, Andrew Morton , Linux Kernel Mailing List , devel@openvz.org Subject: [PATCH netdev] "wrong timeout value" in sk_wait_data() X-Enigmail-Version: 0.94.2.0 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1718 Lines: 48 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 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; - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/