From owner-freebsd-bugs@FreeBSD.ORG Sat May 17 00:19:16 2003 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 764DE37B401; Sat, 17 May 2003 00:19:16 -0700 (PDT) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 28EF343F85; Sat, 17 May 2003 00:19:15 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id RAA20515; Sat, 17 May 2003 17:18:58 +1000 Date: Sat, 17 May 2003 17:18:57 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Yar Tikhiy In-Reply-To: <200305161646.h4GGkdDS000677@stylish.chem.msu.su> Message-ID: <20030517165718.B15076@gamplex.bde.org> References: <200305161646.h4GGkdDS000677@stylish.chem.msu.su> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-bugs@freebsd.org cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: kern/52338: fd(4) floppy disk driver & non-blocking I/O X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 May 2003 07:19:17 -0000 On Fri, 16 May 2003, Yar Tikhiy wrote: > >Description: > > If /dev/fdX has been opened in non-blocking mode, the > inserted floppy type will never be autoselected. So trying > to get its parameters through DIOCGSECTORSIZE or DIOCGMEDIASIZE > will cause panic on dereferencing the NULL fd->ft pointer. > And reading from or writing to its descriptor will result > in the ENXIO (Device not configured) error. I made the obvious quick for for the null pointer panics when they were implemented: %%% Index: fd.c =================================================================== RCS file: /home/ncvs/src/sys/isa/fd.c,v retrieving revision 1.244 diff -u -2 -r1.244 fd.c --- fd.c 11 Jan 2003 20:10:41 -0000 1.244 +++ fd.c 11 Jan 2003 21:02:32 -0000 @@ -2623,12 +2788,22 @@ * FD_NONBLOCK still being set. */ - switch (cmd) { +#ifdef TEST_LABELLING + /* XXX only some slice ioctls are non-blocking. */ + error = dsioctl(dev, cmd, addr, flag, &fd->slices); + if (error != ENOIOCTL) + return (error); +#endif + switch (cmd) { case DIOCGMEDIASIZE: - *(off_t *)addr = (128 << (fd->ft->secsize)) * fd->ft->size; + if (fd->ft == 0) + return (ENXIO); + *(off_t *)addr = (128 << fd->ft->secsize) * fd->ft->size; return (0); case DIOCGSECTORSIZE: - *(u_int *)addr = 128 << (fd->ft->secsize); + if (fd->ft == 0) + return (ENXIO); + *(u_int *)addr = 128 << fd->ft->secsize; return (0); %%% Other changes in this patch: - local code (TEST_LABELLING). - fix 2 style bugs (excessive parentheses). Style bugs in this patch: - '0' is used for a null pointer constant to give bug for bug compatibility with other checks for fd->ft being a null pointer. Not autoselecting for the O_NONBLOCK case seems to be a feature. Autoselecting requires even more blocking than does starting the motor, and it would be just bogus to autoselect for an open whose purpose is to set the type. fd->ft may be NULL for other reasons, so the null pointer checks are needed no matter how O_NONBLOCK is handled. Bruce