Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1940112imm; Sat, 4 Aug 2018 14:39:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd5lKjC+6ZHNk5v14jHijIuDw6wgyaDY6p2+kxJi2OE0ZD2p1TAufyNZ37e1yBqNCZgK4st X-Received: by 2002:a17:902:8d96:: with SMTP id v22-v6mr8366784plo.176.1533418771944; Sat, 04 Aug 2018 14:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533418771; cv=none; d=google.com; s=arc-20160816; b=KA02qW4OKpgE2d1eUROjDyTGvBO6n5pcnt65lM6wIWFhXUnG0Fp+Et41TO1+EZJLG8 pToOM7tl58w5nrPtAakJyoYGh7AULXZwG2AWdYLkwkpQSXMyggofHIi4wrmJvk772L9N kTxyFLqFQPxnIzw1673kD3nYyfjzHTLEOxFZUd/PC5ltulBFZqxjp62hR728RwnKo8X1 uaBu1yXoNYlO6lIeQyYiRncxnQEVwEAXO8BsfyjB4jspeyYogPQ/Nsn/hNrZ3DXkKpSb ASKH7E1t9PmGNad7zpdb3c0MTSHQR1jmz3QWoXdrTs4xnzuZPqI0lPy7Kf1DlqxQe3oH rIYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=TPZ3SDHmtit0uSf7FA0lEiwgK3QdXI1gFdr5UNQg2Zc=; b=KZt8wB4PEI6qE+iqkZOxZx2IC45hXyP2jLakQOKJq9xD+g2GNJhmnEaDW3PUwatgB/ PjmUeiQC3hWU17b6w2jk28CxyspcULzGHJaYrv+v/K9nv1uabWHLqYNIsVS5yGhlBEba AuxDL9z7j4ExyXdoMO1MdYDZ1hIVz5gSpw8OI/r3wGj3VKCTDBFF4LeQnypVwcu4aZnR 4YLXa6DDjpkPxK5sgnPGrUEJ07xfwPTyTFPgo4CyIlkO4l0B3KUNfYmLKM4K8qbmJ8BB fDQPr3IpDPH+2fw00hCsni9lriVFm8GV6EeM/M0SUFSCPNLwyMx9hJ5Rv1Bxvm7Qv6kN 872w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JmhweQwP; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9-v6si7518551pgn.177.2018.08.04.14.39.16; Sat, 04 Aug 2018 14:39:31 -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=@kernel.org header.s=default header.b=JmhweQwP; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729669AbeHDXka (ORCPT + 99 others); Sat, 4 Aug 2018 19:40:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:43382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728745AbeHDXka (ORCPT ); Sat, 4 Aug 2018 19:40:30 -0400 Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 897C321854 for ; Sat, 4 Aug 2018 21:38:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533418706; bh=UgbtdEUDMwTAfPp0oHVk4r5WX30LlpoPgFC2Bdrs9j8=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=JmhweQwP5SH5dBW6831qTFSGAE5SgryNM2JxMrrt9wSyv0/c28q8GaU/rDT/+e+7m c70WLOD56yRZZbUffvGS9ogrc/CZf/SASkSh3G2/IN5mb8zO8SGklOCaXC+yQAqmSc x0DDOWf5uVQplPt3sCiULACv+yzi0wsBpyPwJHqQ= Received: by mail-wm0-f48.google.com with SMTP id t25-v6so10114417wmi.3 for ; Sat, 04 Aug 2018 14:38:26 -0700 (PDT) X-Gm-Message-State: AOUpUlHtBdApLiIVTiyw2OzH6iHXmRbEvfjbzRP/+/25BGITHgerZJMw b9FsGTG6EmNELacuC606Xvg6k8Llg2m5ppYuYWTDNQ== X-Received: by 2002:a1c:8b0d:: with SMTP id n13-v6mr7488513wmd.46.1533418704915; Sat, 04 Aug 2018 14:38:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:548:0:0:0:0:0 with HTTP; Sat, 4 Aug 2018 14:38:04 -0700 (PDT) In-Reply-To: <20180802225831.5F6A2BFC@viggo.jf.intel.com> References: <20180802225823.4711C55B@viggo.jf.intel.com> <20180802225831.5F6A2BFC@viggo.jf.intel.com> From: Andy Lutomirski Date: Sat, 4 Aug 2018 14:38:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 5/7] x86/mm/init: remove freed kernel image areas from alias mapping To: Dave Hansen Cc: LKML , Kees Cook , Thomas Gleixner , Ingo Molnar , Andrea Arcangeli , Juergen Gross , Josh Poimboeuf , Greg KH , Peter Zijlstra , Hugh Dickins , Linus Torvalds , Borislav Petkov , Andrew Lutomirski , Andi Kleen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 2, 2018 at 3:58 PM, Dave Hansen wrote: > > From: Dave Hansen > > The kernel image is mapped into two places in the virtual address > space (addresses without KASLR, of course): > > 1. The kernel direct map (0xffff880000000000) > 2. The "high kernel map" (0xffffffff81000000) > > We actually execute out of #2. If we get the address of a kernel > symbol, it points to #2, but almost all physical-to-virtual > translations point to #1. > > Parts of the "high kernel map" alias are mapped in the userspace > page tables with the Global bit for performance reasons. The > parts that we map to userspace do not (er, should not) have > secrets. > > This is fine, except that some areas in the kernel image that > are adjacent to the non-secret-containing areas are unused holes. > We free these holes back into the normal page allocator and > reuse them as normal kernel memory. The memory will, of course, > get *used* via the normal map, but the alias mapping is kept. > > This otherwise unused alias mapping of the holes will, by default > keep the Global bit, be mapped out to userspace, and be > vulnerable to Meltdown. > > Remove the alias mapping of these pages entirely. This is likely > to fracture the 2M page mapping the kernel image near these areas, > but this should affect a minority of the area. > > The pageattr code changes *all* aliases mapping the physical pages > that it operates on (by default). We only want to modify a single > alias, so we need to tweak its behavior. > > This unmapping behavior is currently dependent on PTI being in > place. Going forward, we should at least consider doing this for > all configurations. Having an extra read-write alias for memory > is not exactly ideal for debugging things like random memory > corruption and this does undercut features like DEBUG_PAGEALLOC > or future work like eXclusive Page Frame Ownership (XPFO). > I like this patch, and I tend to think we should (eventually) enable it regardless of PTI. Cleaning up the memory map is generally a good thing. Also, just to make sure I fully understand: the kernel text is aliased in both the direct map and the high map, right? This means that we should be able to make the high kernel mapping have proper RO permissions very early without breaking text_poke() at the minor cost of needing to force a serializing instruction at the end of each big block of text pokes. I think this would be worthwhile, although I suspect we'll uncover *tons* of bugs in the process.