Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933171AbbLOIJh (ORCPT ); Tue, 15 Dec 2015 03:09:37 -0500 Received: from mail.kernel.org ([198.145.29.136]:33964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932184AbbLOIJe (ORCPT ); Tue, 15 Dec 2015 03:09:34 -0500 From: Andy Lutomirski To: Pavel Machek , x86@kernel.org Cc: Arjan van de Ven , Linus Torvalds , Borislav Petkov , linux-kernel@vger.kernel.org, Stephen Smalley , Brian Gerst , Denys Vlasenko , hpa@zytor.com, Mike Galbraith , Peter Zijlstra , Andy Lutomirski Subject: [PATCH 1/2] x86_32/mm: Set NX in __supported_pte_mask before enabling paging Date: Tue, 15 Dec 2015 00:09:29 -0800 Message-Id: <69d86767981330ca2255a791bf457fbe0253f8f4.1450166786.git.luto@kernel.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: <20151215075656.GA3734@amd> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1571 Lines: 54 There's a short window in which very early mappings can end up with NX clear because they are created before we've noticed that we have NX. It turns out that we detect NX very early, so there's no need to defer __supported_pte_mask setup. Signed-off-by: Andy Lutomirski --- arch/x86/kernel/head_32.S | 6 ++++++ arch/x86/mm/setup_nx.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S index 6bc9ae24b6d2..57fc3f8c85fd 100644 --- a/arch/x86/kernel/head_32.S +++ b/arch/x86/kernel/head_32.S @@ -389,6 +389,12 @@ default_entry: /* Make changes effective */ wrmsr + /* + * And make sure that all the mappings we set up have NX set from + * the beginning. + */ + orl $(1 << (_PAGE_BIT_NX - 32)), pa(__supported_pte_mask + 4) + enable_paging: /* diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c index 90555bf60aa4..5095ecb0719c 100644 --- a/arch/x86/mm/setup_nx.c +++ b/arch/x86/mm/setup_nx.c @@ -31,9 +31,8 @@ early_param("noexec", noexec_setup); void x86_configure_nx(void) { - if (cpu_has_nx && !disable_nx) - __supported_pte_mask |= _PAGE_NX; - else + /* If disable_nx is set, clear NX on all new mappings going forward. */ + if (disable_nx) __supported_pte_mask &= ~_PAGE_NX; } -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/