Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp171616imm; Thu, 30 Aug 2018 19:40:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbnqEdqPWr4BriPgYEGZL9IdTRjKR4qQqO+7y/nCwCRKavcTpqRH8VGTpm9Cv1DLY4GZiLZ X-Received: by 2002:a65:6654:: with SMTP id z20-v6mr7416822pgv.186.1535683240403; Thu, 30 Aug 2018 19:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535683240; cv=none; d=google.com; s=arc-20160816; b=nhc2ZI2uPFuReTe3vSn6Yo7vpxVvyDriHl1oCR8RY97fQXG7K64Vr2rZPZRqU3R/Af IAd91OwFc1GQ5isvUO1h+CYnCaWonmy0F9hVqVQ8TQcBEBIvA0R13BJ1jY9maoJ3BMx9 8PzyDSlW6abzonGa6ccSyJuOp4aCfb63oVEKAN8s0BTYe5YIYnCuzksOaH0EI02nqG8D wnkClbpHzLUQ1iysTmg06E/G/+Ylnxy7cqxqy5uOHVE3o5eZODev5ldOAHZ5BAz8RdiM 78POzoeX3hSvRDAqEdl4lf5wlr+tEYCVRP+DXB4PWKr7p5ftPZ3yA+N5kKOPOWDuv0lx OgAQ== 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 :arc-authentication-results; bh=cYDmEEYw+tWM+pjJaVrgu2mCCDmIgLjzvZQ8UQa04XU=; b=ulTpxaMPr0rPexk58Oq171laODHec54nkmTRmycQ++LHhJFteQc3Ab1Zt0XN9UP0Bd sznlZZBwJx93h9J3u3jbneoKkdUKJO9wYQBf9KBU5AacvHe/fFOC4l98JBwxqRSCOv9a +lMsTSTYJmzpExVEL/k5d9PIb62nkd62cCQavLKmya3vS/m86lOt2pPxZYTE6mt6U6UX 8RGrrWE4r34rHDSv3HWOO7UJIKUI3iSP8T6+zraO0SK2pXzoZNGmE5Q1mnKZXEUgO7dp W898OOjnTdoIIKvKQg/eNgXtfChPDSw3wOSDE9pkhfW71GKyb9Ki2SoCD6H2TN/Bsjq9 JjXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=U8vbCqx7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10-v6si8361563pfe.41.2018.08.30.19.40.25; Thu, 30 Aug 2018 19:40:40 -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=@google.com header.s=20161025 header.b=U8vbCqx7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727211AbeHaGoW (ORCPT + 99 others); Fri, 31 Aug 2018 02:44:22 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:36575 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbeHaGoW (ORCPT ); Fri, 31 Aug 2018 02:44:22 -0400 Received: by mail-oi0-f65.google.com with SMTP id r69-v6so19185120oie.3 for ; Thu, 30 Aug 2018 19:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cYDmEEYw+tWM+pjJaVrgu2mCCDmIgLjzvZQ8UQa04XU=; b=U8vbCqx7ldbSCyBG1SJ+kbmwxL8kV+J3ajiN7W5WW2cfmC0aoenlyg4XsZXDHeYB6k tUzEy6YEksH6lJuouziKvC+xeJ6ZrMvn0ObMYPlbKQ4+dOEFqJGstS+WBCPQOT6pcLaL LGIuCl97jmxJPW5qhZXnbHKOK9eN5FB6dk/0elVhcZheHuVwIiUimsWJPWd5AL/ZmnCG SdjlU/T3u6lxl/fAbiC+hBg3mtT/jRRFLFtqYzighyTsHKpoWrGkH5IJPAzbUf3/+Eyk OSMJM6D7bPl98Y3fwCU6+dV+sUxoS/3jSaBi+bnoqLg7pQqXaXVsGQgrXyA5aKbqyxoH cO2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cYDmEEYw+tWM+pjJaVrgu2mCCDmIgLjzvZQ8UQa04XU=; b=CvHOwDB+u6fD4vlFZZU32eJCbpQ+uKMPGFoSEqICCe+HYwrNThCAjSMxPD2wKW957W yA+wfn5gTNaEygnOxmiOY/bdKLlT6OEQXWFPLpNslqDegD03XJgclxCyzindobOmIUfe UUkUvqaU4WHFp9P9ysqzEvCUATvF/4ZI8esVhU3igNxi9azqT2RFjdvSHinBBjZGZ0qS sSCAQjLMfdjlRk+3N2vcgupgfNj1VwLlORAcg/Z1CGA3FEdXs5xpc4yYJ94iNy19ZAF4 1gFnsiqgQkjM5wFEbPKGxD/7v12tueSGNEk6xYN9k2MJ7rbo+dZs73n86wrp33oUby7w 4G2w== X-Gm-Message-State: APzg51ArOxmgFMuYwjkWGdAggAp+Pmr7TuuvMatKqpDOBSqyuvmyPw6d 6/YvU7GRnch1zZw+ISXvmLE9/kjJGm4QCCgrK9goUA== X-Received: by 2002:aca:4784:: with SMTP id u126-v6mr5394889oia.229.1535683151872; Thu, 30 Aug 2018 19:39:11 -0700 (PDT) MIME-Version: 1.0 References: <20180807172920.8766-1-sean.j.christopherson@intel.com> In-Reply-To: From: Jann Horn Date: Fri, 31 Aug 2018 04:38:44 +0200 Message-ID: Subject: Re: [PATCH] x86/pkeys: Explicitly treat PK #PF on kernel address as a bad area To: Dave Hansen , Andy Lutomirski Cc: sean.j.christopherson@intel.com, kernel list , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , "the arch/x86 maintainers" 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 Tue, 7 Aug 2018 Dave Hansen wrote: > > On 08/07/2018 10:29 AM, Sean Christopherson wrote: > > if (unlikely(fault_in_kernel_space(address))) { > > + /* > > + * We should never encounter a protection keys fault on a > > + * kernel address as kernel address are always mapped with > > + * _PAGE_USER=0, i.e. PKRU isn't enforced. > > + */ > > + if (WARN_ON_ONCE(error_code & X86_PF_PK)) > > + goto bad_kernel_address; > > I just realized one more thing: the vsyscall page can bite us here. > It's at a fault_in_kernel_space() address and we *can* trigger a pkey > fault on it if we jump to an instruction that reads from a > pkey-protected area. > > We can make a gadget out of unaligned vsyscall instructions that does > that. See: > > 0xffffffffff600002: shlb $0x0,0x0(%rax) > > Then, we turn off access to all pkeys, including pkey-0, then jump to > the unaligned vsyscall instruction, which reads %rax, which is a kernel > address: Andy got rid of the (native) vsyscall page in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=076ca272a14cea558b1092ec85cea08510283f2a ('x86/vsyscall/64: Drop "native" vsyscalls') a few months ago, right? At this point, the vsyscall page should never be executable.