From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752056AbdKZW0K (ORCPT ); Sun, 26 Nov 2017 17:26:10 -0500 Received: from mail.skyhub.de ([5.9.137.197]:60698 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751816AbdKZW0J (ORCPT ); Sun, 26 Nov 2017 17:26:09 -0500 Date: Sun, 26 Nov 2017 23:25:58 +0100 From: Borislav Petkov To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Thomas Gleixner , "H . Peter Anvin" , Peter Zijlstra , Linus Torvalds Subject: Re: [PATCH 25/43] x86/mm/kaiser: Unmap kernel from userspace page tables (core patch), noexec=off Message-ID: <20171126222558.wkdrsp2laxmsmoib@pd.tnic> References: <20171124172411.19476-1-mingo@kernel.org> <20171124172411.19476-26-mingo@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20171124172411.19476-26-mingo@kernel.org> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 24, 2017 at 06:23:53PM +0100, Ingo Molnar wrote: > + * Take a PGD location (pgdp) and a pgd value that needs > + * to be set there. Populates the shadow and returns > + * the resulting PGD that must be set in the kernel copy > + * of the page tables. > + */ > +static inline pgd_t kaiser_set_shadow_pgd(pgd_t *pgdp, pgd_t pgd) > +{ > +#ifdef CONFIG_KAISER > + if (pgd_userspace_access(pgd)) { > + if (pgdp_maps_userspace(pgdp)) { > + /* > + * The user/shadow page tables get the full > + * PGD, accessible from userspace: > + */ > + kernel_to_shadow_pgdp(pgdp)->pgd = pgd.pgd; > + /* > + * For the copy of the pgd that the kernel > + * uses, make it unusable to userspace. This > + * ensures if we get out to userspace with the > + * wrong CR3 value, userspace will crash > + * instead of running. > + */ > + pgd.pgd |= _PAGE_NX; Lemme hold this down here so that we don't forget (and tglx is working on it already... ): So we need to handle the case where we boot with "noexec=off" and thus clear _PAGE_NX from __supported_pte_mask. I'd vouch for a conservative solution where we warn if _PAGE_NX is not set in __supported_pte_mask and thus at least tell the user that she shouldn't do noexec kernels and expect kaiser protection... -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.