From owner-svn-src-head@freebsd.org Mon Jul 2 18:19:09 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 85B581033531; Mon, 2 Jul 2018 18:19:09 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3189473ECC; Mon, 2 Jul 2018 18:19:09 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0EA9C11068; Mon, 2 Jul 2018 18:19:09 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w62IJ8Ue072882; Mon, 2 Jul 2018 18:19:08 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w62IJ8Zt072881; Mon, 2 Jul 2018 18:19:08 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <201807021819.w62IJ8Zt072881@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Mon, 2 Jul 2018 18:19:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335868 - head/stand/common X-SVN-Group: head X-SVN-Commit-Author: allanjude X-SVN-Commit-Paths: head/stand/common X-SVN-Commit-Revision: 335868 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2018 18:19:09 -0000 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");