Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1649984pxj; Fri, 18 Jun 2021 11:42:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDU+mpcgDUt4p0W6rNKgzret/zl3uKAaEz8g/6OaKNJRsfIY+eLS3aTd9ARd3VoZfsIBTC X-Received: by 2002:a5e:8349:: with SMTP id y9mr8846797iom.105.1624041771365; Fri, 18 Jun 2021 11:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624041771; cv=none; d=google.com; s=arc-20160816; b=Yfllo3Nlq18rN3blgdzkI5mmD0eNdfYo6eRoRs27HzbbbK+9OO/HVPcIZAUysXxO2d pxXclmRK8XLRaPS1ut8hRTm6zvXTB+CiFPUrIgxE7uqkS8auXLWYoKzpMT+7hqxMplAC byG3DCiD+0vrfMLQHSehbWtWL7poEt4uII7WUtsmIK1NJIh9WQvfjABiB8Do3ssjH3g5 RDGaYjSOKlChHVOLF6BALEnKd/EtOR7KsGWe5KtpdVRJM8R9QZbDKal9+VVfXcriE0hk O7P6aVIQ1pcyztGIkqkctzDneNMR3pNkUvfwVYIbWSxckQTJIB5dqeooGC9uQtwUdUCn 6VDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=g5RTqi/e2VZEnD4YII83visKqCzEsKpSz2d4ciHrfvI=; b=bafX++h4ABVRPDpwB3RX967EX3uO5Y+Z87OZ4QO7/ZKd80WJvRjg/Sl6wghVganjUn VRP7gSYuMfP7xecxhjMZqw5DS+7ayIYTAo3bhVCh8i1X8QmsANSyhBHo7zSM1E5KkrpA kMBnGt5uCyOhY8kxpkWLMTDZdyGho7NHiHbWQFO05JkrM9xz8l95ZyUnwtKxWreVQc7h RGP1JXXZOR9y7xNVC9qoGTzthGQEihHtkEyHf73tjXL+1ddo3NC72SnXIKf+QgrSJAiv 3Umnbqsv4O13o/OQgzDDMfoV2pdKoG3OMBlQCRNW2HN4i/jiIdMuu4BFUQXtHXHvF+h/ YkTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=J5OVyn8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k24si10235043jan.49.2021.06.18.11.42.38; Fri, 18 Jun 2021 11:42:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=J5OVyn8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235770AbhFRQK1 (ORCPT + 99 others); Fri, 18 Jun 2021 12:10:27 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:23376 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234403AbhFRQJx (ORCPT ); Fri, 18 Jun 2021 12:09:53 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15IG0sKU005131; Fri, 18 Jun 2021 16:06:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=g5RTqi/e2VZEnD4YII83visKqCzEsKpSz2d4ciHrfvI=; b=J5OVyn8YADZ1xCs67GxaeKo0XEMBqF5k82yuOVWu1vhDdmtyIOh17b3Peckiho9IBRI8 PUWjIvNQiSKUzZaQ8+6CKUBJdIm5CGvRit1zBO8tVIorFzxac0MjU2gErtw1dIpln9TP OVfGCh3mIxDW7SML4QTiVfGOFVGKPkpg1ClkAaFW5NerjkESfUuFKEHH9f/X5OgBec0q CMWC9XZJsgwT8pFDUaWIES6Jv77dlRsFWVt7V3b0YRSe2AEr/+hm3m0g5WIUOLZl698g bYCuzJdsWHVuItLzK468P/ZcAkmlHwVn836VW9Coo4EJfzhEbT+Y3xg/Vzx20QZg99U6 YA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 397mptmbh9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jun 2021 16:06:56 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 15IG1DgW172978; Fri, 18 Jun 2021 16:06:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 396way7631-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jun 2021 16:06:55 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 15IG6sFj014246; Fri, 18 Jun 2021 16:06:54 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 396way761q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Jun 2021 16:06:54 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 15IG6jD2002531; Fri, 18 Jun 2021 16:06:45 GMT Received: from lateralus.us.oracle.com (/10.149.232.101) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 18 Jun 2021 16:06:45 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, iommu@lists.linux-foundation.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, luto@amacapital.net, trenchboot-devel@googlegroups.com Subject: [PATCH v2 01/12] x86/boot: Place kernel_info at a fixed offset Date: Fri, 18 Jun 2021 12:12:46 -0400 Message-Id: <1624032777-7013-2-git-send-email-ross.philipson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1624032777-7013-1-git-send-email-ross.philipson@oracle.com> References: <1624032777-7013-1-git-send-email-ross.philipson@oracle.com> X-Proofpoint-GUID: -QRecCBmK_5XwLnJX6fuA2k3sPD-9GF9 X-Proofpoint-ORIG-GUID: -QRecCBmK_5XwLnJX6fuA2k3sPD-9GF9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arvind Sankar There are use cases for storing the offset of a symbol in kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header in kernel_info. Since commit (note: commit ID from tip/master) 527afc212231 ("x86/boot: Check that there are no run-time relocations") run-time relocations are not allowed in the compressed kernel, so simply using the symbol in kernel_info, as .long symbol will cause a linker error because this is not position-independent. With kernel_info being a separate object file and in a different section from startup_32, there is no way to calculate the offset of a symbol from the start of the image in a position-independent way. To enable such use cases, put kernel_info into its own section which is placed at a predetermined offset (KERNEL_INFO_OFFSET) via the linker script. This will allow calculating the symbol offset in a position-independent way, by adding the offset from the start of kernel_info to KERNEL_INFO_OFFSET. Ensure that kernel_info is aligned, and use the SYM_DATA.* macros instead of bare labels. This stores the size of the kernel_info structure in the ELF symbol table. Signed-off-by: Arvind Sankar Cc: Ross Philipson Signed-off-by: Ross Philipson --- arch/x86/boot/compressed/kernel_info.S | 19 +++++++++++++++---- arch/x86/boot/compressed/kernel_info.h | 12 ++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 arch/x86/boot/compressed/kernel_info.h diff --git a/arch/x86/boot/compressed/kernel_info.S b/arch/x86/boot/compressed/kernel_info.S index f818ee8..c18f071 100644 --- a/arch/x86/boot/compressed/kernel_info.S +++ b/arch/x86/boot/compressed/kernel_info.S @@ -1,12 +1,23 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include #include +#include "kernel_info.h" - .section ".rodata.kernel_info", "a" +/* + * If a field needs to hold the offset of a symbol from the start + * of the image, use the macro below, eg + * .long rva(symbol) + * This will avoid creating run-time relocations, which are not + * allowed in the compressed kernel. + */ + +#define rva(X) (((X) - kernel_info) + KERNEL_INFO_OFFSET) - .global kernel_info + .section ".rodata.kernel_info", "a" -kernel_info: + .balign 16 +SYM_DATA_START(kernel_info) /* Header, Linux top (structure). */ .ascii "LToP" /* Size. */ @@ -19,4 +30,4 @@ kernel_info: kernel_info_var_len_data: /* Empty for time being... */ -kernel_info_end: +SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) diff --git a/arch/x86/boot/compressed/kernel_info.h b/arch/x86/boot/compressed/kernel_info.h new file mode 100644 index 00000000..c127f84 --- /dev/null +++ b/arch/x86/boot/compressed/kernel_info.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BOOT_COMPRESSED_KERNEL_INFO_H +#define BOOT_COMPRESSED_KERNEL_INFO_H + +#ifdef CONFIG_X86_64 +#define KERNEL_INFO_OFFSET 0x500 +#else /* 32-bit */ +#define KERNEL_INFO_OFFSET 0x100 +#endif + +#endif /* BOOT_COMPRESSED_KERNEL_INFO_H */ diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 112b237..84c7b4d 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -7,6 +7,7 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) #include #include +#include "kernel_info.h" #ifdef CONFIG_X86_64 OUTPUT_ARCH(i386:x86-64) @@ -27,6 +28,11 @@ SECTIONS HEAD_TEXT _ehead = . ; } + .rodata.kernel_info KERNEL_INFO_OFFSET : { + *(.rodata.kernel_info) + } + ASSERT(ABSOLUTE(kernel_info) == KERNEL_INFO_OFFSET, "kernel_info at bad address!") + .rodata..compressed : { *(.rodata..compressed) } -- 1.8.3.1