From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kiZFP-0006q2-G4 for mharc-grub-devel@gnu.org; Fri, 27 Nov 2020 03:36:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiZFO-0006pi-36 for grub-devel@gnu.org; Fri, 27 Nov 2020 03:36:54 -0500 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]:35683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kiZFL-0003SK-Sw for grub-devel@gnu.org; Fri, 27 Nov 2020 03:36:53 -0500 Received: by mail-lf1-x144.google.com with SMTP id a9so5956788lfh.2 for ; Fri, 27 Nov 2020 00:36:50 -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:mime-version :content-transfer-encoding; bh=veTBLkQSCNsjElL94pxvReo6KJXwMzVHd3G1OJ4GzLw=; b=di/i3KqYMuwAVzpzu7QzEMi+NlfXBIZmojOONLM0jKIsUMY5YYDG2e9rOx/pfghrRS 8CXLg2+7v4YySaU2yQiWml6J5y1YRH4vcc8puK+5HD1K3GC2i0XsP5R5F/WcXrsotPjg vveLw+AMpPipE1f9xDNB5cfXSjvjsbNTCEuPQeEmkfbnzFJwBqQmOQMZj23+DDWd7JZ2 z3nDg8wUQARogIQO2of9LurPZvb8PCY//WaNHAOKH0Ixtdb9fFctGAzPeXlK2GOmVYFj FFiZQ6+OOSLMtskH8dRbwqe05J6YkIGbzJ3cvEScWu7lrglge7q4bzWmnm/OzG3BUm1a XzAg== 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:mime-version :content-transfer-encoding; bh=veTBLkQSCNsjElL94pxvReo6KJXwMzVHd3G1OJ4GzLw=; b=OBHdmZ6ZfzI3E8e6xRuC8elC3+7HF7HDmlt009s2hjxM+uQbwQVfVZG03YJtEZrC7W ghmi5ANf1NHu3/NgwVZGMhrPxkmvXKIWlyayV9klp31gbged8TDrZKbb/N8fW9JqeObU /KW2lk5eVc0IixD9rzR+qsbh6pWqmcyRINByTpBa+xVBHKTw1jug7qrnNLjOYWYBwLOz 3A0ckBpN7DSutGFnTN/6hKRKi9mWF/bWvHWXMqAy5ocjX/TvvUHZk5VZ560h+dwgrtZn VAA27Z0dvGF4RJHQnr2Tr1zWQcAiStIP+WAvWglwgcDS5r23zccwjZKYgd2eN+qKpq3K Gz9A== X-Gm-Message-State: AOAM532VrqRJVqC5BGYkuYbxmSumAoyO8mGd7HJcnERMw5q+YsM1+UP1 jW8k8yjCt5oO/FkB50ZrO6anCApJLQkKvg== X-Google-Smtp-Source: ABdhPJwXEjiCJqaJ/YR64ltXKveHxQWwP4Nm8DVzB9dc++G23h4d+jtSl4ZZ9/dv2hYcR7KQ+HFF1g== X-Received: by 2002:a19:fc0f:: with SMTP id a15mr2822219lfi.248.1606466208991; Fri, 27 Nov 2020 00:36:48 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id v17sm607372lfp.169.2020.11.27.00.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 00:36:48 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Glenn Washburn Subject: [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Date: Fri, 27 Nov 2020 02:36:23 -0600 Message-Id: <20201127083624.3482953-1-development@efficientek.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::144; envelope-from=development@efficientek.com; helo=mail-lf1-x144.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: Fri, 27 Nov 2020 08:36:54 -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 | 13 +++++++------ include/grub/disk.h | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/grub-core/kern/disk_common.c b/grub-core/kern/disk_common.c index 5b92f670b..d20ed20d2 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 = grub_disk_from_native_sector (disk, disk->total_sectors); - /* 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. + /* + 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 > (1ULL << 51)) - total_sectors = (1ULL << 51); + 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 1a9e8fcf4..0bf08091f 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -157,6 +157,12 @@ struct grub_disk_memberlist typedef struct grub_disk_memberlist *grub_disk_memberlist_t; #endif +/* + Some drivers have problems with disks above reasonable sizes. + Set max disk size at 1EiB. +*/ +#define GRUB_DISK_MAX_SECTORS (1ULL << (60 - 9)) + /* The sector size. */ #define GRUB_DISK_SECTOR_SIZE 0x200 #define GRUB_DISK_SECTOR_BITS 9 -- 2.27.0