Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp232873ybp; Thu, 10 Oct 2019 17:09:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwj3GPVAw31WxIpQmkYv0e2m4e6dMQSIFDCsnExYG6sIzcfqWWGatxr7mGr1Ik/gSL11nz7 X-Received: by 2002:a17:907:429d:: with SMTP id ny21mr11238215ejb.176.1570752560335; Thu, 10 Oct 2019 17:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570752560; cv=none; d=google.com; s=arc-20160816; b=PbFeyeZrOY7OzIvaR1ynv/10mEmjtWGEIEPSGQyFnD3Yf5icuSESkkTX42d8DtCGK8 p+R4hRGTtnLFoGf3tL6/GFFXe4GNlAkTq++1adJIK458qIZLLMYcbY5yeYmByQr0cGbn 8nSv1c9zvsV84AteEVFMNZiti56X3HckNROVbjoRGovX6QPyuX/ulW4Y5253blAy9g/P Z4Wylctw8JOQX+Hl0NdKBJezauzVQH2NmIYWVBGzYrJ8aC09Wz/GgEf3PgobC8bAYc7O amhMYy5ZYUN5DIQzdTwLHklHJyCbdujQHQHzUMrWUeIUv+/oCzgxBZA57ncsubAi8Aly 3uvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=MEsYo+M8tYJs19WnuB4vdd58NV32mqrr8UAWRisKZTU=; b=Scc3MR7G491D3ajvSyBDfu8fhqAV2EOBYywkdntHUchd1U7A1sh8v9meBJlQbMsY5y 79L4FuaCF3mufGhz+DqSUObV+22Su3R78tVUGiqknjxSJdpnsKK86FRcSHcTD1K7tmD/ HL8ajIR1EWmCmk57SCMXyPIWanmJ+dKanDPbphZDUtRuQaZJVwnbiHCqIyhtPkCmEg8a mMVNz/5OqojKsOoyqLrvAa/85d3LINLxZX5baN7nVOUNWEkWh8yibHQOU/zbDi9Xmwp9 tyB5dajxUCyNFzeatshe1UatGEfDoNUFssmiGlBxEWqWKw0amgYw5YUdk/h2vVHLavij IwoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cke1k+Wo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v26si4205238ejw.276.2019.10.10.17.08.57; Thu, 10 Oct 2019 17:09:20 -0700 (PDT) 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; dkim=pass header.i=@chromium.org header.s=google header.b=Cke1k+Wo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727687AbfJKAGm (ORCPT + 99 others); Thu, 10 Oct 2019 20:06:42 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36450 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727656AbfJKAGh (ORCPT ); Thu, 10 Oct 2019 20:06:37 -0400 Received: by mail-pg1-f194.google.com with SMTP id 23so4704642pgk.3 for ; Thu, 10 Oct 2019 17:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MEsYo+M8tYJs19WnuB4vdd58NV32mqrr8UAWRisKZTU=; b=Cke1k+WoV3d4y7UYLwGR6Cccr6ntETV7w4A+pAdyCIZxanwHXq4EPnvgyBzqAj40+x LiPrWoEPAyegIEPYdAPySyJ4W/aeyE2yAl3to28d7+EqgEkXRjB2PlBmPUXFz9yU7bX0 btdMvXUw872LvztOLh6mK1NAcmtdiy6tXBqrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MEsYo+M8tYJs19WnuB4vdd58NV32mqrr8UAWRisKZTU=; b=EYR6oVUWBpXDVt/Z5zn6fK3ByMQGXMILgp+bNZI8nlfXgdhVsmMThGuFjX1Ij0O+cq WrDds3FuoBekHmnukZlG4Yymih0Wnia03JCTkPR78aZseXqn49nPNbHqWo36ELfCCLak QNMji71UdvHm2RHWEqW4E5uKr9l+6ngCGBBwfwON1baFcVo/vrpavAbVGU6bGVzxz42J UMQ0Zo6rcY5r1wL5Vw5yPdZBOgiP0oX4nLzU21cGL7LPmJGJqXXrC9fjTq5DYsWnQnUW Y5NuIoBRRQFAyapmZrmDY3tSzad3WfW4CEYEsMzD9JDHkCa7hFqNAGGgvcHRlaNBDuPe 3FFQ== X-Gm-Message-State: APjAAAX+24UyFyGdlFEcmssuWE0ByGTPtYww9235pBzdpCeHEThB78bw FAsFJbGgWJ5D5FwAhG3Fse4lJQ== X-Received: by 2002:aa7:8691:: with SMTP id d17mr13279534pfo.218.1570752395513; Thu, 10 Oct 2019 17:06:35 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y28sm7193083pfq.48.2019.10.10.17.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 17:06:32 -0700 (PDT) From: Kees Cook To: Borislav Petkov Cc: Kees Cook , Rick Edgecombe , Dave Hansen , Andy Lutomirski , Arnd Bergmann , Michael Ellerman , Heiko Carstens , Will Deacon , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-alpha@vger.kernel.org, linux-ia64@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michal Simek , linux-parisc@vger.kernel.org, linux-xtensa@linux-xtensa.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 15/29] x86: Actually use _etext for end of text segment Date: Thu, 10 Oct 2019 17:05:55 -0700 Message-Id: <20191011000609.29728-16-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191011000609.29728-1-keescook@chromium.org> References: <20191011000609.29728-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Various calculations are using the end of the exception table (which does not need to be executable) as the end of the text segment. Instead, in preparation for moving the exception table into RO_DATA, move _etext after the exception table and update the calculations. Signed-off-by: Kees Cook --- arch/x86/include/asm/sections.h | 1 - arch/x86/kernel/vmlinux.lds.S | 7 +++---- arch/x86/mm/init_64.c | 6 +++--- arch/x86/mm/pti.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h index 71b32f2570ab..036c360910c5 100644 --- a/arch/x86/include/asm/sections.h +++ b/arch/x86/include/asm/sections.h @@ -6,7 +6,6 @@ #include extern char __brk_base[], __brk_limit[]; -extern struct exception_table_entry __stop___ex_table[]; extern char __end_rodata_aligned[]; #if defined(CONFIG_X86_64) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 41362e90142d..a1a758e25b2b 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -143,15 +143,14 @@ SECTIONS *(.text.__x86.indirect_thunk) __indirect_thunk_end = .; #endif - - /* End of text section */ - _etext = .; } :text = 0x9090 EXCEPTION_TABLE(16) - /* .text should occupy whole number of pages */ + /* End of text section, which should occupy whole number of pages */ + _etext = .; . = ALIGN(PAGE_SIZE); + X86_ALIGN_RODATA_BEGIN RO_DATA(PAGE_SIZE) X86_ALIGN_RODATA_END diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index a6b5c653727b..26299e9ce6da 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1263,7 +1263,7 @@ int kernel_set_to_readonly; void set_kernel_text_rw(void) { unsigned long start = PFN_ALIGN(_text); - unsigned long end = PFN_ALIGN(__stop___ex_table); + unsigned long end = PFN_ALIGN(_etext); if (!kernel_set_to_readonly) return; @@ -1282,7 +1282,7 @@ void set_kernel_text_rw(void) void set_kernel_text_ro(void) { unsigned long start = PFN_ALIGN(_text); - unsigned long end = PFN_ALIGN(__stop___ex_table); + unsigned long end = PFN_ALIGN(_etext); if (!kernel_set_to_readonly) return; @@ -1301,7 +1301,7 @@ void mark_rodata_ro(void) unsigned long start = PFN_ALIGN(_text); unsigned long rodata_start = PFN_ALIGN(__start_rodata); unsigned long end = (unsigned long) &__end_rodata_hpage_align; - unsigned long text_end = PFN_ALIGN(&__stop___ex_table); + unsigned long text_end = PFN_ALIGN(&_etext); unsigned long rodata_end = PFN_ALIGN(&__end_rodata); unsigned long all_end; diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 7f2140414440..44a9f068eee0 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -574,7 +574,7 @@ static void pti_clone_kernel_text(void) */ unsigned long start = PFN_ALIGN(_text); unsigned long end_clone = (unsigned long)__end_rodata_aligned; - unsigned long end_global = PFN_ALIGN((unsigned long)__stop___ex_table); + unsigned long end_global = PFN_ALIGN((unsigned long)_etext); if (!pti_kernel_image_global_ok()) return; -- 2.17.1