From owner-svn-src-head@FreeBSD.ORG Thu Dec 19 09:01:47 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 29592700; Thu, 19 Dec 2013 09:01:47 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 15EB71B05; Thu, 19 Dec 2013 09:01:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBJ91kgA036882; Thu, 19 Dec 2013 09:01:46 GMT (envelope-from se@svn.freebsd.org) Received: (from se@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBJ91ko3036881; Thu, 19 Dec 2013 09:01:46 GMT (envelope-from se@svn.freebsd.org) Message-Id: <201312190901.rBJ91ko3036881@svn.freebsd.org> From: Stefan Esser Date: Thu, 19 Dec 2013 09:01:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r259609 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Dec 2013 09:01:47 -0000 Author: se Date: Thu Dec 19 09:01:46 2013 New Revision: 259609 URL: http://svnweb.freebsd.org/changeset/base/259609 Log: Fix overflow for timeout values of more than 68 years, which is the maximum covered by sbintime (LONG_MAX seconds). Some programs use timeout values in excess of 1000 years. The conversion to sbintime caused wrap-around on overflow, which resulted in short or negative timeout values. This caused long delays on sockets opened by affected programs (e.g. OpenSSH). Kernels compiled without -fno-strict-overflow were not affected, apparently because the compiler tested the sign of the timeout value before performing the multiplication that lead to overflow. When the -fno-strict-overflow option was added to CFLAGS, this optimization was disabled and the test was performed on the result of the multiplication. Negative products were caught and resulted in EINVAL being returned, but wrap-around to positive values just shortened the timeout value to the residue of the result that could be represented by sbintime. The fix is to cap the timeout values at the maximum that can be represented by sbintime, which is 2^31 - 1 seconds or more than 68 years. After this change, the kernel can be compiled with -fno-strict-overflow with no ill effects. MFC after: 3 days Modified: head/sys/kern/kern_event.c Modified: head/sys/kern/kern_event.c ============================================================================== --- head/sys/kern/kern_event.c Thu Dec 19 07:33:07 2013 (r259608) +++ head/sys/kern/kern_event.c Thu Dec 19 09:01:46 2013 (r259609) @@ -526,7 +526,8 @@ knote_fork(struct knlist *list, int pid) static __inline sbintime_t timer2sbintime(intptr_t data) { - + if (data > LLONG_MAX / SBT_1MS) + return LLONG_MAX; return (SBT_1MS * data); }