From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fhUj1-00061J-Sp for mharc-grub-devel@gnu.org; Mon, 23 Jul 2018 02:53:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhUiz-00060w-Rd for grub-devel@gnu.org; Mon, 23 Jul 2018 02:53:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhUiw-0001Ns-PD for grub-devel@gnu.org; Mon, 23 Jul 2018 02:53:41 -0400 Received: from ionic.de ([87.98.244.45]:47099 helo=mail.ionic.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhUiw-0001Ni-Eh for grub-devel@gnu.org; Mon, 23 Jul 2018 02:53:38 -0400 Received: from localhost.localdomain (178.162.222.163.adsl.inet-telecom.org [178.162.222.163]) by mail.ionic.de (Postfix) with ESMTPSA id 53ABA4F002E1; Mon, 23 Jul 2018 06:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ionic.de; s=default; t=1532328816; bh=o/osTRTeB7NxyltfbHu/MFimpvbMWmKGQkK6oGhRIuA=; h=From:To:Cc:Subject:Date:From; b=bJVvF9lpeSA4KI4CbsmcjzciniKSOB6tzi3AAC18doONruBdZAYbjMHiVCEltrLYy miy+HLwtPtZipLQoOCLPESa4f9iMpnDPJTDBvWxBAGu750BJ4V7Xtr7799FCf3PLak SC6RMam2Rr4U3wkcmkukOsxekQXdIK4L1sVYVvqI= From: Mihai Moldovan To: grub-devel@gnu.org Cc: Mihai Moldovan Subject: [PATCH] osdep/linux: convert partition start to disk sector length. Date: Mon, 23 Jul 2018 08:52:50 +0200 Message-Id: <20180723065250.8879-1-ionic@ionic.de> X-Mailer: git-send-email 2.15.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.244.45 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2018 06:53:42 -0000 When reading data off a disk, sector values are based on the disk sector length. Within grub_util_fd_open_device(), the start of the partition was taken directly from grub's partition information structure, which uses the internal sector length (currently 512b), but never transformed to the disk's sector length. Subsequent calculations were all wrong for devices that have a diverging sector length and the functions eventually skipped to the wrong stream location, reading invalid data. --- grub-core/osdep/linux/hostdisk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c index 06179fca7..8b92f8528 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -374,7 +374,8 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f char dev[PATH_MAX]; grub_disk_addr_t part_start = 0; - part_start = grub_partition_get_start (disk->partition); + part_start = grub_partition_get_start (disk->partition) + >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); strncpy (dev, grub_util_biosdisk_get_osdev (disk), sizeof (dev) - 1); dev[sizeof(dev) - 1] = '\0'; -- 2.15.1