diff options
-rw-r--r-- | sys/arch/hp300/dev/hd.c | 34 | ||||
-rw-r--r-- | sys/arch/octeon/dev/octcf.c | 33 | ||||
-rw-r--r-- | sys/arch/sparc/dev/presto.c | 16 | ||||
-rw-r--r-- | sys/arch/sparc/dev/xd.c | 24 | ||||
-rw-r--r-- | sys/arch/sparc/dev/xy.c | 24 | ||||
-rw-r--r-- | sys/arch/vax/mscp/mscp_disk.c | 20 | ||||
-rw-r--r-- | sys/arch/vax/vsa/hdc9224.c | 11 | ||||
-rw-r--r-- | sys/dev/ata/wd.c | 32 | ||||
-rw-r--r-- | sys/dev/ccd.c | 21 | ||||
-rw-r--r-- | sys/dev/flash.c | 28 | ||||
-rw-r--r-- | sys/dev/raidframe/rf_openbsdkintf.c | 4 | ||||
-rw-r--r-- | sys/dev/rd.c | 20 | ||||
-rw-r--r-- | sys/dev/vnd.c | 4 | ||||
-rw-r--r-- | sys/kern/subr_disk.c | 4 | ||||
-rw-r--r-- | sys/scsi/cd.c | 28 | ||||
-rw-r--r-- | sys/scsi/sd.c | 28 |
16 files changed, 104 insertions, 227 deletions
diff --git a/sys/arch/hp300/dev/hd.c b/sys/arch/hp300/dev/hd.c index 3f9d01610a0..e07497b4ceb 100644 --- a/sys/arch/hp300/dev/hd.c +++ b/sys/arch/hp300/dev/hd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hd.c,v 1.68 2011/06/19 21:20:04 miod Exp $ */ +/* $OpenBSD: hd.c,v 1.69 2011/07/06 04:49:35 matthew Exp $ */ /* $NetBSD: rd.c,v 1.33 1997/07/10 18:14:08 kleink Exp $ */ /* @@ -650,7 +650,6 @@ hdstrategy(bp) int unit = DISKUNIT(bp->b_dev); struct hd_softc *rs; struct buf *dp; - struct disklabel *lp; int s; rs = hdlookup(unit); @@ -666,27 +665,8 @@ hdstrategy(bp) (bp->b_flags & B_READ) ? 'R' : 'W'); #endif - lp = rs->sc_dkdev.dk_label; - - /* - * If it's a null transfer, return immediately - */ - if (bp->b_bcount == 0) - goto done; - - /* - * The transfer must be a whole number of blocks. - */ - if ((bp->b_bcount % lp->d_secsize) != 0) { - bp->b_error = EINVAL; - goto bad; - } - - /* - * Do bounds checking, adjust transfer. if error, process; - * If end of partition, just return. - */ - if (bounds_check_with_label(bp, lp) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, rs->sc_dkdev.dk_label) == -1) goto done; s = splbio(); @@ -700,13 +680,11 @@ hdstrategy(bp) device_unref(&rs->sc_dev); return; -bad: + + bad: bp->b_flags |= B_ERROR; -done: - /* - * Correctly set the buf to indicate a completed xfer - */ bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/arch/octeon/dev/octcf.c b/sys/arch/octeon/dev/octcf.c index a6879e15e0f..ccba97d1063 100644 --- a/sys/arch/octeon/dev/octcf.c +++ b/sys/arch/octeon/dev/octcf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: octcf.c,v 1.6 2011/06/19 04:55:34 deraadt Exp $ */ +/* $OpenBSD: octcf.c,v 1.7 2011/07/06 04:49:35 matthew Exp $ */ /* $NetBSD: wd.c,v 1.193 1999/02/28 17:15:27 explorer Exp $ */ /* @@ -302,27 +302,22 @@ octcfstrategy(struct buf *bp) } OCTCFDEBUG_PRINT(("octcfstrategy (%s)\n", wd->sc_dev.dv_xname), DEBUG_XFERS); - /* Valid request? */ - if (bp->b_blkno < 0 || - (bp->b_bcount % wd->sc_dk.dk_label->d_secsize) != 0 || - (bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) { - bp->b_error = EINVAL; - goto bad; - } /* If device invalidated (e.g. media change, door open), error. */ if ((wd->sc_flags & OCTCFF_LOADED) == 0) { bp->b_error = EIO; goto bad; } - /* If it's a null transfer, return immediately. */ - if (bp->b_bcount == 0) - goto done; - /* - * Do bounds checking, adjust transfer. if error, process. - * If end of partition, just return. - */ - if (bounds_check_with_label(bp, wd->sc_dk.dk_label) <= 0) + + /* Validate the request. */ + if (bounds_check_with_label(bp, wd->sc_dk.dk_label) == -1) goto done; + + /* Check that the number of sectors can fit in a byte. */ + if ((bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) { + bp->b_error = EINVAL; + goto bad; + } + /* Queue transfer on drive, activate drive and controller if idle. */ s = splbio(); disksort(&wd->sc_q, bp); @@ -330,11 +325,11 @@ octcfstrategy(struct buf *bp) splx(s); device_unref(&wd->sc_dev); return; -bad: + + bad: bp->b_flags |= B_ERROR; -done: - /* Toss transfer; we're done early. */ bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/arch/sparc/dev/presto.c b/sys/arch/sparc/dev/presto.c index f9d05429d4c..b242ce3fd97 100644 --- a/sys/arch/sparc/dev/presto.c +++ b/sys/arch/sparc/dev/presto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: presto.c,v 1.21 2011/06/03 21:14:11 matthew Exp $ */ +/* $OpenBSD: presto.c,v 1.22 2011/07/06 04:49:35 matthew Exp $ */ /* * Copyright (c) 2003, Miodrag Vallat. * All rights reserved. @@ -280,15 +280,14 @@ prestostrategy(struct buf *bp) sc = (struct presto_softc *)device_lookup(&presto_cd, unit); /* Sort rogue requests out */ - if (sc == NULL || bp->b_blkno < 0 || - (bp->b_bcount % sc->sc_dk.dk_label->d_secsize) != 0) { + if (sc == NULL) { bp->b_error = EINVAL; goto bad; } - /* Do not write on "no trespassing" areas... */ - if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0) - goto bad; + /* Validate the request. */ + if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) + goto done; /* Bound the request size, then move data between buf and nvram */ bp->b_resid = bp->b_bcount; @@ -303,11 +302,10 @@ prestostrategy(struct buf *bp) bp->b_resid -= count; goto done; -bad: + bad: bp->b_flags |= B_ERROR; bp->b_resid = bp->b_bcount; - -done: + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/arch/sparc/dev/xd.c b/sys/arch/sparc/dev/xd.c index af721ed86e2..166dee9db63 100644 --- a/sys/arch/sparc/dev/xd.c +++ b/sys/arch/sparc/dev/xd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xd.c,v 1.55 2011/06/05 18:40:33 matthew Exp $ */ +/* $OpenBSD: xd.c,v 1.56 2011/07/06 04:49:35 matthew Exp $ */ /* $NetBSD: xd.c,v 1.37 1997/07/29 09:58:16 fair Exp $ */ /* @@ -1011,9 +1011,7 @@ xdstrategy(bp) /* check for live device */ - if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == 0 || - bp->b_blkno < 0 || - (bp->b_bcount % xd->sc_dk.dk_label->d_secsize) != 0) { + if (unit >= xd_cd.cd_ndevs || (xd = xd_cd.cd_devs[unit]) == 0) { bp->b_error = EINVAL; goto bad; } @@ -1036,17 +1034,9 @@ xdstrategy(bp) bp->b_error = EIO; goto bad; } - /* short circuit zero length request */ - if (bp->b_bcount == 0) - goto done; - - /* check bounds with label (disksubr.c). Determine the size of the - * transfer, and make sure it is within the boundaries of the - * partition. Adjust transfer if needed, and signal errors or early - * completion. */ - - if (bounds_check_with_label(bp, xd->sc_dk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, xd->sc_dk.dk_label) == -1) goto done; /* @@ -1090,11 +1080,11 @@ xdstrategy(bp) splx(s); return; -bad: /* tells upper layers we have an error */ + bad: /* tells upper layers we have an error */ bp->b_flags |= B_ERROR; -done: /* tells upper layers we are done with this - * buf */ bp->b_resid = bp->b_bcount; + done: /* tells upper layers we are done with this + * buf */ s = splbio(); biodone(bp); splx(s); diff --git a/sys/arch/sparc/dev/xy.c b/sys/arch/sparc/dev/xy.c index 071f98fc864..24dc1510bec 100644 --- a/sys/arch/sparc/dev/xy.c +++ b/sys/arch/sparc/dev/xy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xy.c,v 1.52 2011/06/05 18:40:33 matthew Exp $ */ +/* $OpenBSD: xy.c,v 1.53 2011/07/06 04:49:35 matthew Exp $ */ /* $NetBSD: xy.c,v 1.26 1997/07/19 21:43:56 pk Exp $ */ /* @@ -974,9 +974,7 @@ xystrategy(bp) /* check for live device */ - if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == 0 || - bp->b_blkno < 0 || - (bp->b_bcount % xy->sc_dk.dk_label->d_secsize) != 0) { + if (unit >= xy_cd.cd_ndevs || (xy = xy_cd.cd_devs[unit]) == 0) { bp->b_error = EINVAL; goto bad; } @@ -999,17 +997,9 @@ xystrategy(bp) bp->b_error = EIO; goto bad; } - /* short circuit zero length request */ - if (bp->b_bcount == 0) - goto done; - - /* check bounds with label (disksubr.c). Determine the size of the - * transfer, and make sure it is within the boundaries of the - * partition. Adjust transfer if needed, and signal errors or early - * completion. */ - - if (bounds_check_with_label(bp, xy->sc_dk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, xy->sc_dk.dk_label) == -1) goto done; /* @@ -1029,11 +1019,11 @@ xystrategy(bp) splx(s); return; -bad: /* tells upper layers we have an error */ + bad: /* tells upper layers we have an error */ bp->b_flags |= B_ERROR; -done: /* tells upper layers we are done with this - * buf */ bp->b_resid = bp->b_bcount; + done: /* tells upper layers we are done with this + * buf */ s = splbio(); biodone(bp); splx(s); diff --git a/sys/arch/vax/mscp/mscp_disk.c b/sys/arch/vax/mscp/mscp_disk.c index b4cb3da23f3..c9bc08d52fa 100644 --- a/sys/arch/vax/mscp/mscp_disk.c +++ b/sys/arch/vax/mscp/mscp_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mscp_disk.c,v 1.36 2011/07/05 21:39:08 krw Exp $ */ +/* $OpenBSD: mscp_disk.c,v 1.37 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: mscp_disk.c,v 1.30 2001/11/13 07:38:28 lukem Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. @@ -286,8 +286,7 @@ rastrategy(bp) unit = DISKUNIT(bp->b_dev); if (unit >= ra_cd.cd_ndevs || (ra = ra_cd.cd_devs[unit]) == NULL) { bp->b_error = ENXIO; - bp->b_flags |= B_ERROR; - goto done; + goto bad; } /* * If drive is open `raw' or reading label, let it at it. @@ -303,16 +302,12 @@ rastrategy(bp) /* If disk is not online, try to put it online */ if (ra->ra_state == DK_CLOSED) if (ra_putonline(ra) == MSCP_FAILED) { - bp->b_flags |= B_ERROR; bp->b_error = EIO; - goto done; + goto bad; } - /* - * Determine the size of the transfer, and make sure it is - * within the boundaries of the partition. - */ - if (bounds_check_with_label(bp, ra->ra_disk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, ra->ra_disk.dk_label) == -1) goto done; /* Make some statistics... /bqt */ @@ -322,7 +317,10 @@ rastrategy(bp) mscp_strategy(bp, ra->ra_dev.dv_parent); return; -done: + bad: + bp->b_flags |= B_ERROR; + bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/arch/vax/vsa/hdc9224.c b/sys/arch/vax/vsa/hdc9224.c index bf95d76b523..6f8921f4666 100644 --- a/sys/arch/vax/vsa/hdc9224.c +++ b/sys/arch/vax/vsa/hdc9224.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hdc9224.c,v 1.36 2011/06/05 18:40:33 matthew Exp $ */ +/* $OpenBSD: hdc9224.c,v 1.37 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: hdc9224.c,v 1.16 2001/07/26 15:05:09 wiz Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. @@ -440,22 +440,19 @@ hdstrategy(struct buf *bp) { struct hdsoftc *hd; struct hdcsoftc *sc; - struct disklabel *lp; int unit, s; unit = DISKUNIT(bp->b_dev); if (unit > hd_cd.cd_ndevs || (hd = hd_cd.cd_devs[unit]) == NULL) { bp->b_error = ENXIO; bp->b_flags |= B_ERROR; + bp->b_resid = bp->b_bcount; goto done; } sc = (void *)hd->sc_dev.dv_parent; - lp = hd->sc_disk.dk_label; - if ((bounds_check_with_label(bp, hd->sc_disk.dk_label)) <= 0) - goto done; - - if (bp->b_bcount == 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, hd->sc_disk.dk_label) == -1) goto done; s = splbio(); diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c index e3499ca6d44..2e1c23b920b 100644 --- a/sys/dev/ata/wd.c +++ b/sys/dev/ata/wd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wd.c,v 1.107 2011/06/30 16:28:05 matthew Exp $ */ +/* $OpenBSD: wd.c,v 1.108 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: wd.c,v 1.193 1999/02/28 17:15:27 explorer Exp $ */ /* @@ -407,30 +407,22 @@ wdstrategy(struct buf *bp) WDCDEBUG_PRINT(("wdstrategy (%s)\n", wd->sc_dev.dv_xname), DEBUG_XFERS); - /* Valid request? */ - if (bp->b_blkno < 0 || - (bp->b_bcount % wd->sc_dk.dk_label->d_secsize) != 0 || - (bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) { - bp->b_error = EINVAL; - goto bad; - } - /* If device invalidated (e.g. media change, door open), error. */ if ((wd->sc_flags & WDF_LOADED) == 0) { bp->b_error = EIO; goto bad; } - /* If it's a null transfer, return immediately. */ - if (bp->b_bcount == 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, wd->sc_dk.dk_label) == -1) goto done; - /* - * Do bounds checking, adjust transfer. if error, process. - * If end of partition, just return. - */ - if (bounds_check_with_label(bp, wd->sc_dk.dk_label) <= 0) - goto done; + /* Check that the number of sectors can fit in a byte. */ + if ((bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) { + bp->b_error = EINVAL; + goto bad; + } + /* Queue transfer on drive, activate drive and controller if idle. */ bufq_queue(&wd->sc_bufq, bp); s = splbio(); @@ -438,11 +430,11 @@ wdstrategy(struct buf *bp) splx(s); device_unref(&wd->sc_dev); return; -bad: + + bad: bp->b_flags |= B_ERROR; -done: - /* Toss transfer; we're done early. */ bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/dev/ccd.c b/sys/dev/ccd.c index dd678022a24..9f6a0bb04a7 100644 --- a/sys/dev/ccd.c +++ b/sys/dev/ccd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccd.c,v 1.96 2011/06/30 16:28:05 matthew Exp $ */ +/* $OpenBSD: ccd.c,v 1.97 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: ccd.c,v 1.33 1996/05/05 04:21:14 thorpej Exp $ */ /*- @@ -614,28 +614,18 @@ ccdstrategy(struct buf *bp) int unit = DISKUNIT(bp->b_dev); struct ccd_softc *cs = &ccd_softc[unit]; int s; - struct disklabel *lp; CCD_DPRINTF(CCDB_FOLLOW, ("ccdstrategy(%p): unit %d\n", bp, unit)); if ((cs->sc_flags & CCDF_INITED) == 0) { bp->b_error = ENXIO; - bp->b_resid = bp->b_bcount; bp->b_flags |= B_ERROR; + bp->b_resid = bp->b_bcount; goto done; } - /* If it's a nil transfer, wake up the top half now. */ - if (bp->b_bcount == 0) - goto done; - - lp = cs->sc_dkdev.dk_label; - - /* - * Do bounds checking and adjust transfer. If there's an - * error, the bounds check will flag that for us. - */ - if (bounds_check_with_label(bp, lp) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, cs->sc_dkdev.dk_label) == -1) goto done; bp->b_resid = bp->b_bcount; @@ -647,7 +637,8 @@ ccdstrategy(struct buf *bp) ccdstart(cs, bp); splx(s); return; -done: + + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/dev/flash.c b/sys/dev/flash.c index 27215ce1c14..8f5dd8dd48f 100644 --- a/sys/dev/flash.c +++ b/sys/dev/flash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: flash.c,v 1.23 2011/06/19 04:55:33 deraadt Exp $ */ +/* $OpenBSD: flash.c,v 1.24 2011/07/06 04:49:36 matthew Exp $ */ /* * Copyright (c) 2005 Uwe Stuehler <uwe@openbsd.org> @@ -784,12 +784,6 @@ flashstrategy(struct buf *bp) goto bad; } - /* Transfer only a multiple of the flash page size. */ - if ((bp->b_bcount % sc->sc_flashdev->pagesize) != 0) { - bp->b_error = EINVAL; - goto bad; - } - /* If the device has been invalidated, error out. */ if ((sc->sc_flags & FDK_LOADED) == 0) { bp->b_error = EIO; @@ -797,15 +791,14 @@ flashstrategy(struct buf *bp) } /* Translate logical block numbers to physical. */ - if (flashsafe(bp->b_dev) && flashsafestrategy(sc, bp) <= 0) - goto done; - - /* Return immediately if it is a null transfer. */ - if (bp->b_bcount == 0) + if (flashsafe(bp->b_dev) && flashsafestrategy(sc, bp) <= 0) { + if (bp->b_flags & B_ERROR) + bp->b_resid = bp->b_bcount; goto done; + } - /* Do bounds checking on partitions. */ - if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) goto done; /* Queue the transfer. */ @@ -816,11 +809,10 @@ flashstrategy(struct buf *bp) device_unref(&sc->sc_dev); return; -bad: + bad: bp->b_flags |= B_ERROR; -done: - if ((bp->b_flags & B_ERROR) != 0) - bp->b_resid = bp->b_bcount; + bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/dev/raidframe/rf_openbsdkintf.c b/sys/dev/raidframe/rf_openbsdkintf.c index c1bd25b2318..16792611a6a 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.64 2011/06/21 16:46:00 tedu Exp $ */ +/* $OpenBSD: rf_openbsdkintf.c,v 1.65 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: rf_netbsdkintf.c,v 1.109 2001/07/27 03:30:07 oster Exp $ */ /*- @@ -758,7 +758,7 @@ raidstrategy(struct buf *bp) * Do bounds checking and adjust transfer. If there's an * error, the bounds check will flag that for us. */ - if (bounds_check_with_label(bp, lp) <= 0) { + if (bounds_check_with_label(bp, lp) == -1) { db1_printf(("Bounds check failed!!: %d\n", (int)bp->b_blkno)); biodone(bp); diff --git a/sys/dev/rd.c b/sys/dev/rd.c index dccbd679e32..080291ecf67 100644 --- a/sys/dev/rd.c +++ b/sys/dev/rd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rd.c,v 1.4 2011/06/30 16:28:05 matthew Exp $ */ +/* $OpenBSD: rd.c,v 1.5 2011/07/06 04:49:36 matthew Exp $ */ /* * Copyright (c) 2011 Matthew Dempsky <matthew@dempsky.org> @@ -215,18 +215,8 @@ rdstrategy(struct buf *bp) goto bad; } - /* If it's a null transfer, return immediately. */ - if (bp->b_bcount == 0) - goto done; - - /* The transfer must be a whole number of sectors. */ - if ((bp->b_bcount % sc->sc_dk.dk_label->d_secsize) != 0) { - bp->b_error = EINVAL; - goto bad; - } - - /* Check that the request is within the partition boundaries. */ - if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) goto done; /* Do the transfer. */ @@ -250,11 +240,13 @@ rdstrategy(struct buf *bp) bad: bp->b_flags |= B_ERROR; + bp->b_resid = bp->b_bcount; done: s = splbio(); biodone(bp); splx(s); - device_unref(&sc->sc_dev); + if (sc != NULL) + device_unref(&sc->sc_dev); } int diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index e71d9d7850a..7f391bc3157 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnd.c,v 1.137 2011/07/04 20:35:34 deraadt Exp $ */ +/* $OpenBSD: vnd.c,v 1.138 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */ /* @@ -292,7 +292,7 @@ vndstrategy(struct buf *bp) /* If we have a label, do a boundary check. */ if (sc->sc_flags & VNF_HAVELABEL) { - if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0) + if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) goto done; /* diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index ff3765eeacf..9c41426adc4 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.128 2011/07/05 04:05:04 matthew Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.129 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -717,7 +717,7 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp) /* calculate cylinder for disksort to order transfers with */ bp->b_cylinder = (bp->b_blkno + DL_SECTOBLK(lp, DL_GETPOFFSET(p))) / DL_SECTOBLK(lp, lp->d_secpercyl); - return (1); + return (0); bad: bp->b_error = EINVAL; diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index a0c64748ec2..ff64bcbb520 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.206 2011/07/03 15:47:18 matthew Exp $ */ +/* $OpenBSD: cd.c,v 1.207 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -466,24 +466,9 @@ cdstrategy(struct buf *bp) bp->b_error = EIO; goto bad; } - /* - * The transfer must be a whole number of blocks. - */ - if ((bp->b_bcount % sc->sc_dk.dk_label->d_secsize) != 0) { - bp->b_error = EINVAL; - goto bad; - } - /* - * If it's a null transfer, return immediately - */ - if (bp->b_bcount == 0) - goto done; - /* - * Do bounds checking, adjust transfer. if error, process. - * If end of partition, just return. - */ - if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) goto done; /* Place it in the queue of disk activities for this disk. */ @@ -498,13 +483,10 @@ cdstrategy(struct buf *bp) device_unref(&sc->sc_dev); return; -bad: + bad: bp->b_flags |= B_ERROR; -done: - /* - * Set the buf to indicate no xfer was done. - */ bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 2222e4a1493..59379bd9da8 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.232 2011/07/03 15:47:18 matthew Exp $ */ +/* $OpenBSD: sd.c,v 1.233 2011/07/06 04:49:36 matthew Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -517,24 +517,9 @@ sdstrategy(struct buf *bp) bp->b_error = ENODEV; goto bad; } - /* - * If it's a null transfer, return immediately - */ - if (bp->b_bcount == 0) - goto done; - /* - * The transfer must be a whole number of sectors. - */ - if ((bp->b_bcount % sc->sc_dk.dk_label->d_secsize) != 0) { - bp->b_error = EINVAL; - goto bad; - } - /* - * Do bounds checking, adjust transfer. if error, process. - * If end of partition, just return. - */ - if (bounds_check_with_label(bp, sc->sc_dk.dk_label) <= 0) + /* Validate the request. */ + if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) goto done; /* Place it in the queue of disk activities for this disk. */ @@ -549,13 +534,10 @@ sdstrategy(struct buf *bp) device_unref(&sc->sc_dev); return; -bad: + bad: bp->b_flags |= B_ERROR; -done: - /* - * Correctly set the buf to indicate a completed xfer - */ bp->b_resid = bp->b_bcount; + done: s = splbio(); biodone(bp); splx(s); |