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.
This commit is contained in:
Marcel Moolenaar 2002-12-17 02:51:56 +00:00
parent 1df5f8294f
commit 1aa83d38bc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=107963

View file

@ -41,6 +41,12 @@
CTASSERT(sizeof(struct kerneldumpheader) == 512); 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 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)) #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); hdrgap = fileofs - DEV_ALIGN(hdrsz);
/* Determine dump offset on device. */ /* 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 = di->mediaoffset + di->mediasize - dumpsize;
dumplo -= sizeof(kdh) * 2; dumplo -= sizeof(kdh) * 2;