Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1572941ybk; Thu, 21 May 2020 09:59:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMOVu+ObDej+qQ3MZQuIaeAnk7n83AgngzKCyZ7XfArLIRtBjJqqzEAQKR882f9UieAtz+ X-Received: by 2002:a17:906:7684:: with SMTP id o4mr4655599ejm.449.1590080395474; Thu, 21 May 2020 09:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590080395; cv=none; d=google.com; s=arc-20160816; b=G/7U8eSgF4Z/BbuRuAS4xI6wZW0Tgr3AI1YBrFRmWBerXXCmhWEqeWjTN66nGMcpc8 sBvO5gExFTePDvrXLaCtCJXhYLh3IWitgqPDFncQyJL5HrKtZtPTRmtCcJ9fFrvY+dci r0Zi0akF9P5mPwOHKRzglQ8ZgJAMXK+0JaopyrC42pYKtj/CVDYSKYHCoYtRSpIRtdDJ F1LJ8NlX8GGMi72hjhynV1ExELq3kzAgiSYzsqMGP2QxnDyMPNAzkJUJ8O5QmgY4YGyR OduN2jwUktmSYW/6D+tVqnzo2hPZhDZzIol4kyvbk8wlYed9CVxHCESrvRi5e9YDqjKW GU8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=80dRjz+oTmXaQBMcd1v1B20f4xSHYYKfWEFAoBXL8a8=; b=YyXO50T+z/oWkQ9mfNcot5ov9tY+dX+rTikBHNdKZ/Rp/7UBX8FDQNwCdCwWVW1ics +0TPP2skyJed5kIkzv7YmFOMjsH4d9j+1YgazE5DBI2Pb4RUadfSM0M6v4almkbb6ui8 t76wDRuhVwhhA6y5AJmDHVO0X1zQhiK0ItH7NCpweh1FCtCdtmAZNm0dgm3pHmeVVcAi hueI6XBCKbXq5k+0oXxVwIJeIxIjPyTA0hMOb1enfGvC9AmsQ7pTCG73IUZV/vrXXK2S dAfK8l1ippx7mNnI1qvuLPXMHKKJsvnhBlaTr6gSUXgeUEdeaPdh6RXhzp2D7qwO/idJ Sguw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r28si3644495edc.610.2020.05.21.09.59.33; Thu, 21 May 2020 09:59:55 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730182AbgEUQ5Y (ORCPT + 99 others); Thu, 21 May 2020 12:57:24 -0400 Received: from mga02.intel.com ([134.134.136.20]:46206 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730138AbgEUQ5V (ORCPT ); Thu, 21 May 2020 12:57:21 -0400 IronPort-SDR: ytGNl485kZmMLgJZnTecbBroAA/trbVjDhuI7809p58y4e0LpSwyO0NqhHeFWmozinjmz6jX2x o62ZMm0LrC6w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 09:57:19 -0700 IronPort-SDR: 9SfFdTDsfAhfALwEknMLqp3h+TL9Dg7I6I5yl5HH9puVrI4kq6G9/gJCimlW63xkeR0vPBBGXK i9FqhpFLOFAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,418,1583222400"; d="scan'208";a="309094735" Received: from kcaccard-mobl.amr.corp.intel.com (HELO kcaccard-mobl1.jf.intel.com) ([10.212.147.236]) by FMSMGA003.fm.intel.com with ESMTP; 21 May 2020 09:57:17 -0700 From: Kristen Carlson Accardi To: keescook@chromium.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann Cc: arjan@linux.intel.com, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, rick.p.edgecombe@intel.com, Kristen Carlson Accardi , Tony Luck , linux-arch@vger.kernel.org Subject: [PATCH v2 5/9] x86: Make sure _etext includes function sections Date: Thu, 21 May 2020 09:56:36 -0700 Message-Id: <20200521165641.15940-6-kristen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200521165641.15940-1-kristen@linux.intel.com> References: <20200521165641.15940-1-kristen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using -ffunction-sections to place each function in it's own text section so it can be randomized at load time, the linker considers these .text.* sections "orphaned sections", and will place them after the first similar section (.text). In order to accurately represent the end of the text section and the orphaned sections, _etext must be moved so that it is after both .text and .text.* The text size must also be calculated to include .text AND .text.* Signed-off-by: Kristen Carlson Accardi Reviewed-by: Tony Luck Tested-by: Tony Luck --- arch/x86/kernel/vmlinux.lds.S | 18 +++++++++++++++++- include/asm-generic/vmlinux.lds.h | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 1bf7e312361f..044f7528a2f0 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -147,8 +147,24 @@ SECTIONS #endif } :text =0xcccc - /* End of text section, which should occupy whole number of pages */ +#ifdef CONFIG_FG_KASLR + /* + * -ffunction-sections creates .text.* sections, which are considered + * "orphan sections" and added after the first similar section (.text). + * Adding this ALIGN statement causes the address of _etext + * to be below that of all the .text.* orphaned sections + */ + . = ALIGN(PAGE_SIZE); +#endif _etext = .; + + /* + * the size of the .text section is used to calculate the address + * range for orc lookups. If we just use SIZEOF(.text), we will + * miss all the .text.* sections. Calculate the size using _etext + * and _stext and save the value for later. + */ + text_size = _etext - _stext; . = ALIGN(PAGE_SIZE); X86_ALIGN_RODATA_BEGIN diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 71e387a5fe90..f5baee74854c 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -813,7 +813,7 @@ . = ALIGN(4); \ .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \ orc_lookup = .; \ - . += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) / \ + . += (((text_size + LOOKUP_BLOCK_SIZE - 1) / \ LOOKUP_BLOCK_SIZE) + 1) * 4; \ orc_lookup_end = .; \ } -- 2.20.1