From owner-svn-src-head@FreeBSD.ORG Thu Sep 26 13:17:31 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 ESMTP id DBD35725; Thu, 26 Sep 2013 13:17:31 +0000 (UTC) (envelope-from kib@FreeBSD.org) 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 C94AD2933; Thu, 26 Sep 2013 13:17:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8QDHV4A038274; Thu, 26 Sep 2013 13:17:31 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r8QDHVeA038273; Thu, 26 Sep 2013 13:17:31 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201309261317.r8QDHVeA038273@svn.freebsd.org> From: Konstantin Belousov Date: Thu, 26 Sep 2013 13:17:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r255882 - 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.14 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, 26 Sep 2013 13:17:31 -0000 Author: kib Date: Thu Sep 26 13:17:31 2013 New Revision: 255882 URL: http://svnweb.freebsd.org/changeset/base/255882 Log: Do not allow negative timeouts for kqueue timers, check for the negative timeout both before and after the conversion to sbintime_t. For periodic kqueue timer, convert zero timeout into 1ms, to avoid interrupt storm on fast event timers. Reported and tested by: pho Discussed with: mav Reviewed by: davide Sponsored by: The FreeBSD Foundation Approved by: re (marius) Modified: head/sys/kern/kern_event.c Modified: head/sys/kern/kern_event.c ============================================================================== --- head/sys/kern/kern_event.c Thu Sep 26 13:15:33 2013 (r255881) +++ head/sys/kern/kern_event.c Thu Sep 26 13:17:31 2013 (r255882) @@ -554,8 +554,17 @@ static int filt_timerattach(struct knote *kn) { struct callout *calloutp; + sbintime_t to; unsigned int ncallouts; + if ((intptr_t)kn->kn_sdata < 0) + return (EINVAL); + if ((intptr_t)kn->kn_sdata == 0 && (kn->kn_flags & EV_ONESHOT) == 0) + kn->kn_sdata = 1; + to = timer2sbintime(kn->kn_sdata); + if (to < 0) + return (EINVAL); + ncallouts = atomic_load_explicit(&kq_ncallouts, memory_order_relaxed); do { if (ncallouts >= kq_calloutmax) @@ -569,8 +578,7 @@ filt_timerattach(struct knote *kn) calloutp = malloc(sizeof(*calloutp), M_KQUEUE, M_WAITOK); callout_init(calloutp, CALLOUT_MPSAFE); kn->kn_hook = calloutp; - callout_reset_sbt_on(calloutp, - timer2sbintime(kn->kn_sdata), 0 /* 1ms? */, + callout_reset_sbt_on(calloutp, to, 0 /* 1ms? */, filt_timerexpire, kn, PCPU_GET(cpuid), 0); return (0);