Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp807865ybv; Wed, 5 Feb 2020 15:06:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwrpNK7eXymQiDsaaWTn59WWy1Kggm1Rnlyi8TnWLy/0mg2F3qBGl/2X914a2EqMdfu3OFH X-Received: by 2002:aca:ebc2:: with SMTP id j185mr4865922oih.71.1580943964599; Wed, 05 Feb 2020 15:06:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580943964; cv=none; d=google.com; s=arc-20160816; b=q/mPm7dkfYFTkwxZ2X1GoBmeNztvtVo+BWi0fpXxCOXi2UZy1dJCnOCzBsDrdhf7a8 ySRTvgyTTqDI8Nj1d81kTQtFDDNfelJIK1SNKh7eteOiv+mR48oSHv9BuKwJjNNa2DP5 zOdYy9e9fmr5Aan13F13ka/nLvuBRsaPg2/J2tgwYlxac1IwEwVD7CZQAA2vhSCiCWen gs1Jmc0y4CWpWfjatSn59O3bzi13LPKrQJXLaLMd+VQrItxVBf+LkVg7afwL2et+Qpfb vsyomhL7B5ptJ23vBUuH84YADFs6SWM8LRV3F9Y/Y79Je/JQi5O4/2gDCAFibbMYHCkS etHA== 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; bh=P9njH8CCNbTrs8/3yGAFngiaFzdsrGwdzI2HlFmG0tY=; b=eJkSoFHrFN7xgWZHx4nmPBwW+6uOMaBhsJPqaB4Ji34dIYlPKpbw+A+kkClRs/wC4q stZffwUCr/g1s0mgQttIEYr5WWEa7q9DT46K65n9QESNMSYJ5/oKVo1jflPx+pk+DOX8 5R0ZNH2B3UtqJEO2bP7piLxYD+JdGMk+Vi1u4DcqZeS4ywxiH6UczQTfa9pTVgy3XGhn ++czLrXfqPuDpe4aRx0pFuQaJHkTwYqDgD+skxw+UyXsHvviAOfY1yDb27OVC0fkmsNu zfrdXFzsL6uPQpGDOKocpPb9lcBSGlHkw+wl8diLQS4ROeckJwPcBaKvM68AzJzIpn/3 ek7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id s204si1133252oie.82.2020.02.05.15.05.52; Wed, 05 Feb 2020 15:06:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727457AbgBEWjm (ORCPT + 99 others); Wed, 5 Feb 2020 17:39:42 -0500 Received: from mga02.intel.com ([134.134.136.20]:60116 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727389AbgBEWji (ORCPT ); Wed, 5 Feb 2020 17:39:38 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2020 14:39:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,407,1574150400"; d="scan'208";a="225092452" Received: from unknown (HELO localhost.jf.intel.com) ([10.54.75.26]) by fmsmga007.fm.intel.com with ESMTP; 05 Feb 2020 14:39:36 -0800 From: Kristen Carlson Accardi To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, arjan@linux.intel.com, keescook@chromium.org Cc: rick.p.edgecombe@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Kristen Carlson Accardi Subject: [RFC PATCH 06/11] x86: make sure _etext includes function sections Date: Wed, 5 Feb 2020 14:39:45 -0800 Message-Id: <20200205223950.1212394-7-kristen@linux.intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200205223950.1212394-1-kristen@linux.intel.com> References: <20200205223950.1212394-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 We will be 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). However, we need to move _etext so that it is after both .text and .text.* We also need to calculate text size to include .text AND .text.* Signed-off-by: Kristen Carlson Accardi --- 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 3a1a819da137..e54e9ac5b429 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -146,8 +146,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 e00f41aa8ec4..edf19f4296e2 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -798,7 +798,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.24.1