diff options
author | Pedro Martelletto <pedro@cvs.openbsd.org> | 2005-12-29 20:02:04 +0000 |
---|---|---|
committer | Pedro Martelletto <pedro@cvs.openbsd.org> | 2005-12-29 20:02:04 +0000 |
commit | 8883f3a07c9c444259820364fa3a7cf8103d8cad (patch) | |
tree | 79bc023ab320b5dea301138f37c4abe74674570d /sys | |
parent | 4e974cec464a9e0f0b9ba94ee6924b436da434a3 (diff) |
Correctly bounds check transfers passed to vndstrategy()
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/vnd.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index ff3ba330965..a472e510bcb 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnd.c,v 1.56 2005/07/20 02:36:13 tedu Exp $ */ +/* $OpenBSD: vnd.c,v 1.57 2005/12/29 20:02:03 pedro Exp $ */ /* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */ /* @@ -427,8 +427,8 @@ vndstrategy(bp) } bn = bp->b_blkno; - sz = howmany(bp->b_bcount, DEV_BSIZE); bp->b_resid = bp->b_bcount; + if (bn < 0) { bp->b_error = EINVAL; bp->b_flags |= B_ERROR; @@ -437,15 +437,25 @@ vndstrategy(bp) splx(s); return; } - if (DISKPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, vnd->sc_dk.dk_label, - vnd->sc_dk.dk_cpulabel, 1) <= 0) { - s = splbio(); - biodone(bp); - splx(s); - return; + + /* If we have a label, do a boundary check. */ + if (vnd->sc_flags & VNF_HAVELABEL) { + if (bounds_check_with_label(bp, vnd->sc_dk.dk_label, + vnd->sc_dk.dk_cpulabel, 1) <= 0) { + s = splbio(); + biodone(bp); + splx(s); + return; + } + + /* + * bounds_check_with_label() changes bp->b_resid, reset it + */ + bp->b_resid = bp->b_bcount; } + sz = howmany(bp->b_bcount, DEV_BSIZE); + /* No bypassing of buffer cache? */ if (vndsimple(bp->b_dev)) { /* |