From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org
Cc: Daniel Kiper <dkiper@net-space.pl>,
Glenn Washburn <development@efficientek.com>
Subject: [PATCH v2] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h
Date: Mon, 30 Nov 2020 23:16:19 -0600 [thread overview]
Message-ID: <20201201051619.3701941-1-development@efficientek.com> (raw)
In-Reply-To: <20201127083624.3482953-1-development@efficientek.com>
There is a hardcoded maximum disk size that can be read or written from,
currently set at 1EiB in grub_disk_adjust_range. Move the literal into a
macro in disk.h, so our assumptions are more visible. This hard coded limit
does not prevent using larger disks, just grub won't read/write past the
limit. The comment accompanying this restriction didn't quite make sense to
me, so its been modified.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/kern/disk_common.c | 15 ++++++++-------
include/grub/disk.h | 6 ++++++
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/grub-core/kern/disk_common.c b/grub-core/kern/disk_common.c
index 2ca12b5f8..d43b927a4 100644
--- a/grub-core/kern/disk_common.c
+++ b/grub-core/kern/disk_common.c
@@ -32,13 +32,14 @@ grub_disk_adjust_range (grub_disk_t disk, grub_disk_addr_t *sector,
/* Transform total_sectors to number of 512B blocks. */
total_sectors = disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
- /* Some drivers have problems with disks above reasonable.
- Treat unknown as 1EiB disk. While on it, clamp the size to 1EiB.
- Just one condition is enough since GRUB_DISK_UNKNOWN_SIZE << ls is always
- above 9EiB.
- */
- if (total_sectors > (1ULL << 51))
- total_sectors = (1ULL << 51);
+ /*
+ * Some drivers have problems with disks above reasonable sizes.
+ * Clamp the size to GRUB_DISK_MAX_SECTORS. Just one condition is enough
+ * since GRUB_DISK_UNKNOWN_SIZE is always above GRUB_DISK_MAX_SECTORS,
+ * assuming a maximum 4KiB sector size.
+ */
+ if (total_sectors > GRUB_DISK_MAX_SECTORS)
+ total_sectors = GRUB_DISK_MAX_SECTORS;
if ((total_sectors <= *sector
|| ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
diff --git a/include/grub/disk.h b/include/grub/disk.h
index 132a1bb75..93f4ae226 100644
--- a/include/grub/disk.h
+++ b/include/grub/disk.h
@@ -161,6 +161,12 @@ typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
#define GRUB_DISK_SECTOR_SIZE 0x200
#define GRUB_DISK_SECTOR_BITS 9
+/*
+ * Some drivers have problems with disks above reasonable sizes.
+ * Set max disk size at 1EiB.
+ */
+#define GRUB_DISK_MAX_SECTORS (1ULL << (60 - GRUB_DISK_MAX_SECTORS))
+
/* The maximum number of disk caches. */
#define GRUB_DISK_CACHE_NUM 1021
--
2.27.0
next prev parent reply other threads:[~2020-12-01 5:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-27 8:36 [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Glenn Washburn
2020-11-27 8:36 ` [PATCH] loopback: Do not automaticaly replace existing loopback dev, error instead Glenn Washburn
2020-12-02 14:36 ` Daniel Kiper
2020-12-04 11:45 ` Glenn Washburn
2020-11-30 14:42 ` [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Daniel Kiper
2020-12-01 5:15 ` Glenn Washburn
2020-12-01 5:16 ` Glenn Washburn [this message]
2020-12-02 14:28 ` [PATCH v2] " Daniel Kiper
2020-12-04 1:57 ` [PATCH v2] loopback: Do not automaticaly replace existing loopback dev, error instead Glenn Washburn
2020-12-04 12:34 ` Daniel Kiper
2020-12-08 4:52 ` Glenn Washburn
2020-12-10 16:55 ` Daniel Kiper
2020-12-11 22:36 ` Glenn Washburn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201201051619.3701941-1-development@efficientek.com \
--to=development@efficientek.com \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.