From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fxv5o-0004Wk-9Y for mharc-grub-devel@gnu.org; Thu, 06 Sep 2018 10:17:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxv5m-0004WF-Cf for grub-devel@gnu.org; Thu, 06 Sep 2018 10:17:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxv5i-0005gG-Du for grub-devel@gnu.org; Thu, 06 Sep 2018 10:17:06 -0400 Received: from ionic.de ([87.98.244.45]:53107 helo=mail.ionic.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxv5i-0005e4-2r for grub-devel@gnu.org; Thu, 06 Sep 2018 10:17:02 -0400 Received: from localhost.localdomain (178.162.222.41.adsl.inet-telecom.org [178.162.222.41]) by mail.ionic.de (Postfix) with ESMTPSA id 305D44F0030F; Thu, 6 Sep 2018 14:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ionic.de; s=default; t=1536243418; bh=nFAMYMZ67kN0K7d4b5Nu7LT5yP/7xG/stGTQ4Z1f8II=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aLGwOXfzUHtbdWuwbJHheXCKxmxFo1jeyYBr9QoBs0C/Tm7UnmE6nJEzGTtFI1XEG +H9BGl0VBalomGjvlVzdqE74/AFqEJuyhQ6mkZEYV5mOXvxMDBQEqwBCttsfZuZqS5 SlFPjzPzYgoE8GzGdfIqiNje3Ho9CPVYPDO1PpMQ= From: Mihai Moldovan To: grub-devel@gnu.org Cc: Mihai Moldovan Subject: [PATCH v2] osdep/linux: convert partition start to disk sector length. Date: Thu, 6 Sep 2018 16:16:39 +0200 Message-Id: <20180906141639.3050-1-ionic@ionic.de> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180906134009.GC29770@router-fw-old.i.net-space.pl> References: <20180906134009.GC29770@router-fw-old.i.net-space.pl> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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: Thu, 06 Sep 2018 14:17:07 -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. Signed-off-by: Mihai Moldovan --- 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