From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1okrvH-0007bs-Ux for mharc-grub-devel@gnu.org; Tue, 18 Oct 2022 15:06:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okruW-0007NV-O4 for grub-devel@gnu.org; Tue, 18 Oct 2022 15:05:59 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:46514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okruA-0000fC-9Z for grub-devel@gnu.org; Tue, 18 Oct 2022 15:05:39 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4CC2661668; Tue, 18 Oct 2022 19:05:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FBA4C433D7; Tue, 18 Oct 2022 19:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666119930; bh=a7V7Hu1LXpbnd9iYzQ9OlUVav3pf0DXQSeUQC68bmBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tupY5lsoI3rFJ2J5+FM2ksPqhEqzDIJ9GqMnGJbA6OYAGrUKcQoVQ3WDacnehi06w a11UUPHlOB5Cbczc+8YG6RQQhF0d/gN3bbVltFYH6LXSaKqNJ53JdobZehTB45N2WO iaY38l+gqdNDmohhSaaJIwVR2iTQWP6ZxMsCcZ5eqmiRKcKdyZ0YY9JWRMeoxpcQPj jHV1dx3X4u6ehjeqwCAOTSfM2c2ONX6iBbNEg3XUHW4bPXp8izD37K2lSGZ4hCxaDu LDZhq6MdgfTkbu7glKovw2ViLaS1X6lRmr0z/HaUPhpDJkov5MD+eGNhCd1WlyGrho wIegD5FjvWCLw== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: Ard Biesheuvel , Daniel Kiper , Leif Lindholm , Nikita Ermakov , Atish Patra , Huacai Chen , Heinrich Schuchardt , dann frazier , Julian Andres Klode , Ilias Apalodimas Subject: [PATCH v5 4/6] efi/efinet: Don't close connections at fini_hw() time Date: Tue, 18 Oct 2022 21:05:05 +0200 Message-Id: <20221018190508.177568-5-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018190508.177568-1-ardb@kernel.org> References: <20221018190508.177568-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3413; i=ardb@kernel.org; h=from:subject; bh=a7V7Hu1LXpbnd9iYzQ9OlUVav3pf0DXQSeUQC68bmBE=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjTvjfcu3vQbVJ99y/z2fkg37CXXVOuUvwhCwjjtV7 HtKZajyJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY0743wAKCRDDTyI5ktmPJN4hDA CKIu46lrnbu6N05iEgD6SBlRjx9OXC+svqx5+u3ls9ZGVI7lLkJrydjxeQBmqCdnwYpTpkBvxl6p+e GzsEBP36iyCNTHKEAbQVWHWVqT0TQLWUHNVoykUNnzLrZpDHMjZhUwyLblkmrSL2/VkP2ybXg5lAEl PgaU3NH14QrzDLjV7AZWy1R26KrzrzBr1k0sbFKDnk2262AYnNxVw6kYxRaVuMEuy32cXiSzVyye/M 0U6mc8Z78fUN17S1vFJKJ4sOZjCOXw2s0+JMYw8A/js24KPxoBHmIiA06khrlws1K9il8qn/SGKsrh QB/WcdZMArW0PEOfjF+NRE1+o9CaTRpRQjSotqaw2NVhryjmyrWnaYn8NBHrhL4LijOc739cyyNJWu GDpYqT+mprcqasqlYwjb+s43soUkQWdNUymHZUzsr17NzXU8FbgLFcewtsv0GZkD0CYL5KNxCcuVdN n59e4z+4Xgj7r21rdqmjEtfpW/knFGAEkoJUgtws3cpV4= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=139.178.84.217; envelope-from=ardb@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -73 X-Spam_score: -7.4 X-Spam_bar: ------- X-Spam_report: (-7.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.256, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, 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.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Oct 2022 19:06:01 -0000 When GRUB runs on top of EFI firmware, it only has access to block and network device abstractions exposed by the firmware, and it is up to the firmware to quiesce the underlying hardware when exiting boot services and handing over to the OS. This is especially important for network devices, to prevent incoming packets from being DMA'd straight into memory after the OS has taken over but before it has managed to reconfigure the network hardware. GRUB handles this by means of the grub_net_fini_hw() preboot hook, which is executed before calling into the booted image. This means that all network devices disappear or become inoperable before the EFI stub executes on EFI targeted builds. This is problematic as it prevents the EFI stub from calling back into GRUB provided protocols such as LoadFile2 for the initrd, which we will provide in a subsequent patch. So add a flag that indicates to the network core that EFI network devices should not be closed when grub_net_fini_hw() is called. Signed-off-by: Ard Biesheuvel Reviewed-by: Heinrich Schuchardt Reviewed-by: Daniel Kiper --- grub-core/net/drivers/efi/efinet.c | 10 +++++++++- grub-core/net/net.c | 2 +- include/grub/net.h | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 73343d26d9e1..5adf5f40f492 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -320,7 +320,15 @@ grub_efinet_findcards (void) card->name = grub_xasprintf ("efinet%d", i++); card->driver = &efidriver; - card->flags = 0; + /* + * EFI network devices are abstract SNP protocol instances, and the + * firmware is in charge of ensuring that they will be torn down when the + * OS loader hands off to the OS proper. Closing them as part of the + * preboot cleanup is therefore unnecessary, and undesirable, as it + * prevents us from using the network connection in a protocal callback + * such as LoadFile2 for initrd loading. + */ + card->flags = GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW; card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; grub_memcpy (card->default_address.mac, net->mode->current_address, diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 064e7114e012..7046dc57890a 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -1787,7 +1787,7 @@ grub_net_fini_hw (int noreturn __attribute__ ((unused))) { struct grub_net_card *card; FOR_NET_CARDS (card) - if (card->opened) + if (card->opened && !(card->flags & GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW)) { if (card->driver->close) card->driver->close (card); diff --git a/include/grub/net.h b/include/grub/net.h index a64a04cc80b1..79cba357ae6a 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -64,7 +64,8 @@ typedef enum grub_net_interface_flags typedef enum grub_net_card_flags { GRUB_NET_CARD_HWADDRESS_IMMUTABLE = 1, - GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2 + GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2, + GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW = 4 } grub_net_card_flags_t; struct grub_net_card; -- 2.35.1