DragonFlyBSD Kernel Audit
DF-0988 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/bus/cam/scsi/scsi_cd.c b/sys/bus/cam/scsi/scsi_cd.c
index 0000000..1111111 100644
--- a/sys/bus/cam/scsi/scsi_cd.c
+++ b/sys/bus/cam/scsi/scsi_cd.c
@@ -3068,6 +3068,20 @@
 	if (softc->params.blksize > 2048 && softc->params.blksize <= 2352)
 		softc->params.blksize = 2048;
 
+	/*
+	 * A malicious or buggy device may report blksize == 0 (or some
+	 * other unworkable value). cdstart() divides by softc->params.blksize
+	 * at scsi_cd.c:1530/1540/1541, which would panic the kernel with a
+	 * divide-by-zero / assertion. Refuse the media in that case so that
+	 * cdcheckmedia() reports the failure rather than crashing on the
+	 * next read.
+	 */
+	if (softc->params.blksize == 0) {
+		xpt_print(periph->path, "cdsize: device reported blocksize of 0, "
+		    "rejecting media\n");
+		error = ENXIO;
+	}
+
 	kfree(rcap_buf, M_SCSICD);
 	*size = softc->params.disksize;