Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp666523rdb; Sat, 19 Aug 2023 19:29:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXQrahab4eBE1g/4VsJWhL9d22P5Ild20xhuXSVLWIL/m7WxgdEroVwICgJjTK2k8wyldi X-Received: by 2002:a17:90a:2f41:b0:26d:4ade:fcf0 with SMTP id s59-20020a17090a2f4100b0026d4adefcf0mr3007891pjd.4.1692498555838; Sat, 19 Aug 2023 19:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692498555; cv=none; d=google.com; s=arc-20160816; b=F+VAk0i+SBiqqSSHLdrJGNkkeupdkElr/3m83jayRhRttTrP/drFTt3+5QzsOFUGSQ wzc1ChRIbTHmoE2UKm8maLls4r0rfHiNP+vLUxN9oJWfJoAfIYV2DXY/mTuOtKSA+hGk sPk0YOaIZZjYVXIsUs7ReQ+8d4h+nm0o9LZpmp0CX2DO0dC6X5aXrN4iQRiFYXBcGfqe xUYIgmQKyT8r5RO65B2qR0A93jMqKyWGB3cv5R+oHrj2wQXk9N+fvueeMegWRQ4El3Rl RSaV55JKG0O3WTUABepD+YhJVMa10x3ZOc2PS6zsTBotlwjOzSmohFZrCef3MmSPa6yy +YqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cvi9Pjg0p6+K0AnnAC6MpibEu0xLOnjNgnjm7H/bjUA=; fh=2K0cnVWNN/lSoXOQ2Jt2UifFp/1e7O4elwn57wGf9gU=; b=vyT+C9loueS1zeHy/MERvxhPtwBvCApB5G4o/SWS+hIDDrdHMxCfijRh4GlE6AZ9pJ GobntPKhCls0j6RlU5Bv+VVFYG54QB+XjPbENK+A42s2B665Wbcn7PYKhoHjeIv/n6/N bTlhfhx+vi1iTL/A5Rw03sbGh2P4wRmrwBMCy4bvSrmhL8btw2jIA5LTbmNvOLbXeRZR ecALHsrZPDUKDf4Fr7wiX36bQftCJGERPDctnizkl1ijdi5PUrq5GvnCDYTflM4RB7Ci kv6jOSx2H9y+XlqLNZZT8u9JIWZWQqc7+bTXDevzuAzMWXl/SkTfbDLLvsdf6AdRjbQQ sqyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y5jQQ1r0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id kb13-20020a17090ae7cd00b00263d00e1c54si4779381pjb.54.2023.08.19.19.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 19:29:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y5jQQ1r0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 853C5211155; Sat, 19 Aug 2023 11:30:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377355AbjHRNqT (ORCPT + 99 others); Fri, 18 Aug 2023 09:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377349AbjHRNpf (ORCPT ); Fri, 18 Aug 2023 09:45:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F45D4229; Fri, 18 Aug 2023 06:45:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 372BE60F45; Fri, 18 Aug 2023 13:45:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4782C433C7; Fri, 18 Aug 2023 13:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692366327; bh=qP277qhLgzUM7xLfNEHA2KtyZSQajU/8gNGhoczKCNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y5jQQ1r0XnlB1X+scrqBdqKpUVl7fIgolmkGJKwh9Vr+kzEzOj3NHAH1TDZa+FcfC 12JV7ea5LOUVn3irW9PuVQhsz5e0wvxXhznwmhey5RmoO6Bk6JgjH6yc8KibA92uwf HWTZLzSLNFO6pDp1KESRlYhXWO6BRWDXHYCam/Bp7wrXvfHqPQrZHEKEPjzDb2M60C qn7q6nHcJD/PP9jhv7Iw/aNx9rJRsK2YMYMkVrojW66EwOOq9eKctShnwk/OHDjUyM iuLDp17XxNboxY+6NHxvSdFzmzCFjsuDAkrHIN3sMuOTJpthN9TUHVpUTqUjSn8U9n 031aI9YS89KPQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Peter Jones , Matthew Garrett , Gerd Hoffmann , Kees Cook , "H. Peter Anvin" , =?UTF-8?q?Marvin=20H=C3=A4user?= Subject: [PATCH 14/17] x86/boot: Drop PE/COFF .reloc section Date: Fri, 18 Aug 2023 15:44:19 +0200 Message-Id: <20230818134422.380032-15-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230818134422.380032-1-ardb@kernel.org> References: <20230818134422.380032-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4068; i=ardb@kernel.org; h=from:subject; bh=qP277qhLgzUM7xLfNEHA2KtyZSQajU/8gNGhoczKCNU=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIeV+6Vr+peb/F52Qf3dWb15c1Tx2/r/n19vX1r44fOvwQ dVv/ziUOkpZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBE8iQY/so5fv1f3BmivW5y kHFCzH+b1qDzfOUpjdWsrSddWSLuvWT4Xxq+LcYg8/Kttgvy12P6C2e+jpwhm8LyLvhzTHD/irs h7AA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ancient buggy EFI loaders may have required a .reloc section to be present at some point in time, but this has not been true for a long time so the .reloc section can just be dropped. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/header.S | 20 ----------- arch/x86/boot/tools/build.c | 35 +++----------------- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index c23c5feef37e55ed..ccfb7a7d8c29275e 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -159,26 +159,6 @@ section_table: IMAGE_SCN_MEM_READ | \ IMAGE_SCN_MEM_EXECUTE # Characteristics - # - # The EFI application loader requires a relocation section - # because EFI applications must be relocatable. The .reloc - # offset & size fields are filled in by build.c. - # - .ascii ".reloc" - .byte 0 - .byte 0 - .long 0 - .long 0 - .long 0 # SizeOfRawData - .long 0 # PointerToRawData - .long 0 # PointerToRelocations - .long 0 # PointerToLineNumbers - .word 0 # NumberOfRelocations - .word 0 # NumberOfLineNumbers - .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ - IMAGE_SCN_MEM_READ | \ - IMAGE_SCN_MEM_DISCARDABLE # Characteristics - #ifdef CONFIG_EFI_MIXED # # The offset & size fields are filled in by build.c. diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 6b6282a96c6ab24d..08065c333b482174 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c @@ -45,8 +45,6 @@ typedef unsigned int u32; /* This must be large enough to hold the entire setup */ u8 buf[(SETUP_SECT_NUM+1)*512]; -#define PECOFF_RELOC_RESERVE 0x20 - #ifdef CONFIG_EFI_MIXED #define PECOFF_COMPAT_RESERVE 0x20 #else @@ -183,24 +181,13 @@ static void update_pecoff_section_header(char *section_name, u32 offset, u32 siz update_pecoff_section_header_fields(section_name, offset, size, size, offset); } -static void update_pecoff_setup_and_reloc(unsigned int size) +static void update_pecoff_setup(unsigned int size) { u32 setup_offset = 0x200; - u32 reloc_offset = size - PECOFF_RELOC_RESERVE - PECOFF_COMPAT_RESERVE; -#ifdef CONFIG_EFI_MIXED - u32 compat_offset = reloc_offset + PECOFF_RELOC_RESERVE; -#endif - u32 setup_size = reloc_offset - setup_offset; + u32 compat_offset = size - PECOFF_COMPAT_RESERVE; + u32 setup_size = compat_offset - setup_offset; update_pecoff_section_header(".setup", setup_offset, setup_size); - update_pecoff_section_header(".reloc", reloc_offset, PECOFF_RELOC_RESERVE); - - /* - * Modify .reloc section contents with a single entry. The - * relocation is applied to offset 10 of the relocation section. - */ - put_unaligned_le32(reloc_offset + 10, &buf[reloc_offset]); - put_unaligned_le32(10, &buf[reloc_offset + 4]); #ifdef CONFIG_EFI_MIXED update_pecoff_section_header(".compat", compat_offset, PECOFF_COMPAT_RESERVE); @@ -217,21 +204,10 @@ static void update_pecoff_setup_and_reloc(unsigned int size) #endif } -static int reserve_pecoff_reloc_section(int c) -{ - /* Reserve 0x20 bytes for .reloc section */ - memset(buf+c, 0, PECOFF_RELOC_RESERVE); - return PECOFF_RELOC_RESERVE; -} - #else -static inline void update_pecoff_setup_and_reloc(unsigned int size) {} +static inline void update_pecoff_setup(unsigned int size) {} -static inline int reserve_pecoff_reloc_section(int c) -{ - return 0; -} #endif /* CONFIG_EFI_STUB */ static int reserve_pecoff_compat_section(int c) @@ -310,7 +286,6 @@ int main(int argc, char ** argv) fclose(file); c += reserve_pecoff_compat_section(c); - c += reserve_pecoff_reloc_section(c); /* Pad unused space with zeros */ setup_sectors = (c + 511) / 512; @@ -320,7 +295,7 @@ int main(int argc, char ** argv) i = setup_sectors*512; memset(buf+c, 0, i-c); - update_pecoff_setup_and_reloc(i); + update_pecoff_setup(i); /* Open and stat the kernel file */ fd = open(argv[2], O_RDONLY); -- 2.39.2