From 8f1d7465c5479f4ce506ff4a29caee1af9fc0756 Mon Sep 17 00:00:00 2001 From: kevans Date: Sun, 21 Apr 2019 04:15:57 +0000 Subject: [PATCH] MFC r338262, r339334, r339796, r340240, r340857, r340917, r341007 r338262: stand: fdt: Drop some write-only assignments/variables and leaked bits Generally straightforward enough; a copy of argv[1] was being made in command_fdt_internal, solely used for a comparison within the handler-search, then promptly leaked. r339334: loader.efi: add poweroff command Add poweroff command to make life a bit easier. r339796: Simplify the EFI delay() function by calling BS->Stall() r340240: loader: ptable_open() check for ptable_cd9660read result is wrong The ptable_*read() functions return NULL on read errors (and partition table closed as an side effect). The ptable_open must check the return value and act properly. r340857: Nuke out buffer overflow safety marker code, it duplicates similar code in the malloc()/free() as well as having potential of softening the handling in case error is detected down to a mere warning as compared to hard panic in free(). r340917: Update pxeboot(8) manual page to reflect the next-server change in the ISC DHCP v3 server. r341007: Bump the date of pxeboot(8) manual page for r340917. PR: 123484, 232483 --- stand/common/bcache.c | 17 +---------------- stand/common/part.c | 10 ++++++---- stand/efi/libefi/delay.c | 12 +----------- stand/efi/loader/main.c | 17 +++++++++++++++++ stand/fdt/fdt_loader_cmd.c | 11 ++--------- stand/i386/pxeldr/pxeboot.8 | 10 ++++++---- 6 files changed, 33 insertions(+), 44 deletions(-) diff --git a/stand/common/bcache.c b/stand/common/bcache.c index 198dd5f3b7a..39e8e35a559 100644 --- a/stand/common/bcache.c +++ b/stand/common/bcache.c @@ -86,7 +86,6 @@ static u_int bcache_rablks; ((bc)->bcache_ctl[BHASH((bc), (blkno))].bc_blkno != (blkno)) #define BCACHE_READAHEAD 256 #define BCACHE_MINREADAHEAD 32 -#define BCACHE_MARKER 0xdeadbeef static void bcache_invalidate(struct bcache *bc, daddr_t blkno); static void bcache_insert(struct bcache *bc, daddr_t blkno); @@ -123,7 +122,6 @@ bcache_allocate(void) u_int i; struct bcache *bc = malloc(sizeof (struct bcache)); int disks = bcache_numdev; - uint32_t *marker; if (disks == 0) disks = 1; /* safe guard */ @@ -142,8 +140,7 @@ bcache_allocate(void) bc->bcache_nblks = bcache_total_nblks >> i; bcache_unit_nblks = bc->bcache_nblks; - bc->bcache_data = malloc(bc->bcache_nblks * bcache_blksize + - sizeof(uint32_t)); + bc->bcache_data = malloc(bc->bcache_nblks * bcache_blksize); if (bc->bcache_data == NULL) { /* dont error out yet. fall back to 32 blocks and try again */ bc->bcache_nblks = 32; @@ -158,9 +155,6 @@ bcache_allocate(void) errno = ENOMEM; return (NULL); } - /* Insert cache end marker. */ - marker = (uint32_t *)(bc->bcache_data + bc->bcache_nblks * bcache_blksize); - *marker = BCACHE_MARKER; /* Flush the cache */ for (i = 0; i < bc->bcache_nblks; i++) { @@ -222,15 +216,12 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size, int result; daddr_t p_blk; caddr_t p_buf; - uint32_t *marker; if (bc == NULL) { errno = ENODEV; return (-1); } - marker = (uint32_t *)(bc->bcache_data + bc->bcache_nblks * bcache_blksize); - if (rsize != NULL) *rsize = 0; @@ -350,12 +341,6 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size, result = 0; } - if (*marker != BCACHE_MARKER) { - printf("BUG: bcache corruption detected: nblks: %zu p_blk: %lu, " - "p_size: %zu, ra: %zu\n", bc->bcache_nblks, - (long unsigned)BHASH(bc, p_blk), p_size, ra); - } - done: if ((result == 0) && (rsize != NULL)) *rsize = size; diff --git a/stand/common/part.c b/stand/common/part.c index 10c6e9c9af0..da0934d74f0 100644 --- a/stand/common/part.c +++ b/stand/common/part.c @@ -675,10 +675,12 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, table->type = PTABLE_NONE; STAILQ_INIT(&table->entries); - if (ptable_iso9660read(table, dev, dread) != NULL) { - if (table->type == PTABLE_ISO9660) - goto out; - } + if (ptable_iso9660read(table, dev, dread) == NULL) { + /* Read error. */ + table = NULL; + goto out; + } else if (table->type == PTABLE_ISO9660) + goto out; #ifdef LOADER_VTOC8_SUPPORT if (be16dec(buf + offsetof(struct vtoc8, magic)) == VTOC_MAGIC) { diff --git a/stand/efi/libefi/delay.c b/stand/efi/libefi/delay.c index 723f681c528..9eb12309663 100644 --- a/stand/efi/libefi/delay.c +++ b/stand/efi/libefi/delay.c @@ -33,15 +33,5 @@ __FBSDID("$FreeBSD$"); void delay(int usecs) { - static EFI_EVENT ev = 0; - UINTN junk; - - if (!ev) { - if (BS->CreateEvent(EVT_TIMER, TPL_APPLICATION, 0, 0, &ev) - != EFI_SUCCESS) - return; - } - - BS->SetTimer(ev, TimerRelative, usecs * 10); - BS->WaitForEvent(1, &ev, &junk); + BS->Stall(usecs); } diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index 0f9e400c9b7..de7a3ba7c9e 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -746,6 +746,23 @@ main(int argc, CHAR16 *argv[]) return (EFI_SUCCESS); /* keep compiler happy */ } +COMMAND_SET(poweroff, "poweroff", "power off the system", command_poweroff); + +static int +command_poweroff(int argc __unused, char *argv[] __unused) +{ + int i; + + for (i = 0; devsw[i] != NULL; ++i) + if (devsw[i]->dv_cleanup != NULL) + (devsw[i]->dv_cleanup)(); + + RS->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL); + + /* NOTREACHED */ + return (CMD_ERROR); +} + COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); static int diff --git a/stand/fdt/fdt_loader_cmd.c b/stand/fdt/fdt_loader_cmd.c index cb72ccafa9b..87b587275bc 100644 --- a/stand/fdt/fdt_loader_cmd.c +++ b/stand/fdt/fdt_loader_cmd.c @@ -848,7 +848,6 @@ void fdt_fixup_stdout(const char *str) { char *ptr; - int serialno; int len, no, sero; const struct fdt_property *prop; char *tmp[10]; @@ -860,7 +859,6 @@ fdt_fixup_stdout(const char *str) if (ptr == str) return; - serialno = (int)strtol(ptr, NULL, 0); no = fdt_path_offset(fdtp, "/chosen"); if (no < 0) return; @@ -917,9 +915,7 @@ fdt_load_dtb_overlays(const char *extras) static int fdt_fixup(void) { - int chosen, len; - - len = 0; + int chosen; debugf("fdt_fixup()\n"); @@ -977,7 +973,6 @@ command_fdt_internal(int argc, char *argv[]) { cmdf_t *cmdh; int flags; - char *cmd; int i, err; if (argc < 2) { @@ -988,11 +983,10 @@ command_fdt_internal(int argc, char *argv[]) /* * Validate fdt . */ - cmd = strdup(argv[1]); i = 0; cmdh = NULL; while (!(commands[i].name == NULL)) { - if (strcmp(cmd, commands[i].name) == 0) { + if (strcmp(argv[1], commands[i].name) == 0) { /* found it */ cmdh = commands[i].handler; flags = commands[i].flags; @@ -1516,7 +1510,6 @@ fdt_modprop(int nodeoff, char *propname, void *value, char mode) sprintf(command_errbuf, "property does not exist!"); return (CMD_ERROR); } - len = strlen(value); rv = 0; buf = value; diff --git a/stand/i386/pxeldr/pxeboot.8 b/stand/i386/pxeldr/pxeboot.8 index 0194e218e52..c9fa434b302 100644 --- a/stand/i386/pxeldr/pxeboot.8 +++ b/stand/i386/pxeldr/pxeboot.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 27, 2017 +.Dd November 25, 2018 .Dt PXEBOOT 8 .Os .Sh NAME @@ -58,7 +58,7 @@ The .Nm binary is loaded just like any other boot file, by specifying it in the DHCP server's configuration file. -Below is a sample configuration for the ISC DHCP v2 server: +Below is a sample configuration for the ISC DHCP v3 server: .Bd -literal -offset indent option domain-name "example.com"; option routers 10.0.0.1; @@ -67,6 +67,7 @@ option broadcast-address 10.0.0.255; option domain-name-servers 10.0.0.1; server-name "DHCPserver"; server-identifier 10.0.0.1; +next-server 10.0.0.1; default-lease-time 120; max-lease-time 120; @@ -80,10 +81,11 @@ subnet 10.0.0.0 netmask 255.255.255.0 { } .Ed +.Va next-server +is the IP address of the next server in the bootstrap process, i.e. +your TFTP server or NFS server. .Nm recognizes -.Va next-server -and .Va option root-path directives as the server and path to NFS mount for file requests, respectively, or the server to make TFTP requests to. -- 2.45.0