From modulus@h24-79-64-13.wp.shawcable.net  Fri Jun 20 08:08:44 2003
Return-Path: <modulus@h24-79-64-13.wp.shawcable.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id AB69D37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 20 Jun 2003 08:08:44 -0700 (PDT)
Received: from h24-79-64-13.wp.shawcable.net (h24-79-64-13.wp.shawcable.net [24.79.64.13])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6578B43FAF
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 20 Jun 2003 08:08:43 -0700 (PDT)
	(envelope-from modulus@h24-79-64-13.wp.shawcable.net)
Received: from h24-79-64-13.wp.shawcable.net (localhost [127.0.0.1])
	by h24-79-64-13.wp.shawcable.net (8.12.9/8.12.9) with ESMTP id h5KF8V6g000840
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 20 Jun 2003 10:08:31 -0500 (CDT)
	(envelope-from modulus@h24-79-64-13.wp.shawcable.net)
Received: (from root@localhost)
	by h24-79-64-13.wp.shawcable.net (8.12.9/8.12.9/Submit) id h5KF8Vgc000839;
	Fri, 20 Jun 2003 10:08:31 -0500 (CDT)
Message-Id: <200306201508.h5KF8Vgc000839@h24-79-64-13.wp.shawcable.net>
Date: Fri, 20 Jun 2003 10:08:31 -0500 (CDT)
From: "Christian S.J. Peron" <maneo@bsdpro.com>
Reply-To: "Christian S.J. Peron" <maneo@bsdpro.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch]: kernel panic: fix for a divide by zero processor exception
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         53557
>Category:       kern
>Synopsis:       [patch]: kernel panic: fix for a divide by zero processor exception
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 20 08:10:14 PDT 2003
>Closed-Date:    Fri Jun 20 15:20:16 PDT 2003
>Last-Modified:  Fri Jun 20 20:50:14 PDT 2003
>Originator:     Christian S.J. Peron
>Release:        FreeBSD 5.1-RELEASE i386
>Organization:
>Environment:
System: FreeBSD h24-79-64-13 5.1-RELEASE FreeBSD 5.1-RELEASE #5: Fri Jun 20 09:49:44 CDT 2003 maneo@movl:/usr/src/sys/i386/compile/RAID0 i386


	
>Description:
	If root sets the kern.log_wakeups_per_second variable to 0
	the next time the callback for the syslog wakeup gets scheduled
	it will panic due to divide by zero machine exception.

	
>How-To-Repeat:
	sysctl kern.log_wakeups_per_second=0

	
>Fix:

I have enclosed a patch that appears to fix the problem:

--- /usr/src/sys/kern/subr_log.c.bak	Fri Jun 20 09:14:12 2003
+++ /usr/src/sys/kern/subr_log.c	Fri Jun 20 09:45:04 2003
@@ -99,6 +99,17 @@
 	log_open = 1;
 	callout_init(&logsoftc.sc_callout, 0);
 	fsetown(td->td_proc->p_pid, &logsoftc.sc_sigio);	/* signal process only */
+
+	/*
+	 * Check to make sure the `log_wakeups_per_second' sysctl variable
+	 * is sane so that we avoid a divide by zero machine exception.
+	 */
+	if (!log_wakeups_per_second) {
+		printf("syslog wakeup is less then one. Adjusting to "
+			"one wakeup per second.\n");
+		log_wakeups_per_second = 1;
+	}
+
 	callout_reset(&logsoftc.sc_callout, hz / log_wakeups_per_second,
 	    logtimeout, NULL);
 	return (0);
@@ -181,6 +192,17 @@
 
 	if (!log_open)
 		return;
+
+	/*
+	 * Check to make sure the `log_wakeups_per_second' sysctl variable
+	 * is sane so that we avoid a divide by zero machine exception.
+	 */
+	if (!log_wakeups_per_second) {
+		printf("syslog wakeup is less then one. Adjusting to "
+			"one wakeup per second.\n");
+		log_wakeups_per_second = 1;
+	}
+
 	if (msgbuftrigger == 0) {
 		callout_reset(&logsoftc.sc_callout,
 		    hz / log_wakeups_per_second, logtimeout, NULL);
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: bmilekic 
State-Changed-When: Fri Jun 20 15:19:42 PDT 2003 
State-Changed-Why:  
Committed fix.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=53557 

From: Bruce Evans <bde@zeta.org.au>
To: "Christian S.J. Peron" <maneo@bsdpro.com>
Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Subject: Re: kern/53557: [patch]: kernel panic: fix for a divide by zero
 processor exception
Date: Sat, 21 Jun 2003 13:48:22 +1000 (EST)

 On Fri, 20 Jun 2003, Christian S.J. Peron wrote:
 
 > >Description:
 > 	If root sets the kern.log_wakeups_per_second variable to 0
 > 	the next time the callback for the syslog wakeup gets scheduled
 > 	it will panic due to divide by zero machine exception.
 
 Don't do that then.
 
 There are hundreds or thousands of sysctls that may be used for much
 more interesting foot shooting than a panic.  If foot shooting prevention
 is required, then it should be implemented more generally starting
 with simple range checks for all sysctls that set scalar values.
 
 Bruce
>Unformatted:
