From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kjy2u-0002Th-Cr for mharc-grub-devel@gnu.org; Tue, 01 Dec 2020 00:17:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kjy2t-0002Tb-EN for grub-devel@gnu.org; Tue, 01 Dec 2020 00:17:47 -0500 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]:41954) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kjy2r-0002fE-QB for grub-devel@gnu.org; Tue, 01 Dec 2020 00:17:47 -0500 Received: by mail-lf1-x143.google.com with SMTP id r24so1530488lfm.8 for ; Mon, 30 Nov 2020 21:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=66ng30VPTANs+WnVH7t/FSSPm96LYljWVMiR/QjNYs4=; b=SO6WKbgxh7aUHvfFBEPBa9o3ijRWzGnddPYk2LJfoZnLbhfS3SLANDBbHDCrY1rieN f5/V9siNstWyVkh24KLvWOa1t+DcET7xY0xdOEaupPGe3RJxJiGqIyEYRQlMbuUmgA17 u0JxyRs63PWUKplwaEtp/Nh+bhi+2L7G2oXl1wWHfY1A5H+voA4thAQUyzRvAh9l1UYk aEJOsTrVfkX9+cUFlEe/LTjus9khAVzuMA4E2s3HGfzKQkTz4870RiH0nEa6v8mR2zvX 8JpQR583GV8HDU35bIe9d6yjJebVP5it3CuIcsXUGEfEvHa1Hh8Hd5yWt2+Z86hhfV4f 078w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=66ng30VPTANs+WnVH7t/FSSPm96LYljWVMiR/QjNYs4=; b=loMIdAIDBKVno93hh9dQpEaY3dY6QA+qvtDxXhym9fOFf5oEELPSg3Z8Z8M5u/sOLY IThtWAu+Lgh2ItQHX8GIluqAGMffyA7uGYraf8LEj0n0+lERKnRTxshQgSMFbWjefYkF heNfaZgYKBnnVuF647GRGI2qRnuSq3zmfgEs33yLFB3KEzSxIFmxa0Ywp+jTbYpqgH6P 3tlH0BgQZ4NbzsQvLWfX0fSFAgD3h7pq3HeKbj0/w496wWu+4opRUcyv7CbylBZZ4SU6 UW0wTtj8S8cqwNjfmM/T19Qt4YJgILH2jZHIEQrBqcDd86fXkLHz8PfmhFdGdnyFvxP+ 74rw== X-Gm-Message-State: AOAM5305eeGudkZGEAMAK9Bg+Oo1gbwvEG5d/Rd7lrvfP5x5bxeERR0W iZJEjm27mZMG+b5BlsyIv/kjvxxAAFb/Og== X-Google-Smtp-Source: ABdhPJxusOCyDEoW8KnAqQhmpXj7qhSpOm9yk6Gl8GV6IuQFAq9STp6wGQ7ejYS6gocw+4iT/okNqg== X-Received: by 2002:ac2:5607:: with SMTP id v7mr428628lfd.71.1606799863626; Mon, 30 Nov 2020 21:17:43 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id 16sm77403lfr.85.2020.11.30.21.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 21:17:42 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Glenn Washburn 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 Message-Id: <20201201051619.3701941-1-development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201127083624.3482953-1-development@efficientek.com> References: <20201127083624.3482953-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::143; envelope-from=development@efficientek.com; helo=mail-lf1-x143.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Dec 2020 05:17:47 -0000 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 --- 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