From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752231AbdKZOst (ORCPT ); Sun, 26 Nov 2017 09:48:49 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:43603 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752147AbdKZOsr (ORCPT ); Sun, 26 Nov 2017 09:48:47 -0500 X-Google-Smtp-Source: AGs4zMYw1V98loO9E+yepErfbEMfmPjE6ein8XWfPwRqMOx0K0r/+f1Y7mKDgXY+2foKqKD0vYnccg== Date: Sun, 26 Nov 2017 15:48:42 +0100 From: Ingo Molnar To: Rik van Riel Cc: Dave Hansen , linux-kernel@vger.kernel.org, linux-mm@kvack.org, bp@suse.de, tglx@linutronix.de, moritz.lipp@iaik.tugraz.at, daniel.gruss@iaik.tugraz.at, michael.schwarz@iaik.tugraz.at, richard.fellner@student.tugraz.at, luto@kernel.org, torvalds@linux-foundation.org, keescook@google.com, hughd@google.com, x86@kernel.org Subject: Re: [PATCH 04/30] x86, kaiser: disable global pages by default with KAISER Message-ID: <20171126144842.7ojxbo5wsu44w4ti@gmail.com> References: <20171110193058.BECA7D88@viggo.jf.intel.com> <20171110193105.02A90543@viggo.jf.intel.com> <1510688325.1080.1.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1510688325.1080.1.camel@redhat.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Rik van Riel wrote: > On Fri, 2017-11-10 at 11:31 -0800, Dave Hansen wrote: > > From: Dave Hansen > > > > Global pages stay in the TLB across context switches.  Since all > > contexts > > share the same kernel mapping, these mappings are marked as global > > pages > > so kernel entries in the TLB are not flushed out on a context switch. > > > > But, even having these entries in the TLB opens up something that an > > attacker can use [1]. > > > > That means that even when KAISER switches page tables on return to > > user > > space the global pages would stay in the TLB cache. > > > > Disable global pages so that kernel TLB entries can be flushed before > > returning to user space. This way, all accesses to kernel addresses > > from > > userspace result in a TLB miss independent of the existence of a > > kernel > > mapping. > > > > Replace _PAGE_GLOBAL by __PAGE_KERNEL_GLOBAL and keep _PAGE_GLOBAL > > available so that it can still be used for a few selected kernel > > mappings > > which must be visible to userspace, when KAISER is enabled, like the > > entry/exit code and data. > > Nice changelog. > > Why am I pointing this out? > > > +++ b/arch/x86/include/asm/pgtable_types.h 2017-11-10 > > 11:22:06.626244956 -0800 > > @@ -179,8 +179,20 @@ enum page_cache_mode { > >  #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | > > _PAGE_USER | \ > >    _PAGE_ACCESSED) > >   > > +/* > > + * Disable global pages for anything using the default > > + * __PAGE_KERNEL* macros.  PGE will still be enabled > > + * and _PAGE_GLOBAL may still be used carefully. > > + */ > > +#ifdef CONFIG_KAISER > > +#define __PAGE_KERNEL_GLOBAL 0 > > +#else > > +#define __PAGE_KERNEL_GLOBAL _PAGE_GLOBAL > > +#endif > > + > > The comment above could use a little more info > on why things are done that way, though :) Good point - I've updated these comments to say: /* * Disable global pages for anything using the default * __PAGE_KERNEL* macros. * * PGE will still be enabled and _PAGE_GLOBAL may still be used carefully * for a few selected kernel mappings which must be visible to userspace, * when KAISER is enabled, like the entry/exit code and data. */ #ifdef CONFIG_KAISER #define __PAGE_KERNEL_GLOBAL 0 #else #define __PAGE_KERNEL_GLOBAL _PAGE_GLOBAL #endif ... and I've added your Reviewed-by tag which I assume now applies? Thanks, Ingo