Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4498664yba; Wed, 17 Apr 2019 12:50:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAx0HmXlcGCN0V5XOfVFRbs6QFGT82uQ9sflB2c+QIO73DWYH88hQM7bw9bhxzWKNNuild X-Received: by 2002:aa7:8384:: with SMTP id u4mr90886948pfm.214.1555530647395; Wed, 17 Apr 2019 12:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555530647; cv=none; d=google.com; s=arc-20160816; b=WiEZiOPayayOarIyEZjclnRRhwQ2REveAgUv/yYJ4WnH3zKEILExiwlIPKmwkxEff1 DqQrunQjIiRRZ709Z+2sENJHYeOUpl21j71xqLU11AVsR+fNFxC3kdLWAZcsH0G0mVhY iXVcPT3/UxarRdMWj8TBGWde/SEK1TxHhrG/PcmWt2GLtFWubab2kd/8jgNSqulZJQmR F6f91S24yL4jV4nAlaAtnfflf/8BsFjwC/R5Q8hoQro5KE5nNra0ZPeqgUjl98G4P946 rAIxvkg03G5a+JBQ9dJYUozP+lNSC8NY9sjqZ9JkS/8+9tFi6a93Evkz74zhAFBpJloT q57w== 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 :in-reply-to:references:mime-version:dkim-signature; bh=iE6ZxezbsAnxY7b8623590Y49+KIRCSBYNr9ucJ9cPI=; b=uGR6de+VqvvQkIWm6Ahw36mpoLdnqN28ixxfetxnHNtAY+ecQL2kwRK6fcKJk+6x1r 8hv2rqRz4zXQzngmAmnQLKqXUjLJzWtCKklTJt5Ol2VRf6ASWVAKz/fGax4u6om5fO4z FpYrMsTkF3YEz0uCXaahCQi78BqM3xxHqulOSfWzo259CV3w9qW94Lv+TGqcRB/2mi9U uTxI6r0Xk4fyekLAvTaGzIjvBYXIkzQgQf/aiUD+0bnMmw7xyG6VsIURuRu/resF8CO0 uRMP19MiGoTU3wRwfLLqm7tP+CrGG/+TpNwP7RnQqNv4lxLSxpTOGAbm/JInemYrDmxI rhLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LuNxcF2S; 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 w7si48558335pgs.230.2019.04.17.12.50.32; Wed, 17 Apr 2019 12:50:47 -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=LuNxcF2S; 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 S2387416AbfDQTtT (ORCPT + 99 others); Wed, 17 Apr 2019 15:49:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:50610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733114AbfDQTtS (ORCPT ); Wed, 17 Apr 2019 15:49:18 -0400 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 AD5EF2183E for ; Wed, 17 Apr 2019 19:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555530558; bh=un9JngdqTRaqtIrvykfJj/MFL9SGLhvcacMgNjMe4H4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LuNxcF2SUejG3RCYnUi84IwHnSzvhZp333Yg4ShU6P0MGaUA/NTDr3XUm3g4BgmlR 20fu2r8qucKNLAcc3nIREAGx4JbBDxDsqw+oIgiaf6dgKbEh7HbcW8o6Zb/6eLfwFB EE4oZsHUpTpm4eio5i/zvi+yd5mLeu6dUBhVLC4I= Received: by mail-wr1-f43.google.com with SMTP id k11so33517233wro.5 for ; Wed, 17 Apr 2019 12:49:17 -0700 (PDT) X-Gm-Message-State: APjAAAUf3zJTf7n1e3VRxWNjbUHp7lipyvFVCsuvYk3NLUKfBB7zWFSg MTWDOSqOT9CzVN8TTTxWLpP7LMbk+FrRI7b+ktl8xQ== X-Received: by 2002:adf:f344:: with SMTP id e4mr23917370wrp.77.1555530556240; Wed, 17 Apr 2019 12:49:16 -0700 (PDT) MIME-Version: 1.0 References: <20190417161042.GA43453@gmail.com> <20190417170918.GA68678@gmail.com> <8d314750-251c-7e6a-7002-5df2462ada6b@oracle.com> In-Reply-To: <8d314750-251c-7e6a-7002-5df2462ada6b@oracle.com> From: Andy Lutomirski Date: Wed, 17 Apr 2019 12:49:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v9 03/13] mm: Add support for eXclusive Page Frame Ownership (XPFO) To: Khalid Aziz Cc: Ingo Molnar , Juerg Haefliger , Tycho Andersen , jsteckli@amazon.de, Kees Cook , Konrad Rzeszutek Wilk , Juerg Haefliger , deepa.srinivasan@oracle.com, chris hyser , Tyler Hicks , "Woodhouse, David" , Andrew Cooper , Jon Masters , Boris Ostrovsky , iommu@lists.linux-foundation.org, X86 ML , linux-arm-kernel , "open list:DOCUMENTATION" , LKML , Linux-MM , LSM List , Khalid Aziz , Linus Torvalds , Andrew Morton , Thomas Gleixner , Andy Lutomirski , Peter Zijlstra , Dave Hansen , Borislav Petkov , "H. Peter Anvin" , Arjan van de Ven , Greg Kroah-Hartman 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 Wed, Apr 17, 2019 at 10:33 AM Khalid Aziz wrote: > > On 4/17/19 11:09 AM, Ingo Molnar wrote: > > > > * Khalid Aziz wrote: > > > >>> I.e. the original motivation of the XPFO patches was to prevent execution > >>> of direct kernel mappings. Is this motivation still present if those > >>> mappings are non-executable? > >>> > >>> (Sorry if this has been asked and answered in previous discussions.) > >> > >> Hi Ingo, > >> > >> That is a good question. Because of the cost of XPFO, we have to be very > >> sure we need this protection. The paper from Vasileios, Michalis and > >> Angelos - , > >> does go into how ret2dir attacks can bypass SMAP/SMEP in sections 6.1 > >> and 6.2. > > > > So it would be nice if you could generally summarize external arguments > > when defending a patchset, instead of me having to dig through a PDF > > which not only causes me to spend time that you probably already spent > > reading that PDF, but I might also interpret it incorrectly. ;-) > > Sorry, you are right. Even though that paper explains it well, a summary > is always useful. > > > > > The PDF you cited says this: > > > > "Unfortunately, as shown in Table 1, the W^X prop-erty is not enforced > > in many platforms, including x86-64. In our example, the content of > > user address 0xBEEF000 is also accessible through kernel address > > 0xFFFF87FF9F080000 as plain, executable code." > > > > Is this actually true of modern x86-64 kernels? We've locked down W^X > > protections in general. > > > > I.e. this conclusion: > > > > "Therefore, by simply overwriting kfptr with 0xFFFF87FF9F080000 and > > triggering the kernel to dereference it, an attacker can directly > > execute shell code with kernel privileges." > > > > ... appears to be predicated on imperfect W^X protections on the x86-64 > > kernel. > > > > Do such holes exist on the latest x86-64 kernel? If yes, is there a > > reason to believe that these W^X holes cannot be fixed, or that any fix > > would be more expensive than XPFO? > > Even if physmap is not executable, return-oriented programming (ROP) can > still be used to launch an attack. Instead of placing executable code at > user address 0xBEEF000, attacker can place an ROP payload there. kfptr > is then overwritten to point to a stack-pivoting gadget. Using the > physmap address aliasing, the ROP payload becomes kernel-mode stack. The > execution can then be hijacked upon execution of ret instruction. This > is a gist of the subsection titled "Non-executable physmap" under > section 6.2 and it looked convincing enough to me. If you have a > different take on this, I am very interested in your point of view. My issue with all this is that XPFO is really very expensive. I think that, if we're going to seriously consider upstreaming expensive exploit mitigations like this, we should consider others first, in particular CFI techniques. grsecurity's RAP would be a great start. I also proposed using a gcc plugin (or upstream gcc feature) to add some instrumentation to any code that pops RSP to verify that the resulting (unsigned) change in RSP is between 0 and THREAD_SIZE bytes. This will make ROP quite a bit harder.