Subject: kern/649: kernel panic/trap when referencing floppy of "unknown density"
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: George Robbins <grr@shandakor.tharsis.com>
List: netbsd-bugs
Date: 12/18/1994 12:20:07
>Number:         649
>Category:       kern
>Synopsis:       kernel panic/trap when referencing floppy of "unknown density"
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 18 12:20:05 1994
>Originator:     George Robbins
>Organization:
none
>Release:        1.0
>Environment:
	System: NetBSD shandakor.tharsis.com 1.0 NetBSD 1.0 (SHANDAKOR) #0: Sat Dec 17 02:11:22 EST 1994 root@shandakor.tharsis.com:/usr/src/sys/arch/i386/compile/SHANDAKOR i386
>Description:
	When referencing a floppy drive that the configuration/attach code
	reported as being of "unknown density" via the default density /dev
	entry (i.e. /dev/fd0a), a kernel panic results due to dereferencing
	a null "type" pointer in fdstrategy().  This can happen when the
	the CMOS says the drive is "not installed" but the kernel likes it
	anyway, or presumably on 3rd/4th drives not described in the CMOS.

	One case where this can be puzzling is if you try to boot fd(0,a)
	from one of the install floppies with drive A: "not installed" -
	the boot proceeds fine as long as the BIOS(?) is doing the I/O,
	but the kernel panics once the regular driver tries to reference
	the passed boot device.  Since there's no (4)i386/fd manpage, the
	notion that /dev/fd?x refers to a density override rather than
	a partion isn't exposed, nor is this usage mentioned on the reboot
	manpage...
>How-To-Repeat:
	set your floppy drive A: to "not installed"
	boot
	diddle with /dev/fd0a
	panic
>Fix:
	work-around: take intense care to always use /dev/fd?[b-h], or
	link /dev/fd?a to /dev/fd?x as appropriate.

	fix: see attached diff - this seems to be a simple way to deal with
	the problem (thou shalt not panic) with no major downside, another
	would be to error-out the open if default density is requested and
	the type was posted as "unknown density".


*** src/sys/arch/i386/isa/fd.c	Sun Dec 18 13:03:43 1994
--- src/sys/arch/i386/isa/fd.c.dist	Sun Dec 18 12:52:38 1994
***************
*** 403,418 ****
  
  	/* XXXX should allow `flags' to override device type */
  
! 	if (!type) {
! 		printf(": density unknown, defaulting to");
! #if defined(FDDDENSITY)
! 		type = &fd_types[(FDDDENSITY)-1];	/* yeech */
! #else
! 		type = &fd_types[0];
! #endif
! 	}
! 	printf(": %s %d cyl, %d head, %d sec\n", type->name,
! 	    type->tracks, type->heads, type->sectrac);
  	fd->sc_track = -1;
  	fd->sc_drive = drive;
  	fd->sc_deftype = type;
--- 403,413 ----
  
  	/* XXXX should allow `flags' to override device type */
  
! 	if (type)
! 		printf(": %s %d cyl, %d head, %d sec\n", type->name,
! 		    type->tracks, type->heads, type->sectrac);
! 	else
! 		printf(": density unknown\n");
  	fd->sc_track = -1;
  	fd->sc_drive = drive;
  	fd->sc_deftype = type;
>Audit-Trail:
>Unformatted: