Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756671AbeAINB1 (ORCPT + 1 other); Tue, 9 Jan 2018 08:01:27 -0500 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:39147 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751949AbeAINB0 (ORCPT ); Tue, 9 Jan 2018 08:01:26 -0500 From: Willy Tarreau To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Willy Tarreau , Andy Lutomirski , Borislav Petkov , Brian Gerst , Dave Hansen , Ingo Molnar , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , "H. Peter Anvin" , David Woodhouse , Kees Cook Subject: [RFC PATCH v2 4/6] x86/pti: don't mark the user PGD with _PAGE_NX. Date: Tue, 9 Jan 2018 13:56:18 +0100 Message-Id: <1515502580-12261-5-git-send-email-w@1wt.eu> X-Mailer: git-send-email 2.8.0.rc2.1.gbe9624a In-Reply-To: <1515502580-12261-1-git-send-email-w@1wt.eu> References: <1515502580-12261-1-git-send-email-w@1wt.eu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Since we're going to keep running on the same PGD when returning to userspace for certain performance-critical tasks, we'll need the user pages to be executable. So this code disables the extra protection that was added consisting in marking user pages _PAGE_NX so that this pgd remains usable for userspace. Note: it isn't necessarily the best approach, but one way or another if we want to be able to return to userspace from the kernel, we'll have to have this executable anyway. Another approach might consist in using another pgd for userland+kernel but the current core really looks like an extra careful measure to catch early bugs if any. Note2: Andy's suggestion to instead dynamically disable NX upon page fault seems the most appealing. Signed-off-by: Willy Tarreau Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Ingo Molnar Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Josh Poimboeuf Cc: "H. Peter Anvin" Cc: David Woodhouse Cc: Kees Cook --- arch/x86/mm/pti.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 43d4a4a..9e2dca0 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -135,9 +135,11 @@ pgd_t __pti_set_user_pgd(pgd_t *pgdp, pgd_t pgd) * - we don't have NX support * - we're clearing the PGD (i.e. the new pgd is not present). */ +#if 0 if ((pgd.pgd & (_PAGE_USER|_PAGE_PRESENT)) == (_PAGE_USER|_PAGE_PRESENT) && (__supported_pte_mask & _PAGE_NX)) pgd.pgd |= _PAGE_NX; +#endif /* return the copy of the PGD we want the kernel to use: */ return pgd; -- 1.7.12.1