Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2133307ybh; Fri, 17 Jul 2020 10:02:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpf7z1hNmBpyReKDlj/6KcRzUpFLskvqa8WLcMT4IvducJD9TqjTsblZUUgrChT1zlY5Gd X-Received: by 2002:a17:906:6446:: with SMTP id l6mr9893860ejn.184.1595005364437; Fri, 17 Jul 2020 10:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595005364; cv=none; d=google.com; s=arc-20160816; b=BNWa0fLvqlXdDAtKRZzfnTYJgJfy/fp8woJ2eaujHv/58LZKn7rWOjLcRvUMS+tHhy pMkLxj2FF7LQ8DIh0isrd2E57Gu6YZPAm2PubD5ik098owghvxLOZVMdQ7ciiE0rUHPC LrmByDzeE4/DNU7r4gK0h29O3JTAL9P9LLS23HmAdWQ+wOW4YD96/4sWpzrrbBNzsf0u GLXC4BFOpwa/ljB4z7HKYuS5+HBLI8Pc0d2avzdtIhz7DymstQzLxxDpsA6Oe1RqwPkG sgbw5Q3u7qmYpcL3I1Jebcrwt6Wo4hs/Zsf8bOGg9YBYoyXQwwetnBHrfeRvqPmERI9U pKKA== 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=UiE7PTRSg/16A634HnsRpS9uOxdXepttHnZkrUtpXPg=; b=Y2BoECpW3PyRxZFuYDeaPSjk0aI+HxI237s0j2f5mDUrfIKE2rOXqrh4bU46A1z/go 8MVoL5MliCB9c6qB9PJ5fU/DK8eSCzznAMyNcnOfr5s4aQ00fZQl062by66/GVOIIyQA fpu2iqx+vomeWuNDFNtrrD+WFjBFHa8D5Y3iM0TdX54lTcYUkTFpOthehMuBASx5U6j0 nC+/mxjCzqVqAOUakb85mKGO2SaTMO5DeVHrqKCYfIbdB8MGlrmmiT+PwvgLP6aw5/Fr chDHr+Cod3J8SpC6wjCCWsxLrImWWtvDmMTTtswT1K7a6wwuyXHC3e0rhICK90gkJb6E amwA== 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 a16si6144294ejk.194.2020.07.17.10.02.20; Fri, 17 Jul 2020 10:02:44 -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 S1728102AbgGQRAy (ORCPT + 99 others); Fri, 17 Jul 2020 13:00:54 -0400 Received: from mga18.intel.com ([134.134.136.126]:1883 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726938AbgGQRAx (ORCPT ); Fri, 17 Jul 2020 13:00:53 -0400 IronPort-SDR: bTi94862T7nBQMCgUaPxkf7WAddi+kzWSTVh3cEvI2APVZGkqIRmqRoHLYShKdllJBdAE2pOJd 1kTHRsvVkkvw== X-IronPort-AV: E=McAfee;i="6000,8403,9685"; a="137102881" X-IronPort-AV: E=Sophos;i="5.75,362,1589266800"; d="scan'208";a="137102881" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2020 10:00:50 -0700 IronPort-SDR: /V6RtfUS+C686duNWWoKoKTY1Px7zJvGYSGnXaZmHpZxO+uuOWVeof5/iYHkrPO+i1HAgzStE+ upAd5+rglRDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,362,1589266800"; d="scan'208";a="270862091" Received: from kcaccard-mobl.amr.corp.intel.com (HELO kcaccard-mobl1.jf.intel.com) ([10.212.33.149]) by fmsmga008.fm.intel.com with ESMTP; 17 Jul 2020 10:00:43 -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 v4 05/10] x86: Make sure _etext includes function sections Date: Fri, 17 Jul 2020 10:00:02 -0700 Message-Id: <20200717170008.5949-6-kristen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200717170008.5949-1-kristen@linux.intel.com> References: <20200717170008.5949-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 Reviewed-by: Kees Cook --- arch/x86/kernel/vmlinux.lds.S | 17 +++++++++++++++-- include/asm-generic/vmlinux.lds.h | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 3bfc8dd8a43d..e8da7eeb4d8d 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -146,9 +146,22 @@ SECTIONS #endif } :text =0xcccc - /* End of text section, which should occupy whole number of pages */ - _etext = .; + /* + * -ffunction-sections creates .text.* sections, which are considered + * "orphan sections" and added after the first similar section (.text). + * Placing this ALIGN statement before _etext causes the address of + * _etext to be below that of all the .text.* orphaned sections + */ . = ALIGN(PAGE_SIZE); + _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; X86_ALIGN_RODATA_BEGIN RO_DATA(PAGE_SIZE) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index a5552cf28d5d..34eab6513fdc 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -835,7 +835,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