From 0386255bee079922f00f37eeb4e9e3138b7666c1 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 12 Dec 2022 22:39:03 -0700 Subject: [PATCH] kboot: Disks should be at least 16MB Linux pre-boot environments will often have a number of psuedo disks that are small, all smaller than a few MB. 16MB is a good cutoff since it's big enough to filter these devices, yet small enough to allow a super-minimal partition through (the smallest I've been able to make that's useful lately is around 20MB). Sponsored by: Netflix --- stand/kboot/hostdisk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stand/kboot/hostdisk.c b/stand/kboot/hostdisk.c index bc31bef8e6d0..628450ef8bb5 100644 --- a/stand/kboot/hostdisk.c +++ b/stand/kboot/hostdisk.c @@ -60,6 +60,8 @@ struct devsw hostdisk = { */ #define SYSBLK "/sys/block" +#define HOSTDISK_MIN_SIZE (16ul << 20) /* 16MB */ + typedef STAILQ_HEAD(, hdinfo) hdinfo_list_t; typedef struct hdinfo { STAILQ_ENTRY(hdinfo) hd_link; /* link in device list */ @@ -162,6 +164,8 @@ hostdisk_add_drive(const char *drv, uint64_t secs) if (!file2u64(fn, &hd->hd_sectorsize)) goto err; hd->hd_size = hd->hd_sectors * hd->hd_sectorsize; + if (hd->hd_size < HOSTDISK_MIN_SIZE) + goto err; hd->hd_flags = 0; STAILQ_INIT(&hd->hd_children); printf("/dev/%s: %ju %ju %ju\n",