From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oWHcb-00089t-Ou for mharc-grub-devel@gnu.org; Thu, 08 Sep 2022 09:31:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWHcQ-0007yX-IB for grub-devel@gnu.org; Thu, 08 Sep 2022 09:31:01 -0400 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]:53528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWHcO-00038C-30 for grub-devel@gnu.org; Thu, 08 Sep 2022 09:30:58 -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 ams.source.kernel.org (Postfix) with ESMTPS id CE224B82075; Thu, 8 Sep 2022 13:30:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 608E8C433D7; Thu, 8 Sep 2022 13:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662643853; bh=z6XCNHYVnrV2XRumKbcFFaQGpT98rM4HvUBtT5FQH5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zqf44O7/a+kQ8SITJevFfV3wYq3cA8moCW0lj2errNqkqBMuvAFa5Ijp1FZQ6Z21q gLtqADqwKyK/VfkSwN26qmvvkCvXUsb+ciknCmcd8zh/skw8fQ9ceTzyv7QEqrdXVS Z+3+gqjdfa9EjPqDxGpxHuuuketgK6M0HthFl1VjqSio8ebN/ZqpqD9PssjFf6IjwX RAA3Dc6YJTpj5T/ucLmgxn4sMuWFG/s7pqdAQYpPFujIath55QOpx/5ZDDgdZjFr/4 LhuZO+AbThqQxqGdNWyjYS52Y4XXUC8elF5dzGVvLNLOEJ65Q9eBk2qWINN7LWuPHm 1+T8M9BMHkm5g== 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 v4 4/6] efi/efinet: Don't close connections at fini_hw() time Date: Thu, 8 Sep 2022 15:30:15 +0200 Message-Id: <20220908133017.1464494-5-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220908133017.1464494-1-ardb@kernel.org> References: <20220908133017.1464494-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3360; i=ardb@kernel.org; h=from:subject; bh=z6XCNHYVnrV2XRumKbcFFaQGpT98rM4HvUBtT5FQH5g=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjGe5krA0rEEDmw/VyXhlXX/HEIeS4ns7cbb+MxSWN jqhOoE+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYxnuZAAKCRDDTyI5ktmPJN29C/ 0buKyOXGu/Olacyz0MLM7414w3FLTwKKdvhD3tfIU7Si7wy9TSqzLrQvWieHDEGwxGZT8AEVsEFHle EmdcO0Bi+6x9sAu09eAQbHCLYGOb/C01X8XCZozicIlqkK2Za4GLlKppyxynouCdUYLEPEH/w6Zkfr MHrFCrmyaEwXynx5hLFJNNE/dB77X6D7mKr+qg0DmUngPN0yENxxIo8b4UgKFRt+P69Ub/5UjOSU4b c6FWtS6QCldJMAjjh/buHxrV08kf0XwET8MZPBSLmID1UrYMKAV889CFvLDQx/TqdhyvecvQPIs1D7 xRutVt5WKFgz2WitKo6fXPFclNoFuxZSQXdpjN6VUa+c8tlz1u9LT1+A+2J1nNEFYJmSH79uh/oYkt 3rDHdJfG9V3jJaspoxdXEY/eksA/Uqhm0AlABzw4NOaG82A4qSFbOqNagTL9jqAoR3VxYzHYTW0RGO 2U8Uevm4aLavFsTleZG545xLCKtYbF1Nsm982B0tIdtaE= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=ardb@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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, 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: Thu, 08 Sep 2022 13:31: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 --- 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