Thu Nov 20 03:42:11 2008 UTC ()
Pull up following revision(s) (requested by bouyer in ticket #97):
	sys/dev/vnd.c: revision 1.189
Check that vnd is not NULL before using it, return ENXIO if it is.
Avoids a panic when vnconfig -uF is used on a busy vnd.


(snj)
diff -r1.187 -r1.187.4.1 src/sys/dev/vnd.c

cvs diff -r1.187 -r1.187.4.1 src/sys/dev/vnd.c (expand / switch to unified diff)

--- src/sys/dev/vnd.c 2008/09/24 07:57:30 1.187
+++ src/sys/dev/vnd.c 2008/11/20 03:42:11 1.187.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vnd.c,v 1.187 2008/09/24 07:57:30 ad Exp $ */ 1/* $NetBSD: vnd.c,v 1.187.4.1 2008/11/20 03:42:11 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -120,27 +120,27 @@ @@ -120,27 +120,27 @@
120 * systems where the block-level operations are not implemented for 120 * systems where the block-level operations are not implemented for
121 * whatever reason. 121 * whatever reason.
122 * 122 *
123 * NOTE 2: There is a security issue involved with this driver. 123 * NOTE 2: There is a security issue involved with this driver.
124 * Once mounted all access to the contents of the "mapped" file via 124 * Once mounted all access to the contents of the "mapped" file via
125 * the special file is controlled by the permissions on the special 125 * the special file is controlled by the permissions on the special
126 * file, the protection of the mapped file is ignored (effectively, 126 * file, the protection of the mapped file is ignored (effectively,
127 * by using root credentials in all transactions). 127 * by using root credentials in all transactions).
128 * 128 *
129 * NOTE 3: Doesn't interact with leases, should it? 129 * NOTE 3: Doesn't interact with leases, should it?
130 */ 130 */
131 131
132#include <sys/cdefs.h> 132#include <sys/cdefs.h>
133__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.187 2008/09/24 07:57:30 ad Exp $"); 133__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.187.4.1 2008/11/20 03:42:11 snj Exp $");
134 134
135#if defined(_KERNEL_OPT) 135#if defined(_KERNEL_OPT)
136#include "fs_nfs.h" 136#include "fs_nfs.h"
137#include "opt_vnd.h" 137#include "opt_vnd.h"
138#endif 138#endif
139 139
140#include <sys/param.h> 140#include <sys/param.h>
141#include <sys/systm.h> 141#include <sys/systm.h>
142#include <sys/namei.h> 142#include <sys/namei.h>
143#include <sys/proc.h> 143#include <sys/proc.h>
144#include <sys/kthread.h> 144#include <sys/kthread.h>
145#include <sys/errno.h> 145#include <sys/errno.h>
146#include <sys/buf.h> 146#include <sys/buf.h>
@@ -438,30 +438,36 @@ vndclose(dev_t dev, int flags, int mode, @@ -438,30 +438,36 @@ vndclose(dev_t dev, int flags, int mode,
438 438
439 return (0); 439 return (0);
440} 440}
441 441
442/* 442/*
443 * Queue the request, and wakeup the kernel thread to handle it. 443 * Queue the request, and wakeup the kernel thread to handle it.
444 */ 444 */
445static void 445static void
446vndstrategy(struct buf *bp) 446vndstrategy(struct buf *bp)
447{ 447{
448 int unit = vndunit(bp->b_dev); 448 int unit = vndunit(bp->b_dev);
449 struct vnd_softc *vnd = 449 struct vnd_softc *vnd =
450 device_lookup_private(&vnd_cd, unit); 450 device_lookup_private(&vnd_cd, unit);
451 struct disklabel *lp = vnd->sc_dkdev.dk_label; 451 struct disklabel *lp;
452 daddr_t blkno; 452 daddr_t blkno;
453 int s = splbio(); 453 int s = splbio();
454 454
 455 if (vnd == NULL) {
 456 bp->b_error = ENXIO;
 457 goto done;
 458 }
 459 lp = vnd->sc_dkdev.dk_label;
 460
455 if ((vnd->sc_flags & VNF_INITED) == 0) { 461 if ((vnd->sc_flags & VNF_INITED) == 0) {
456 bp->b_error = ENXIO; 462 bp->b_error = ENXIO;
457 goto done; 463 goto done;
458 } 464 }
459 465
460 /* 466 /*
461 * The transfer must be a whole number of blocks. 467 * The transfer must be a whole number of blocks.
462 */ 468 */
463 if ((bp->b_bcount % lp->d_secsize) != 0) { 469 if ((bp->b_bcount % lp->d_secsize) != 0) {
464 bp->b_error = EINVAL; 470 bp->b_error = EINVAL;
465 goto done; 471 goto done;
466 } 472 }
467 473