summaryrefslogtreecommitdiff
path: root/sys/scsi/sd.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2005-08-18 22:59:22 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2005-08-18 22:59:22 +0000
commit826ccce5c32876da679bc20dc369e2ea1a823c00 (patch)
tree1d60d7c6d1e445aa8882b904f51e0c81c675eeff /sys/scsi/sd.c
parent3eb14090c70271ebc05919f0fca6ab448350ad99 (diff)
Only allow blocksizes that are powers of 2 between 512 and 64K. An sd
device that returns any other value via READ CAPACITY or MODE SENSE will be marked 'drive offline'. Prevents divide by zero when calculating disk size in MB, amoung other interesting possibilities. ok mickey@ dlg@ deraadt@ millert@ marco@
Diffstat (limited to 'sys/scsi/sd.c')
-rw-r--r--sys/scsi/sd.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c
index 5451603a849..5fabdafc67a 100644
--- a/sys/scsi/sd.c
+++ b/sys/scsi/sd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sd.c,v 1.84 2005/08/17 02:17:51 krw Exp $ */
+/* $OpenBSD: sd.c,v 1.85 2005/08/18 22:59:21 krw Exp $ */
/* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */
/*-
@@ -1396,6 +1396,25 @@ sd_get_parms(sd, dp, flags)
dp->blksize = (blksize == 0) ? 512 : blksize;
/*
+ * Restrict blksize values to powers of two between 512 and 64k.
+ */
+ switch (dp->blksize) {
+ case 0x200: /* == 512, == DEV_BSIZE on all architectures. */
+ case 0x400:
+ case 0x800:
+ case 0x1000:
+ case 0x2000:
+ case 0x4000:
+ case 0x8000:
+ case 0x10000:
+ break;
+ default:
+ SC_DEBUG(sd->sc_link, SDEV_DB1,
+ ("sd_get_parms: bad blksize: %#x\n", dp->blksize));
+ return (SDGP_RESULT_OFFLINE);
+ }
+
+ /*
* Use Adaptec standard geometry values for anything we still don't
* know.
*/