From 826ccce5c32876da679bc20dc369e2ea1a823c00 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Thu, 18 Aug 2005 22:59:22 +0000 Subject: 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@ --- sys/scsi/sd.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'sys') 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 $ */ /*- @@ -1395,6 +1395,25 @@ sd_get_parms(sd, dp, flags) else 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. -- cgit v1.2.3