Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp162531lqh; Thu, 30 May 2024 18:33:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxhSiyUzdL4izbe3bCGQflh7EHXNBqHY8di8Zmsgw+o+nopPofqEq/0fNxPFJn/NJeS1SEqC8Cju+JEFmQIDXQOPdKL/t9Mu6OvKPr6g== X-Google-Smtp-Source: AGHT+IECIV5pI9bDq400X9y9KLNutJWo5BwAwsFhSJDWtx43zbsyb0nPxMEILKLn+HPsdMvd1KQV X-Received: by 2002:a25:c590:0:b0:df7:93e1:a130 with SMTP id 3f1490d57ef6-dfa73c17927mr678327276.36.1717119195530; Thu, 30 May 2024 18:33:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717119195; cv=pass; d=google.com; s=arc-20160816; b=gRRZ7plb1iSt/G6CLP39iuCb96IICUx50/DhNQdgLhhsyvrH/L2+Rw9Yhf4yiHAlpm DWu6GzTSVVuIhR2H9sSnXJfz5Vuj4o+tx3ffeNeWUb8nJONpKRPJor1Xo6caLJSq2HSI dyMZyi2KzURlEdQCJH8kTqx/3/wUoLq9sJDNiCXlTZh+yp+ZN/t/RY7uhFrqy6/wBnww YofaRBuU686P9xfNbnmY6t0VSibeWbtcWOWAN0DFtafkFctVlKP6bzsJg8uY57Y4hxRh 74sc4wN/usuP9okgOUs6l5uSMJviBAdtKj0gYf1BbdxcuM871gLcqM2Rlm7Dxqh9wqZr IBNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Bnh/jsO288oZNYgrOSrsCN18bQgzJILZGG0JJNquEks=; fh=ksrYNUbdo9+K4DYOCXVji8cRdTI1C1SaRA8HdvQyCiA=; b=JwjQbqgMFiIctpCQCwm+/PO2sxaT2ew4r7qwW33FkZvz0FCv7a+mxG4ZFdQpxTUpih JllClaJIyXTFvi7DCvzTJxA/asbKSvDn5SU2fUoDbhIHToN7rDsV5MDSvlBum1Ag3b5P JD+HSbE8yF00e3shYvYxd8SJN9AofoxfKpYbWikAMLBWmoGjwVUeG8EAHijXqz8WEPxp vrVbMSyZKhlnAsUbmQqZ1Z3sEiaIe9SRpc4x0xf7KqLKtL0nZIos+HNqW4pefjhKpxcF ooNsjK7cFJSpKIqqpQUWC18KMVSiKYUTaLYyu+v2NPss9WQHn0YydXz2r/9ZicElIW9Q wD6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=neutral (bad format) header.i=@oracle.com; arc=pass (i=1 spf=pass spfdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-crypto+bounces-4549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4b42bf6dsi9622846d6.473.2024.05.30.18.33.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 18:33:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=neutral (bad format) header.i=@oracle.com; arc=pass (i=1 spf=pass spfdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-crypto+bounces-4549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C3B321C24D5F for ; Fri, 31 May 2024 01:33:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51CF61CF92; Fri, 31 May 2024 01:32:19 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 773DFC156; Fri, 31 May 2024 01:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717119139; cv=none; b=QF8O0oi8l58mFhlN/UI7IIdUOip3KwmiXZ7fNO1gSHvMwOFnZg2Xpa44NYarxphASxF0pXs3pYPlBxt7Uan1G5hye47htIIsRDyFQNUBwp35ioO96aWWby/5ZqByavpqh/SkxxhBaj6czwWchbWDv8LP8GNbJ3MalyawyKbIUb4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717119139; c=relaxed/simple; bh=Dv0jYuhg9P0m8GJhffOkLirHUVpBtBN04pgcBG6/UBo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NJ4jJit7A9TbavvQAXkx7inV0H5aiFM4yZNpx+9iYcyAj5TiCxt4Jx67uzVp9KFgqum9VypRLDOSEvEFDaNZOJ3KGkNFLqTSi+3Nc6aK+eDiWeG3N4Aa8db4Uk+GI+eBQbgGpuSjZmO/XbxLjm0xK/Dq/OcKvyKi1FBYt4zO6dM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44UFWoL8004475; Fri, 31 May 2024 01:30:33 GMT DKIM-Signature: =?UTF-8?Q?v=3D1;_a=3Drsa-sha256;_c=3Drelaxed/relaxed;_d=3Doracle.com;_h?= =?UTF-8?Q?=3Dcc:content-transfer-encoding:date:from:in-reply-to:message-i?= =?UTF-8?Q?d:mime-version:references:subject:to;_s=3Dcorp-2023-11-20;_bh?= =?UTF-8?Q?=3DBnh/jsO288oZNYgrOSrsCN18bQgzJILZGG0JJNquEks=3D;_b=3DSxzRZqoD?= =?UTF-8?Q?dK+C8FI/jYKkFxIcLhQoDbCEImjcBGhBqPfHkcuiLg7TcfGFH7I6rd4K9Rf6_gC?= =?UTF-8?Q?F6RvNqQPGIfFqUBTqUklxM20JN2gpjMDiG29loQZhl7fapn1W6pe9pkg0tkItK2?= =?UTF-8?Q?qSA_QbffNt3uyHAQ4BffNXP3acoJvdmSDkkB2lltEYd3mT5svdJK8QvYe9pUTxN?= =?UTF-8?Q?BRcNDn4vh_JjMDFD/uy6f/UqnNvEnJqCKtOvHBLWSAKiV0bGK0GrSbV1DIe5iA+?= =?UTF-8?Q?u1jf/73aoLt8bR4_Xd/QUa/J9Mk2x3oGxH8+iOlN7k2P9kYp65pHyO5F2/8k36t?= =?UTF-8?Q?IqZcgyz6LKJx7Fr9NrpRy_CQ=3D=3D_?= Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yb8hga6yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 May 2024 01:30:32 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 44UNM60s016223; Fri, 31 May 2024 01:30:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3yc50t9761-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 31 May 2024 01:30:32 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44V1SKNG027418; Fri, 31 May 2024 01:30:31 GMT Received: from bur-virt-x6-2-100.us.oracle.com (bur-virt-x6-2-100.us.oracle.com [10.153.92.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3yc50t96yw-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 31 May 2024 01:30:31 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux-foundation.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v9 01/19] x86/boot: Place kernel_info at a fixed offset Date: Thu, 30 May 2024 18:03:13 -0700 Message-Id: <20240531010331.134441-2-ross.philipson@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240531010331.134441-1-ross.philipson@oracle.com> References: <20240531010331.134441-1-ross.philipson@oracle.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-30_21,2024-05-30_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405310010 X-Proofpoint-GUID: rX4yWGFJ9rCFi-fOgEnlV90dOeJugfo9 X-Proofpoint-ORIG-GUID: rX4yWGFJ9rCFi-fOgEnlV90dOeJugfo9 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) commit 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 f818ee8fba38..c18f07181dd5 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 000000000000..c127f84aec63 --- /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 083ec6d7722a..718c52f3f1e6 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) } -- 2.39.3