diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2010-09-23 18:49:40 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2010-09-23 18:49:40 +0000 |
commit | 206df040f0a173a6703ddff05fccef9372353b2e (patch) | |
tree | 5dfcd2b0e5fb6c546670363aba8abddd0c671cc4 /sys/dev | |
parent | cff1a3e5da18708311dbb5d2fb178a800b031333 (diff) |
The only sensible argument for VOP_* calls that take a struct proc pointer is
curproc. A bunch of callers were passing in 0 (not even NULL, 0) as this
pointer, which was fine until the called vnode function tried to do
something with it. Typically, this code was then copy/pasted to various
parts of the tree.
Accept the facts of life and switch all of these over to passing curproc
for now until the argument can be removed.
Discovered by stsp trying to create a softraid on top of a vnd, which
crashed with a NULL deref in vndioctl.
softraid bits tested by mikeb and jsing. raidframe bits tested by pea,
matthieu and naddy. The rest tested by at least thib, jsing and myself.
ok thib@, jsing@.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/raidframe/rf_disks.c | 4 | ||||
-rw-r--r-- | sys/dev/raidframe/rf_openbsdkintf.c | 14 | ||||
-rw-r--r-- | sys/dev/softraid.c | 45 | ||||
-rw-r--r-- | sys/dev/softraid_crypto.c | 20 |
4 files changed, 45 insertions, 38 deletions
diff --git a/sys/dev/raidframe/rf_disks.c b/sys/dev/raidframe/rf_disks.c index fefce52be6b..56e7dc1d32c 100644 --- a/sys/dev/raidframe/rf_disks.c +++ b/sys/dev/raidframe/rf_disks.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rf_disks.c,v 1.14 2010/05/23 13:49:35 naddy Exp $ */ +/* $OpenBSD: rf_disks.c,v 1.15 2010/09/23 18:49:39 oga Exp $ */ /* $NetBSD: rf_disks.c,v 1.31 2000/06/02 01:17:14 oster Exp $ */ /* @@ -598,7 +598,7 @@ rf_AutoConfigureDisks(RF_Raid_t *raidPtr, RF_Config_t *cfgPtr, ac = auto_config; while(ac != NULL) { if (ac->flag == 0) { - VOP_CLOSE(ac->vp, FREAD, NOCRED, 0); + VOP_CLOSE(ac->vp, FREAD, NOCRED, curproc); vput(ac->vp); ac->vp = NULL; #if DEBUG diff --git a/sys/dev/raidframe/rf_openbsdkintf.c b/sys/dev/raidframe/rf_openbsdkintf.c index 992ae78364b..51a8bd787e3 100644 --- a/sys/dev/raidframe/rf_openbsdkintf.c +++ b/sys/dev/raidframe/rf_openbsdkintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rf_openbsdkintf.c,v 1.59 2010/09/22 01:18:57 matthew Exp $ */ +/* $OpenBSD: rf_openbsdkintf.c,v 1.60 2010/09/23 18:49:39 oga Exp $ */ /* $NetBSD: rf_netbsdkintf.c,v 1.109 2001/07/27 03:30:07 oster Exp $ */ /*- @@ -2720,7 +2720,7 @@ rf_find_raid_components(void) if (bdevvp(dev, &vp)) panic("RAID can't alloc vnode"); - error = VOP_OPEN(vp, FREAD, NOCRED, 0); + error = VOP_OPEN(vp, FREAD, NOCRED, curproc); if (error) { /* @@ -2733,7 +2733,7 @@ rf_find_raid_components(void) /* Ok, the disk exists. Go get the disklabel. */ error = VOP_IOCTL(vp, DIOCGDINFO, (caddr_t)&label, - FREAD, NOCRED, 0); + FREAD, NOCRED, curproc); if (error) { /* * XXX can't happen - open() would @@ -2747,7 +2747,7 @@ rf_find_raid_components(void) * We don't need this any more. We'll allocate it again * a little later if we really do... */ - VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, curproc); vrele(vp); for (i=0; i < label.d_npartitions; i++) { @@ -2770,7 +2770,7 @@ rf_find_raid_components(void) if (bdevvp(dev, &vp)) panic("RAID can't alloc vnode"); - error = VOP_OPEN(vp, FREAD, NOCRED, 0); + error = VOP_OPEN(vp, FREAD, NOCRED, curproc); if (error) { /* Whatever... */ vput(vp); @@ -2825,7 +2825,7 @@ rf_find_raid_components(void) if (!good_one) { /* Cleanup. */ free(clabel, M_RAIDFRAME); - VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, curproc); vrele(vp); } } @@ -3328,7 +3328,7 @@ rf_release_all_vps(RF_ConfigSet_t *cset) while(ac!=NULL) { /* Close the vp, and give it back. */ if (ac->vp) { - VOP_CLOSE(ac->vp, FREAD, NOCRED, 0); + VOP_CLOSE(ac->vp, FREAD, NOCRED, curproc); vrele(ac->vp); ac->vp = NULL; } diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index f86d0fcc94b..df9d63562a9 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.213 2010/09/07 17:14:06 deraadt Exp $ */ +/* $OpenBSD: softraid.c,v 1.214 2010/09/23 18:49:39 oga Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -322,7 +322,7 @@ sr_meta_probe(struct sr_discipline *sd, dev_t *dt, int no_chunk) * XXX leaving dev open for now; move this to attach * and figure out the open/close dance for unwind. */ - error = VOP_OPEN(vn, FREAD | FWRITE, NOCRED, 0); + error = VOP_OPEN(vn, FREAD | FWRITE, NOCRED, curproc); if (error) { DNPRINTF(SR_D_META,"%s: sr_meta_probe can't " "open %s\n", DEVNAME(sc), devname); @@ -900,7 +900,7 @@ sr_meta_native_bootprobe(struct sr_softc *sc, dev_t devno, } /* open device */ - error = VOP_OPEN(vn, FREAD, NOCRED, 0); + error = VOP_OPEN(vn, FREAD, NOCRED, curproc); if (error) { DNPRINTF(SR_D_META, "%s: sr_meta_native_bootprobe open " "failed\n", DEVNAME(sc)); @@ -909,17 +909,18 @@ sr_meta_native_bootprobe(struct sr_softc *sc, dev_t devno, } /* get disklabel */ - error = VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, NOCRED, 0); + error = VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, NOCRED, + curproc); if (error) { DNPRINTF(SR_D_META, "%s: sr_meta_native_bootprobe ioctl " "failed\n", DEVNAME(sc)); - VOP_CLOSE(vn, FREAD, NOCRED, 0); + VOP_CLOSE(vn, FREAD, NOCRED, curproc); vput(vn); goto done; } /* we are done, close device */ - error = VOP_CLOSE(vn, FREAD, NOCRED, 0); + error = VOP_CLOSE(vn, FREAD, NOCRED, curproc); if (error) { DNPRINTF(SR_D_META, "%s: sr_meta_native_bootprobe close " "failed\n", DEVNAME(sc)); @@ -957,7 +958,7 @@ sr_meta_native_bootprobe(struct sr_softc *sc, dev_t devno, "vnode for partition\n", DEVNAME(sc)); goto done; } - error = VOP_OPEN(vn, FREAD, NOCRED, 0); + error = VOP_OPEN(vn, FREAD, NOCRED, curproc); if (error) { DNPRINTF(SR_D_META, "%s: sr_meta_native_bootprobe " "open failed, partition %d\n", @@ -969,14 +970,14 @@ sr_meta_native_bootprobe(struct sr_softc *sc, dev_t devno, if (sr_meta_native_read(fake_sd, rawdev, md, NULL)) { printf("%s: native bootprobe could not read native " "metadata\n", DEVNAME(sc)); - VOP_CLOSE(vn, FREAD, NOCRED, 0); + VOP_CLOSE(vn, FREAD, NOCRED, curproc); vput(vn); continue; } /* are we a softraid partition? */ if (md->ssdi.ssd_magic != SR_MAGIC) { - VOP_CLOSE(vn, FREAD, NOCRED, 0); + VOP_CLOSE(vn, FREAD, NOCRED, curproc); vput(vn); continue; } @@ -999,7 +1000,7 @@ sr_meta_native_bootprobe(struct sr_softc *sc, dev_t devno, } /* we are done, close partition */ - VOP_CLOSE(vn, FREAD, NOCRED, 0); + VOP_CLOSE(vn, FREAD, NOCRED, curproc); vput(vn); } @@ -1368,7 +1369,7 @@ sr_meta_native_probe(struct sr_softc *sc, struct sr_chunk *ch_entry) /* get disklabel */ error = VOP_IOCTL(ch_entry->src_vn, DIOCGDINFO, (caddr_t)&label, FREAD, - NOCRED, 0); + NOCRED, curproc); if (error) { DNPRINTF(SR_D_META, "%s: %s can't obtain disklabel\n", DEVNAME(sc), devname); @@ -2374,7 +2375,7 @@ sr_hotspare(struct sr_softc *sc, dev_t dev) printf("%s:, sr_hotspare: can't allocate vnode\n", DEVNAME(sc)); goto done; } - if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, 0)) { + if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, curproc)) { DNPRINTF(SR_D_META,"%s: sr_hotspare cannot open %s\n", DEVNAME(sc), devname); vput(vn); @@ -2384,10 +2385,11 @@ sr_hotspare(struct sr_softc *sc, dev_t dev) /* Get partition details. */ part = DISKPART(dev); - if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, NOCRED, 0)) { + if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, + NOCRED, curproc)) { DNPRINTF(SR_D_META, "%s: sr_hotspare ioctl failed\n", DEVNAME(sc)); - VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, curproc); vput(vn); goto fail; } @@ -2498,7 +2500,7 @@ done: if (sm) free(sm, M_DEVBUF); if (open) { - VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, curproc); vput(vn); } @@ -2671,7 +2673,7 @@ sr_rebuild_init(struct sr_discipline *sd, dev_t dev, int hotspare) goto done; } - if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, 0)) { + if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, curproc)) { DNPRINTF(SR_D_META,"%s: sr_ioctl_setstate can't " "open %s\n", DEVNAME(sc), devname); vput(vn); @@ -2681,7 +2683,8 @@ sr_rebuild_init(struct sr_discipline *sd, dev_t dev, int hotspare) /* get partition */ part = DISKPART(dev); - if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, NOCRED, 0)) { + if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, + NOCRED, curproc)) { DNPRINTF(SR_D_META, "%s: sr_ioctl_setstate ioctl failed\n", DEVNAME(sc)); goto done; @@ -2745,7 +2748,7 @@ sr_rebuild_init(struct sr_discipline *sd, dev_t dev, int hotspare) rv = 0; done: if (open) { - VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, curproc); vput(vn); } @@ -3318,8 +3321,10 @@ sr_chunks_unwind(struct sr_softc *sc, struct sr_chunk_head *cl) * the problem introduced by vnode aliasing... specfs * has no locking, whereas ufs/ffs does! */ - vn_lock(ch_entry->src_vn, LK_EXCLUSIVE | LK_RETRY, 0); - VOP_CLOSE(ch_entry->src_vn, FREAD | FWRITE, NOCRED, 0); + vn_lock(ch_entry->src_vn, LK_EXCLUSIVE | + LK_RETRY, curproc); + VOP_CLOSE(ch_entry->src_vn, FREAD | FWRITE, NOCRED, + curproc); vput(ch_entry->src_vn); } free(ch_entry, M_DEVBUF); diff --git a/sys/dev/softraid_crypto.c b/sys/dev/softraid_crypto.c index 18e0cbc76c3..581daeef5fc 100644 --- a/sys/dev/softraid_crypto.c +++ b/sys/dev/softraid_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid_crypto.c,v 1.54 2010/07/02 09:26:05 jsing Exp $ */ +/* $OpenBSD: softraid_crypto.c,v 1.55 2010/09/23 18:49:39 oga Exp $ */ /* * Copyright (c) 2007 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Hans-Joerg Hoexer <hshoexer@openbsd.org> @@ -674,7 +674,7 @@ sr_crypto_create_key_disk(struct sr_discipline *sd, dev_t dev) DEVNAME(sc)); goto done; } - if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, 0)) { + if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, curproc)) { DNPRINTF(SR_D_META,"%s: sr_create_key_disk cannot open %s\n", DEVNAME(sc), devname); vput(vn); @@ -684,10 +684,11 @@ sr_crypto_create_key_disk(struct sr_discipline *sd, dev_t dev) /* Get partition details. */ part = DISKPART(dev); - if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, NOCRED, 0)) { + if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, + FREAD, NOCRED, curproc)) { DNPRINTF(SR_D_META, "%s: sr_create_key_disk ioctl failed\n", DEVNAME(sc)); - VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, curproc); vput(vn); goto fail; } @@ -798,7 +799,7 @@ done: if (sm) free(sm, M_DEVBUF); if (open) { - VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, curproc); vput(vn); } @@ -836,7 +837,7 @@ sr_crypto_read_key_disk(struct sr_discipline *sd, dev_t dev) DEVNAME(sc)); goto done; } - if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, 0)) { + if (VOP_OPEN(vn, FREAD | FWRITE, NOCRED, curproc)) { DNPRINTF(SR_D_META,"%s: sr_create_key_disk cannot open %s\n", DEVNAME(sc), devname); vput(vn); @@ -846,10 +847,11 @@ sr_crypto_read_key_disk(struct sr_discipline *sd, dev_t dev) /* Get partition details. */ part = DISKPART(dev); - if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, NOCRED, 0)) { + if (VOP_IOCTL(vn, DIOCGDINFO, (caddr_t)&label, FREAD, + NOCRED, curproc)) { DNPRINTF(SR_D_META, "%s: sr_create_key_disk ioctl failed\n", DEVNAME(sc)); - VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, 0); + VOP_CLOSE(vn, FREAD | FWRITE, NOCRED, curproc); vput(vn); goto done; } @@ -928,7 +930,7 @@ done: free(sm, M_DEVBUF); if (vn && open) { - VOP_CLOSE(vn, FREAD, NOCRED, 0); + VOP_CLOSE(vn, FREAD, NOCRED, curproc); vput(vn); } |