diff options
author | kn <kn@cvs.openbsd.org> | 2020-06-08 19:17:13 +0000 |
---|---|---|
committer | kn <kn@cvs.openbsd.org> | 2020-06-08 19:17:13 +0000 |
commit | 179d5f98f5f96156e3ba843002b62771bc53ce84 (patch) | |
tree | 6f3517d7606c1dd31796eea1f29cc1374f89116c | |
parent | 4d87865a98319d86a2bc0e344c7f71e8349381e4 (diff) |
Provide clear errors when trying to install oversized boot loader
sparc64 installboot(8) on softraid(4) with too large files, e.g. unstripped
builds, fails poorly with "installboot: softraid installboot failed".
This is due to the BIOCINSTALLBOOT ioctl(2) returing the default EINVAL
rather than using softraid's sr_error() interface properly; additionally,
installboot does not check for such message from the bio(4) layer.
Make the kernel generate "boot block too large" and "boot loader too large"
messages for softraid devices and have installboot act upon them analogous
to bioctl(8), by adapting its bio_status() into the new sr_status() helper.
Input, reminder to look at bioctl, same kernel diff from, OK jsing
-rw-r--r-- | sys/dev/softraid.c | 12 | ||||
-rw-r--r-- | usr.sbin/installboot/i386_softraid.c | 3 | ||||
-rw-r--r-- | usr.sbin/installboot/installboot.h | 5 | ||||
-rw-r--r-- | usr.sbin/installboot/softraid.c | 18 | ||||
-rw-r--r-- | usr.sbin/installboot/sparc64_softraid.c | 3 |
5 files changed, 34 insertions, 7 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index dce30576d1b..95b7ddd57b4 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.401 2020/04/14 07:38:21 jca Exp $ */ +/* $OpenBSD: softraid.c,v 1.402 2020/06/08 19:17:12 kn Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us> * Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org> @@ -3704,11 +3704,17 @@ sr_ioctl_installboot(struct sr_softc *sc, struct sr_discipline *sd, goto done; } - if (bb->bb_bootblk_size > SR_BOOT_BLOCKS_SIZE * DEV_BSIZE) + if (bb->bb_bootblk_size > SR_BOOT_BLOCKS_SIZE * DEV_BSIZE) { + sr_error(sc, "boot block too large (%d > %d)", + bb->bb_bootblk_size, SR_BOOT_BLOCKS_SIZE * DEV_BSIZE); goto done; + } - if (bb->bb_bootldr_size > SR_BOOT_LOADER_SIZE * DEV_BSIZE) + if (bb->bb_bootldr_size > SR_BOOT_LOADER_SIZE * DEV_BSIZE) { + sr_error(sc, "boot loader too large (%d > %d)", + bb->bb_bootldr_size, SR_BOOT_LOADER_SIZE * DEV_BSIZE); goto done; + } secsize = sd->sd_meta->ssdi.ssd_secsize; diff --git a/usr.sbin/installboot/i386_softraid.c b/usr.sbin/installboot/i386_softraid.c index 5c4de777772..9971a23496d 100644 --- a/usr.sbin/installboot/i386_softraid.c +++ b/usr.sbin/installboot/i386_softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i386_softraid.c,v 1.15 2020/03/09 06:16:56 otto Exp $ */ +/* $OpenBSD: i386_softraid.c,v 1.16 2020/06/08 19:17:12 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> * Copyright (c) 2010 Otto Moerbeek <otto@drijf.net> @@ -178,6 +178,7 @@ sr_install_bootldr(int devfd, char *dev) "softraid volume\n", dev); if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) errx(1, "softraid installboot failed"); + sr_status(&bb.bb_bio.bio_status); } /* diff --git a/usr.sbin/installboot/installboot.h b/usr.sbin/installboot/installboot.h index f42c316181e..74488f9e9b4 100644 --- a/usr.sbin/installboot/installboot.h +++ b/usr.sbin/installboot/installboot.h @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.h,v 1.11 2018/09/01 16:55:29 krw Exp $ */ +/* $OpenBSD: installboot.h,v 1.12 2020/06/08 19:17:12 kn Exp $ */ /* * Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org> * @@ -15,6 +15,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <dev/biovar.h> + #include <stdlib.h> extern int nowrite; @@ -41,4 +43,5 @@ void md_installboot(int, char *); void sr_installboot(int, char *); void sr_install_bootblk(int, int, int); void sr_install_bootldr(int, char *); +void sr_status(struct bio_status *); #endif diff --git a/usr.sbin/installboot/softraid.c b/usr.sbin/installboot/softraid.c index 8a3c5620fdc..c197164526a 100644 --- a/usr.sbin/installboot/softraid.c +++ b/usr.sbin/installboot/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.4 2015/10/03 16:56:52 krw Exp $ */ +/* $OpenBSD: softraid.c,v 1.5 2020/06/08 19:17:12 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> * @@ -92,3 +92,19 @@ sr_volume(int devfd, char *dev, int *vol, int *disks) return 1; } + +void +sr_status(struct bio_status *bs) +{ + int i; + + for (i = 0; i < bs->bs_msg_count; i++) + warnx("%s", bs->bs_msgs[i].bm_msg); + + if (bs->bs_status == BIO_STATUS_ERROR) { + if (bs->bs_msg_count == 0) + errx(1, "unknown error"); + else + exit(1); + } +} diff --git a/usr.sbin/installboot/sparc64_softraid.c b/usr.sbin/installboot/sparc64_softraid.c index 776cf4a646a..c1d8f5170de 100644 --- a/usr.sbin/installboot/sparc64_softraid.c +++ b/usr.sbin/installboot/sparc64_softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sparc64_softraid.c,v 1.4 2019/06/28 13:32:48 deraadt Exp $ */ +/* $OpenBSD: sparc64_softraid.c,v 1.5 2020/06/08 19:17:12 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> * @@ -97,5 +97,6 @@ sr_install_bootldr(int devfd, char *dev) "softraid volume\n", dev); if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) errx(1, "softraid installboot failed"); + sr_status(&bb.bb_bio.bio_status); } } |