From 1aa83d38bce732ab938e271acd8d90774185fc77 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Tue, 17 Dec 2002 02:51:56 +0000 Subject: [PATCH] Check that the dump device is large enough. Otherwise we could end up with a dump offset that's smaller than the start of the dump device and either clobber data in preceding partitions or try to write beyond the end of the medium (unsigned wrap). Implement legacy behaviour to never write to the first 64KB as that is where metadata (ie disklabels) may reside. --- sys/ia64/ia64/dump_machdep.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/ia64/ia64/dump_machdep.c b/sys/ia64/ia64/dump_machdep.c index 00994620240e..4195498abec7 100644 --- a/sys/ia64/ia64/dump_machdep.c +++ b/sys/ia64/ia64/dump_machdep.c @@ -41,6 +41,12 @@ CTASSERT(sizeof(struct kerneldumpheader) == 512); +/* + * Don't touch the first SIZEOF_METADATA bytes on the dump device. This + * is to protect us from metadata and to protect metadata from us. + */ +#define SIZEOF_METADATA (64*1024) + #define MD_ALIGN(x) (((off_t)(x) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK) #define DEV_ALIGN(x) (((off_t)(x) + (DEV_BSIZE-1)) & ~(DEV_BSIZE-1)) @@ -251,6 +257,10 @@ dumpsys(struct dumperinfo *di) hdrgap = fileofs - DEV_ALIGN(hdrsz); /* Determine dump offset on device. */ + if (di->mediasize < SIZEOF_METADATA + dumpsize + sizeof(kdh) * 2) { + error = ENOSPC; + goto fail; + } dumplo = di->mediaoffset + di->mediasize - dumpsize; dumplo -= sizeof(kdh) * 2;