Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/miscfs/specfs in spec_ioctl(), don't dereference v_speci...



details:   https://anonhg.NetBSD.org/src/rev/3d5b970f6e32
branches:  trunk
changeset: 584212:3d5b970f6e32
user:      chs <chs%NetBSD.org@localhost>
date:      Sun Sep 11 14:18:54 2005 +0000

description:
in spec_ioctl(), don't dereference v_specinfo if it's NULL.
this is needed due to rev. 1.231 of kern/vfs_subr.c, which now sets
v_specinfo to NULL before changing the vnode's ops vector.

diffstat:

 sys/miscfs/specfs/spec_vnops.c |  25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r 63acbe0def2d -r 3d5b970f6e32 sys/miscfs/specfs/spec_vnops.c
--- a/sys/miscfs/specfs/spec_vnops.c    Sun Sep 11 13:42:40 2005 +0000
+++ b/sys/miscfs/specfs/spec_vnops.c    Sun Sep 11 14:18:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spec_vnops.c,v 1.82 2005/08/30 20:08:01 xtraeme Exp $  */
+/*     $NetBSD: spec_vnops.c,v 1.83 2005/09/11 14:18:54 chs Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.82 2005/08/30 20:08:01 xtraeme Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.83 2005/09/11 14:18:54 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -461,9 +461,26 @@
        } */ *ap = v;
        const struct bdevsw *bdev;
        const struct cdevsw *cdev;
-       dev_t dev = ap->a_vp->v_rdev;
+       struct vnode *vp;
+       dev_t dev;
+
+       /*
+        * Extract all the info we need from the vnode, taking care to
+        * avoid a race with VOP_REVOKE().
+        */
 
-       switch (ap->a_vp->v_type) {
+       vp = ap->a_vp;
+       dev = NODEV;
+       simple_lock(&vp->v_interlock);
+       if ((vp->v_flag & VXLOCK) == 0 && vp->v_specinfo) {
+               dev = vp->v_rdev;
+       }
+       simple_unlock(&vp->v_interlock);
+       if (dev == NODEV) {
+               return ENXIO;
+       }
+
+       switch (vp->v_type) {
 
        case VCHR:
                cdev = cdevsw_lookup(dev);



Home | Main Index | Thread Index | Old Index