Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1prc3Q-00011w-V0 for mharc-grub-devel@gnu.org; Wed, 26 Apr 2023 06:07:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prc3P-00011n-QC for grub-devel@gnu.org; Wed, 26 Apr 2023 06:07:16 -0400 Received: from smtp-relay-canonical-1.canonical.com ([185.125.188.121]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prc3N-0005gv-Mp for grub-devel@gnu.org; Wed, 26 Apr 2023 06:07:15 -0400 Received: from farnsworth.. (unknown [62.168.35.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 2E417418BB; Wed, 26 Apr 2023 10:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1682503629; bh=pW3JllmLia+JU/flKv2uephGX/X/eqv4XDRKkMaUZlU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Tmrie2FSBGnIeKW6TDxT11OZXrvouOqf6oFtxccRfuQJDfq2gGiC8ZCzyHo1dBnUJ qCvOgxEjb2+xO/mmI8aD3cDd5NgOEJg4sXPwwE6dIu5Aga7wfDA7W2l9PRJxPpv9lD 1WFqrn67+WVPaakxLglbosf/TkLsnJFfMmOm7Q1r4BY5JmlUpnfjP80yYWNAAMImz2 t6WhkAoeUQNyE3vUnc7o2A/Xe2JJZZugZBoEWCd5yquA8jsWNk3J5uAgBMfuEOO3B4 BaoRafZ2pXXE91Xwrk/gUOVOTgep+sEx2KWYoQY4A1o66Uo3OWp6WgdhIv2SYM3T0Q KMQ3F5O2izAWg== From: Chris Coulson To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, Chris Coulson Subject: [PATCH] font: Try opening fonts from the bundled memdisk Date: Wed, 26 Apr 2023 12:06:52 +0200 Message-Id: <20230426100652.150775-1-chris.coulson@canonical.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.125.188.121; envelope-from=chris.coulson@canonical.com; helo=smtp-relay-canonical-1.canonical.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Apr 2023 10:07:16 -0000 Grub since 93a786a00163e50c29f0394df198518617e1c9a5 has enforced verification of font files in secure boot mode. In order to continue to be able to load some default fonts, vendors may bundle them with their signed EFI image by adding them to the built-in memdisk. This change makes the font loader try loading fonts from the memdisk before the prefix path when attempting to load a font file by specifying its filename, which avoids having to make changes to grub configurations in order to accommodate memdisk bundled fonts. It expects the directory structure to be the same as fonts stored in the prefix path (ie, /fonts/.pf2). Signed-off-by: Chris Coulson --- grub-core/font/font.c | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/grub-core/font/font.c b/grub-core/font/font.c index 24adcb35a..7c83467a3 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -415,6 +415,27 @@ read_section_as_short (struct font_file_section *section, return 0; } +static grub_file_t +try_open_from_prefix (const char *prefix, const char *filename) +{ + grub_file_t file; + char *fullname, *ptr; + + fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1 + + sizeof ("/fonts/") + sizeof (".pf2")); + if (!fullname) + return 0; + ptr = grub_stpcpy (fullname, prefix); + ptr = grub_stpcpy (ptr, "/fonts/"); + ptr = grub_stpcpy (ptr, filename); + ptr = grub_stpcpy (ptr, ".pf2"); + *ptr = 0; + + file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024); + grub_free (fullname); + return file; +} + /* Load a font and add it to the beginning of the global font list. Returns 0 upon success, nonzero upon failure. */ grub_font_t @@ -433,25 +454,18 @@ grub_font_load (const char *filename) file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024); else { - const char *prefix = grub_env_get ("prefix"); - char *fullname, *ptr; - if (!prefix) + file = try_open_from_prefix ("(memdisk)", filename); + if (!file) { - grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), - "prefix"); - goto fail; + const char *prefix = grub_env_get ("prefix"); + if (!prefix) + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), + "prefix"); + goto fail; + } + file = try_open_from_prefix (prefix, filename); } - fullname = grub_malloc (grub_strlen (prefix) + grub_strlen (filename) + 1 - + sizeof ("/fonts/") + sizeof (".pf2")); - if (!fullname) - goto fail; - ptr = grub_stpcpy (fullname, prefix); - ptr = grub_stpcpy (ptr, "/fonts/"); - ptr = grub_stpcpy (ptr, filename); - ptr = grub_stpcpy (ptr, ".pf2"); - *ptr = 0; - file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024); - grub_free (fullname); } if (!file) goto fail; -- 2.39.2