mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-13 10:02:38 +00:00
stand/common/disk.c: Read partition table relative to the start of the disk
If a disk is of an oddball size, like the 200mb + 512b used in rootgen.sh, when disk_open() is called on a GELI encrypted partition, attempts to read the partition table fail, as they pass through the decryption process which turns the already plaintext data into jibberish. When reading the partition table, always pass a slice and partition setting of -1, and an offset of 0. Setting the slice to -1 prevents a false positive when checking the slice against the cache of GELI encrypted slices. Reviewed by: imp, ian Sponsored by: Klara Systems Differential Revision: https://reviews.freebsd.org/D15847
This commit is contained in:
parent
1b09d9df3d
commit
32c52b4847
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=335868
@ -219,20 +219,13 @@ disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *data)
|
||||
int
|
||||
disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize)
|
||||
{
|
||||
struct disk_devdesc partdev;
|
||||
struct open_disk *od;
|
||||
struct ptable *table;
|
||||
struct ptable_entry part;
|
||||
int rc, slice, partition;
|
||||
|
||||
rc = 0;
|
||||
/*
|
||||
* While we are reading disk metadata, make sure we do it relative
|
||||
* to the start of the disk
|
||||
*/
|
||||
dev->d_offset = 0;
|
||||
table = NULL;
|
||||
slice = dev->d_slice;
|
||||
partition = dev->d_partition;
|
||||
od = (struct open_disk *)malloc(sizeof(struct open_disk));
|
||||
if (od == NULL) {
|
||||
DEBUG("no memory");
|
||||
@ -242,11 +235,24 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize)
|
||||
od->entrysize = 0;
|
||||
od->mediasize = mediasize;
|
||||
od->sectorsize = sectorsize;
|
||||
/*
|
||||
* While we are reading disk metadata, make sure we do it relative
|
||||
* to the start of the disk
|
||||
*/
|
||||
memcpy(&partdev, dev, sizeof(partdev));
|
||||
partdev.d_offset = 0;
|
||||
partdev.d_slice = -1;
|
||||
partdev.d_partition = -1;
|
||||
|
||||
table = NULL;
|
||||
slice = dev->d_slice;
|
||||
partition = dev->d_partition;
|
||||
|
||||
DEBUG("%s unit %d, slice %d, partition %d => %p",
|
||||
disk_fmtdev(dev), dev->dd.d_unit, dev->d_slice, dev->d_partition, od);
|
||||
|
||||
/* Determine disk layout. */
|
||||
od->table = ptable_open(dev, mediasize / sectorsize, sectorsize,
|
||||
od->table = ptable_open(&partdev, mediasize / sectorsize, sectorsize,
|
||||
ptblread);
|
||||
if (od->table == NULL) {
|
||||
DEBUG("Can't read partition table");
|
||||
|
Loading…
Reference in New Issue
Block a user