From nobody Wed Oct 18 15:29:03 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S9ZWg4srhz4x9b9; Wed, 18 Oct 2023 15:29:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S9ZWg4LLDz4BNd; Wed, 18 Oct 2023 15:29:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697642943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0+a0+vFCJz9Z5CwqZKHSeKuyNVnlvrhwXFZ+7AyP/t8=; b=oqw2loUqLQ137QlLIcBhATwZy0g3xoS6Bg38XbZ9jWQn4vb5/QdmUTigbCXNGeOeyCRVTv x+EI9V90k0MOMVd5bym1tco6/D/qYWvhDJKzXr5JS0gTxApBmoKQUAV38vX5vZS5KUTfmS k4cPPXA1XYKFrCwgNJNE+m+3ONhGKrU781ZXuE8OsEjIRrbeCyUwK+zQ8zvRGrMaZtNZ4g fAkP1SNW8GyeuLAA1jGgcE1134VFnjrqxK6C8Gd+NOh288WvxN0GPgvknnXtLsPczqS+c3 QmMSJfY3fZA6uti0TPkeINFuS/YiqaRrSM4n0vEedJDqwLpuklqYPKijibOp7w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697642943; a=rsa-sha256; cv=none; b=dBlVT75HGqJj8SRuCwAz0lw1nQBOYchWziI/zJduMXz5C56LK47ewuDnmyVzsnlvxmzlgD hf41ZzT4JX4XcYKqS37xEkWXTwP44ZzEwEpMpi9JOFjQRM54WZaRzt42J7jGPzm1E5AC5+ 8KW7sTAuTctR0hd0uU3HlFfT434S/NlXLTKhodDhi0IkDPOzaX7BQbElb8RFlGyPNtxDMV qIGv2si9VWDvLfx8C0RTvsNQVwtvy6J3zZsSoDW8uieGEHOHSocwHoog5HnTwCdEqGYWo5 JX9UAyWVpeJrw+l6AJR7BOEN7lQ6341e5MQB0z9Ff8FJjoBEmkXVwIqo7ExRIQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697642943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0+a0+vFCJz9Z5CwqZKHSeKuyNVnlvrhwXFZ+7AyP/t8=; b=Y0tvcB8rIx9cfGaZ6o9OeDwlAb6tqvfrI9COrcy46nmxtaU6r2/eZzoHIT4y+E80d8bPX3 ChDHx5VVQ0SiiAjKzZGf4/xhdN3WkXfq/ImIbmuQCeDiRaiiTNwjhNEq23Ge9BPfCSeyhe wIKz+x1qDJTm7t9ciVBrtcmhadXh7oLRmP1rAMNoZ0jHY4HQv9tJa0fAWNIfPWE4POXyKe ky7zdnyy4ggUg74Ir96sro5KTHlJmqLSWu92Pqyd1YxXL8jSWmSE/iX2VIrZB13vdr2KwK pxeyhXa+th4+XME1cgigxSap7wKrCwipZaPHAbXR2lGcgtyyT5kuY43H0vbtkQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S9ZWg3NhWz1BVj; Wed, 18 Oct 2023 15:29:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39IFT3hT078240; Wed, 18 Oct 2023 15:29:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39IFT3kK078237; Wed, 18 Oct 2023 15:29:03 GMT (envelope-from git) Date: Wed, 18 Oct 2023 15:29:03 GMT Message-Id: <202310181529.39IFT3kK078237@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 5401ebd33cf5 - stable/14 - mkimg: Ensure GPT Entry Array is at least 16k List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5401ebd33cf5073e8c0f095527504d38f74a926b Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=5401ebd33cf5073e8c0f095527504d38f74a926b commit 5401ebd33cf5073e8c0f095527504d38f74a926b Author: Warner Losh AuthorDate: 2023-10-18 15:23:40 +0000 Commit: Warner Losh CommitDate: 2023-10-18 15:23:40 +0000 mkimg: Ensure GPT Entry Array is at least 16k UEFI v2.10 Section 5.3 documentes that the minimum reserved space after the GPT header be at least 16kB. Enforce this minimum. Before, we'd only set the number of entries to be the unpadded size. gpart's selective enforcement of aspects of the GPT standard meant that these images would work, but couldn't be changed (to add a partition or grow the size of a partition). This ensures that gpart's overly picky standards don't cause problems for people wishing to, for example, resize release images. MFC after: 1 day (we want this in 14.0) PR: 274312 Sponsored by: Netflix Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42245 (cherry picked from commit 9b42d3e12ffc6896fcb4e60c1b239ddf60705831) --- sys/sys/disk/gpt.h | 7 +++++++ usr.bin/mkimg/gpt.c | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sys/sys/disk/gpt.h b/sys/sys/disk/gpt.h index e48b13684814..596a5cba1681 100644 --- a/sys/sys/disk/gpt.h +++ b/sys/sys/disk/gpt.h @@ -82,6 +82,13 @@ struct gpt_hdr { CTASSERT(offsetof(struct gpt_hdr, padding) == 92); #endif +/* + * The GPT standard (section 5.3 of UEFI standard version 2.10) requires + * we reserve at least 16k after the PMBR and the GPT header for the GPT + * Array Entries. + */ +#define GPT_MIN_RESERVED 16384 + struct gpt_ent { gpt_uuid_t ent_type; gpt_uuid_t ent_uuid; diff --git a/usr.bin/mkimg/gpt.c b/usr.bin/mkimg/gpt.c index 59c51a6a177b..ed3f008c394f 100644 --- a/usr.bin/mkimg/gpt.c +++ b/usr.bin/mkimg/gpt.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. */ -#include +#include #include #include #include @@ -124,13 +124,21 @@ crc32(const void *buf, size_t sz) return (crc ^ ~0U); } +/* + * Return the number of sectors needed to store the partition table. + */ static u_int gpt_tblsz(void) { - u_int ents; + u_int eps; /* Entries per Sector */ - ents = secsz / sizeof(struct gpt_ent); - return ((nparts + ents - 1) / ents); + /* + * Count the number of sectors needed for the GPT Entry Array to store + * the number of partitions defined for this image. Enforce the 16kB + * minimum space for the GPT Entry Array per UEFI v2.10 Section 5.3. + */ + eps = secsz / sizeof(struct gpt_ent); + return (MAX(howmany(GPT_MIN_RESERVED, secsz), howmany(nparts, eps))); } static lba_t