Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3776184ybt; Tue, 23 Jun 2020 10:25:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCh5tJYN2fhXcOLCMOmIxAa3iV05lI1vB6H0uXB7UWvz1OuXX+Q9gRO+Ygr7zglVQnFQ75 X-Received: by 2002:aa7:da89:: with SMTP id q9mr4584650eds.273.1592933130860; Tue, 23 Jun 2020 10:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592933130; cv=none; d=google.com; s=arc-20160816; b=0GDdwGovLsKwjN/U3LyEhQxxOdQGTo6kwh5HDGSdS8G8l+xmSsaUGGBWWwmSyKycj+ Qx6BD09ym7juqja+PNhCIBUcwgRJy02uUgdr8fornkSHliB9jeE2gWO3N88MUP0HRk+P NX18x93cZRkFIhU5PKcaHcPhjP17FI2Xt5XKG+Hqesy0y96vA07su/P2+v6n6F1dhDmM xgpnKJuQxJdvkshiBWGXkEHM/498tKX24XUJS+sFfFMMkUjDCGNosAoAgzSAdJz4tbPd su1l3cE8Tfi9qkV736Wdah1+xrpe6dLo5eZBPjYRCmTdhBPdcohKAUUq4TuF4d4oug7f 10pA== 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=5ItD/vOtB2Dr5ghuHh0jI3Uh4wELrxYs3PQeu9lAYUo=; b=ugm6szzCm6LLCWB1PG5mgzovRFz3n1AnOlPmWM49uAAyqnvYTPuU7p9M05LOf4T77e cKK7FSvuoGXTT7t/Qa1A9ytdUzGHKUD7BVwBOAvw5NquJ95nUN3InbtE6fVvMnL0ziga EnU5mFdvKumJ48XxXf1G2FALLvXrFjJv6qGK2cOQii2/QM4rWMWNq9AqlQPrVBykvT7t +RV3owyBIyRpoBLHsn8jLD1Wye38GtR15NtEAnzcNPxuKB5OCOCCLurpg3VWmeMRb8SL Iv0Av7GXpEOVBUGO7e2iBRtwryK4LECc4IhmOj+TdtyAI9r8PemXy9vYmRte/EPFYtir E9Xw== 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 b22si11441195edx.194.2020.06.23.10.24.55; Tue, 23 Jun 2020 10:25:30 -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 S1733066AbgFWRYk (ORCPT + 99 others); Tue, 23 Jun 2020 13:24:40 -0400 Received: from mga11.intel.com ([192.55.52.93]:61940 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733130AbgFWRYg (ORCPT ); Tue, 23 Jun 2020 13:24:36 -0400 IronPort-SDR: XQzcqg6RAm4uyvBuTP9EUzhF1/Zpy+fpBJ1wihLaqu4slz4iISN3XaLN/DXRmuaWNGM0RbiXC+ eaxnle/aTcSQ== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="142391493" X-IronPort-AV: E=Sophos;i="5.75,272,1589266800"; d="scan'208";a="142391493" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 10:24:35 -0700 IronPort-SDR: yRJhzfNrUwOMLoy2DUDz43v79VZvHgbwzzZaxQI0bYDJJknbQcAXZPwa3rsXBEL164bV4ls11B H0MY9Eztl3uQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,272,1589266800"; d="scan'208";a="423080075" Received: from kcaccard-mobl.amr.corp.intel.com (HELO kcaccard-mobl1.jf.intel.com) ([10.213.182.184]) by orsmga004.jf.intel.com with ESMTP; 23 Jun 2020 10:24:33 -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 v3 05/10] x86: Make sure _etext includes function sections Date: Tue, 23 Jun 2020 10:23:22 -0700 Message-Id: <20200623172327.5701-6-kristen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200623172327.5701-1-kristen@linux.intel.com> References: <20200623172327.5701-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 | 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