From dima@unixfreak.org  Thu Apr 12 01:05:19 2001
Return-Path: <dima@unixfreak.org>
Received: from bazooka.unixfreak.org (bazooka.unixfreak.org [63.198.170.138])
	by hub.freebsd.org (Postfix) with ESMTP id E4ACF37B42C
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 12 Apr 2001 01:05:17 -0700 (PDT)
	(envelope-from dima@unixfreak.org)
Received: from hornet.unixfreak.org (hornet [63.198.170.140])
	by bazooka.unixfreak.org (Postfix) with ESMTP id 29D413E29
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 12 Apr 2001 01:05:14 -0700 (PDT)
Received: (from dima@localhost)
	by hornet.unixfreak.org (8.11.1/8.11.1) id f3C85EC90485;
	Thu, 12 Apr 2001 01:05:14 -0700 (PDT)
	(envelope-from dima)
Message-Id: <200104120805.f3C85EC90485@hornet.unixfreak.org>
Date: Thu, 12 Apr 2001 01:05:14 -0700 (PDT)
From: dd@freebsd.org
Reply-To: dd@freebsd.org
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] syscons panic in userconfig mode
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         26508
>Category:       kern
>Synopsis:       [PATCH] syscons panic in userconfig mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 12 01:10:01 PDT 2001
>Closed-Date:    Mon Jun 11 20:25:45 PDT 2001
>Last-Modified:  Mon Jun 11 20:26:20 PDT 2001
>Originator:     Dima Dorfman
>Release:        FreeBSD 5.0-20010407-CURRENT i386
>Organization:
Private
>Environment:
System: FreeBSD spike.unixfreak.org 5.0-20010407-CURRENT FreeBSD 5.0-20010407-CURRENT #39: Sun Apr 8 22:44:22 PDT 2001 dima@spike.unixfreak.org:/c/home/dima/w/f/src/sys/compile/SPIKE i386

>Description:

Attempting to switch VTYs in userconfig mode will lead to a null
dereference in syscons.  I saw some messages about this on -current,
-stable, or -bugs recently, but I can't find them now.

>How-To-Repeat:

This is pretty easy to reproduce: simply boot the kernel with the -c
flag (userconfig), and press ALT+F2 (i386).  As far as I can tell,
this isn't a new bug.

>Fix:

The patch changes the VIRTUAL_TTY macro not to blindly assume
sc->dev[x] is a valid pointer.  It is safe to have it "return" NULL
because any code that uses it must (and does) already check for that
condition since si_tty may also be NULL in some cases (or at least
that's the way I understand it).

Index: syscons.c
===================================================================
RCS file: /st/src/FreeBSD/src/sys/dev/syscons/syscons.c,v
retrieving revision 1.355
diff -u -r1.355 syscons.c
--- syscons.c	2001/03/26 12:40:39	1.355
+++ syscons.c	2001/04/07 21:02:31
@@ -122,7 +122,8 @@
 
 #define SC_CONSOLECTL	255
 
-#define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x))->si_tty)
+#define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ?	\
+	SC_DEV((sc), (x))->si_tty : NULL)
 
 static	int		debugger;
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jkh 
Responsible-Changed-By: roam 
Responsible-Changed-When: Thu Apr 12 01:41:08 PDT 2001 
Responsible-Changed-Why:  
I don't know who is really responsible for syscons, but this seems to be 
quite an unfortunate bug; I myself have triggered it a couple of times 
while setting up a new system. 

The fix seems quite trivial; maybe this should go in before 4.3-R? :) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=26508 
Responsible-Changed-From-To: jkh->dd 
Responsible-Changed-By: dd 
Responsible-Changed-When: Thu May 24 17:21:49 PDT 2001 
Responsible-Changed-Why:  
I'll commit this patch. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=26508 
State-Changed-From-To: open->analyzed 
State-Changed-By: dd 
State-Changed-When: Sat May 26 17:57:52 PDT 2001 
State-Changed-Why:  
Committed my own patch; still assigned to myself as an MFC reminder. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=26508 
State-Changed-From-To: analyzed->closed 
State-Changed-By: dd 
State-Changed-When: Mon Jun 11 20:25:45 PDT 2001 
State-Changed-Why:  
MFC'd 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=26508 
>Unformatted:
