Index: sys/amd64/amd64/minidump_machdep.c =================================================================== --- sys/amd64/amd64/minidump_machdep.c +++ sys/amd64/amd64/minidump_machdep.c @@ -327,8 +327,8 @@ mdhdr.dmapbase = DMAP_MIN_ADDRESS; mdhdr.dmapend = DMAP_MAX_ADDRESS; - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, dumpsize, - kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, + dumpsize); printf("Dumping %llu out of %ju MB:", (long long)dumpsize >> 20, ptoa((uintmax_t)physmem) / 1048576); Index: sys/arm/arm/minidump_machdep.c =================================================================== --- sys/arm/arm/minidump_machdep.c +++ sys/arm/arm/minidump_machdep.c @@ -245,8 +245,8 @@ #else mdhdr.mmuformat = MINIDUMP_MMU_FORMAT_V4; #endif - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, dumpsize, - kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, + dumpsize); printf("Physical memory: %u MB\n", ptoa((uintmax_t)physmem) / 1048576); printf("Dumping %llu MB:", (long long)dumpsize >> 20); Index: sys/arm64/arm64/minidump_machdep.c =================================================================== --- sys/arm64/arm64/minidump_machdep.c +++ sys/arm64/arm64/minidump_machdep.c @@ -289,8 +289,8 @@ mdhdr.dmapbase = DMAP_MIN_ADDRESS; mdhdr.dmapend = DMAP_MAX_ADDRESS; - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AARCH64_VERSION, - dumpsize, kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AARCH64_VERSION, + dumpsize); printf("Dumping %llu out of %ju MB:", (long long)dumpsize >> 20, ptoa((uintmax_t)physmem) / 1048576); Index: sys/ddb/db_textdump.c =================================================================== --- sys/ddb/db_textdump.c +++ sys/ddb/db_textdump.c @@ -457,8 +457,7 @@ */ textdump_offset = di->mediasize - sizeof(kdh); textdump_saveoff(&trailer_offset); - mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0, 0, - TEXTDUMP_BLOCKSIZE); + dump_init_header(di, &kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0); (void)textdump_writenextblock(di, (char *)&kdh); /* @@ -483,8 +482,8 @@ * size. */ dumplen = trailer_offset - (textdump_offset + TEXTDUMP_BLOCKSIZE); - mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, dumplen, 0, - TEXTDUMP_BLOCKSIZE); + dump_init_header(di, &kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, + dumplen); (void)textdump_writenextblock(di, (char *)&kdh); textdump_restoreoff(trailer_offset); (void)textdump_writenextblock(di, (char *)&kdh); Index: sys/i386/i386/minidump_machdep.c =================================================================== --- sys/i386/i386/minidump_machdep.c +++ sys/i386/i386/minidump_machdep.c @@ -252,8 +252,8 @@ mdhdr.paemode = 1; #endif - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, - kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, + dumpsize); printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576); printf("Dumping %llu MB:", (long long)dumpsize >> 20); Index: sys/kern/kern_dump.c =================================================================== --- sys/kern/kern_dump.c +++ sys/kern/kern_dump.c @@ -341,8 +341,8 @@ dumpsize += fileofs; hdrgap = fileofs - roundup2((off_t)hdrsz, di->blocksize); - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARCH_VERSION, dumpsize, - kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_ARCH_VERSION, + dumpsize); printf("Dumping %ju MB (%d chunks)\n", (uintmax_t)dumpsize >> 20, ehdr.e_phnum - DUMPSYS_NUM_AUX_HDRS); Index: sys/kern/kern_shutdown.c =================================================================== --- sys/kern/kern_shutdown.c +++ sys/kern/kern_shutdown.c @@ -895,14 +895,10 @@ free(kdc, M_EKCD); return (NULL); } -#endif /* EKCD */ static int kerneldumpcrypto_init(struct kerneldumpcrypto *kdc) { -#ifndef EKCD - return (0); -#else uint8_t hash[SHA256_DIGEST_LENGTH]; SHA256_CTX ctx; struct kerneldumpkey *kdk; @@ -942,21 +938,17 @@ out: explicit_bzero(hash, sizeof(hash)); return (error); -#endif } -uint32_t +static uint32_t kerneldumpcrypto_dumpkeysize(const struct kerneldumpcrypto *kdc) { -#ifdef EKCD if (kdc == NULL) return (0); return (kdc->kdc_dumpkeysize); -#else - return (0); -#endif } +#endif /* EKCD */ /* Registration of dumpers */ int @@ -1036,6 +1028,20 @@ return (0); } +/* Call dumper with bounds checking. */ +static int +dump_raw_write(struct dumperinfo *di, void *virtual, vm_offset_t physical, + off_t offset, size_t length) +{ + int error; + + error = dump_check_bounds(di, offset, length); + if (error != 0) + return (error); + + return (di->dumper(di->priv, virtual, physical, offset, length)); +} + #ifdef EKCD static int dump_encrypt(struct kerneldumpcrypto *kdc, uint8_t *buf, size_t size) @@ -1115,21 +1121,20 @@ return (0); } -#endif /* EKCD */ -/* Call dumper with bounds checking. */ static int -dump_raw_write(struct dumperinfo *di, void *virtual, vm_offset_t physical, - off_t offset, size_t length) +dump_write_key(struct dumperinfo *di, vm_offset_t physical, off_t offset) { - int error; + struct kerneldumpcrypto *kdc; - error = dump_check_bounds(di, offset, length); - if (error != 0) - return (error); + kdc = di->kdc; + if (kdc == NULL) + return (0); - return (di->dumper(di->priv, virtual, physical, offset, length)); + return (dump_raw_write(di, kdc->kdc_dumpkey, physical, offset, + kdc->kdc_dumpkeysize)); } +#endif /* EKCD */ int dump_write(struct dumperinfo *di, void *virtual, vm_offset_t physical, @@ -1194,23 +1199,6 @@ return (ret); } -static int -dump_write_key(struct dumperinfo *di, vm_offset_t physical, off_t offset) -{ -#ifndef EKCD - return (0); -#else /* EKCD */ - struct kerneldumpcrypto *kdc; - - kdc = di->kdc; - if (kdc == NULL) - return (0); - - return (dump_raw_write(di, kdc->kdc_dumpkey, physical, offset, - kdc->kdc_dumpkeysize)); -#endif /* !EKCD */ -} - /* * Do some preliminary setup for a kernel dump: verify that we have enough space * on the dump device, write the leading header, and optionally write the crypto @@ -1221,14 +1209,19 @@ { uint64_t dumpsize; off_t dumplo; + uint32_t keysize; int error; +#ifdef EKCD error = kerneldumpcrypto_init(di->kdc); if (error != 0) return (error); + keysize = kerneldumpcrypto_dumpkeysize(di->kdc); +#else + keysize = 0; +#endif - dumpsize = dtoh64(kdh->dumplength) + 2 * di->blocksize + - kerneldumpcrypto_dumpkeysize(di->kdc); + dumpsize = dtoh64(kdh->dumplength) + 2 * di->blocksize + keysize; if (di->mediasize < KERNELDUMP_METADATA_SIZE + dumpsize) return (E2BIG); @@ -1239,10 +1232,12 @@ return (error); dumplo += di->blocksize; - error = dump_write_key(di, 0, dumplo); +#ifdef EKCD + error = dump_write_key(di, 0, *dumplop); if (error != 0) return (error); - dumplo += kerneldumpcrypto_dumpkeysize(di->kdc); + dumplo += keysize; +#endif *dumplop = dumplo; @@ -1267,8 +1262,8 @@ } void -mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, - uint64_t dumplen, uint32_t dumpkeysize, uint32_t blksz) +dump_init_header(const struct dumperinfo *di, struct kerneldumpheader *kdh, + char *magic, uint32_t archver, uint64_t dumplen) { size_t dstsize; @@ -1279,8 +1274,12 @@ kdh->architectureversion = htod32(archver); kdh->dumplength = htod64(dumplen); kdh->dumptime = htod64(time_second); - kdh->dumpkeysize = htod32(dumpkeysize); - kdh->blocksize = htod32(blksz); +#ifdef EKCD + kdh->dumpkeysize = htod32(kerneldumpcrypto_dumpkeysize(di->kdc)); +#else + kdh->dumpkeysize = 0; +#endif + kdh->blocksize = htod32(di->blocksize); strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname)); dstsize = sizeof(kdh->versionstring); if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize) Index: sys/mips/mips/minidump_machdep.c =================================================================== --- sys/mips/mips/minidump_machdep.c +++ sys/mips/mips/minidump_machdep.c @@ -261,8 +261,8 @@ mdhdr.ptesize = ptesize; mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS; - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_MIPS_VERSION, dumpsize, - kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_MIPS_VERSION, + dumpsize); printf("Dumping %llu out of %ju MB:", (long long)dumpsize >> 20, ptoa((uintmax_t)physmem) / 1048576); Index: sys/sparc64/sparc64/dump_machdep.c =================================================================== --- sys/sparc64/sparc64/dump_machdep.c +++ sys/sparc64/sparc64/dump_machdep.c @@ -94,8 +94,8 @@ DEV_BSIZE); size += hdrsize; - mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, - kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize); + dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, + size); printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg); Index: sys/sys/conf.h =================================================================== --- sys/sys/conf.h +++ sys/sys/conf.h @@ -342,6 +342,8 @@ int set_dumper(struct dumperinfo *di, const char *devname, struct thread *td, uint8_t encrypt, const uint8_t *key, uint32_t encryptedkeysize, const uint8_t *encryptedkey); +void dump_init_header(const struct dumperinfo *di, struct kerneldumpheader *kdh, + char *magic, uint32_t archver, uint64_t dumplen); int dump_start(struct dumperinfo *di, struct kerneldumpheader *kdh, off_t *dumplop); int dump_finish(struct dumperinfo *di, struct kerneldumpheader *kdh, Index: sys/sys/kerneldump.h =================================================================== --- sys/sys/kerneldump.h +++ sys/sys/kerneldump.h @@ -131,11 +131,6 @@ vm_paddr_t pa_size; }; -uint32_t kerneldumpcrypto_dumpkeysize(const struct kerneldumpcrypto *kdc); - -void mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, - uint64_t dumplen, uint32_t dumpkeysize, uint32_t blksz); - int dumpsys_generic(struct dumperinfo *); void dumpsys_map_chunk(vm_paddr_t, size_t, void **);