svn commit: r335868 - head/stand/common
Allan Jude
allanjude at FreeBSD.org
Mon Jul 2 18:19:09 UTC 2018
Author: allanjude
Date: Mon Jul 2 18:19:08 2018
New Revision: 335868
URL: https://svnweb.freebsd.org/changeset/base/335868
Log:
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
Modified:
head/stand/common/disk.c
Modified: head/stand/common/disk.c
==============================================================================
--- head/stand/common/disk.c Mon Jul 2 17:54:33 2018 (r335867)
+++ head/stand/common/disk.c Mon Jul 2 18:19:08 2018 (r335868)
@@ -219,20 +219,13 @@ disk_ioctl(struct disk_devdesc *dev, u_long cmd, void
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
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");
More information about the svn-src-head
mailing list