From 0d0ffe4faac4907cc73211243cc7035fa910cf05 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Fri, 2 Nov 2018 11:41:58 +0000 Subject: [PATCH] loader: biosdisk should check if the media is present The bd_print/bd_open/bd_strategy need to make sure the device does have media, before getting into performing IO operations. Some systems can hung if the device without a media is accessed. Reported by: yuripv --- stand/i386/libi386/biosdisk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stand/i386/libi386/biosdisk.c b/stand/i386/libi386/biosdisk.c index e4dfe3ff708..43cb63fde85 100644 --- a/stand/i386/libi386/biosdisk.c +++ b/stand/i386/libi386/biosdisk.c @@ -418,6 +418,9 @@ bd_print(int verbose) if ((ret = pager_output(line)) != 0) break; + if ((bdinfo[i].bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) + continue; + dev.dd.d_dev = &biosdisk; dev.dd.d_unit = i; dev.d_slice = -1; @@ -464,6 +467,8 @@ bd_open(struct open_file *f, ...) if ((BD(dev).bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) { if (!bd_int13probe(&BD(dev))) return (EIO); + if ((BD(dev).bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) + return (EIO); } BD(dev).bd_open++; if (BD(dev).bd_bcache == NULL) @@ -569,6 +574,9 @@ bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, caddr_t bbuf; int rc; + if ((BD(dev).bd_flags & BD_NO_MEDIA) == BD_NO_MEDIA) + return (EIO); + /* * First make sure the IO size is a multiple of 512 bytes. While we do * process partial reads below, the strategy mechanism is built