Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp474429imm; Thu, 30 Aug 2018 03:43:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZah14lk8xjeOSXDh3QNnnu1o6cW+5x2iiaJBLVYnk52bsxSiAKFeyA05Z7AW3Vydnqh8py X-Received: by 2002:a63:144b:: with SMTP id 11-v6mr8959470pgu.219.1535625805643; Thu, 30 Aug 2018 03:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535625805; cv=none; d=google.com; s=arc-20160816; b=cx8v3nwLiPiUI6apLY/PfTVqaEJMW6WXF0R6wpfbyr8QgFt+mK4G2PWeyuirXVvYRY +VBSkYlO/DbCRelBL8OtOJn9qEOEOE4qjiCUoKj8NvIy5qBWbf6xnACfaQObvVJKzYMx H81fgVe7LJIjVz1YVFvzeV1dwnDi6liYIOJmUPAY1fnp8jIDpIhVfqaFfGye4cxJrU7T kyRp6Yf07tAorprpXeqJ/sF0myWTUgN26xs5J04XYSbrPIYYEKycAQsnThWmQd2wuy6L 9JQhsThivDl7p0DqLxtHyACQ1w/8tsWp65HaCBxesmbZPZeX3axJwwakgPm0KsbKY4YR i3JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=ocIMQC5uqfPYfaRG+NdiGEvT911HJ6L/uuSFk8alyTM=; b=sF2FoARTyZQthJIZgcE01aEZ+d9TTNKTwJiVHuXOeJSuqI0jXv0BOVOJzQOl6cNdn4 hUvx65ccXwBmr2p3lR8AfoCThmcYlXqeww934QwzbHSnT9CfyobimGCEj0VXR0vsf9qv sSv8V55C0QJUY+3gTYO5SkyQATJPTMtMDSeJPFPG2Az6Sg3JOGeiT6nTeNocClQW1622 3kXJzp/Xg493sddYZ/7EvjlFQCruUXIDE8956NNYz0/WGirM4B2I/vgIuH8l1Rl/Qig2 ATVOil48A9E82eSE/PeDlDW737WV+QJrBiGQnB+43SEEX5dJpekFxtmB9A26z+ySUwF2 Tqnw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21-v6si6439701pgk.418.2018.08.30.03.43.10; Thu, 30 Aug 2018 03:43:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728499AbeH3Om1 (ORCPT + 99 others); Thu, 30 Aug 2018 10:42:27 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:49865 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728311AbeH3Om1 (ORCPT ); Thu, 30 Aug 2018 10:42:27 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fvKNh-000137-H5; Thu, 30 Aug 2018 12:40:53 +0200 Date: Thu, 30 Aug 2018 12:40:53 +0200 (CEST) From: Thomas Gleixner To: Dave Hansen cc: Sean Christopherson , linux-kernel@vger.kernel.org, Ingo Molnar , "H. Peter Anvin" , x86@kernel.org Subject: Re: [PATCH] x86/pkeys: Explicitly treat PK #PF on kernel address as a bad area In-Reply-To: Message-ID: References: <20180807172920.8766-1-sean.j.christopherson@intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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: > > asm("movl $0xffffffff, %eax;\ > movl $0x00000000, %ecx;\ > movl $0x00000000, %edx;\ > wrpkru;\ > movq $0xffffffffff600000, %rax;\ > movq $0xffffffffff600002, %rbx;\ > jmpq *%rbx;"); > > So, my bad. It was not a good suggestion to do a WARN_ON(). But, the > other funny thing is I would have expected spurious_fault() to get us > into a fault loop, which it doesn't. It's definitely getting *called* > with my little test program (I see it in ftrace) but it's not quite > doing what I expect. > > I need to dig a bit more. Given the time span you should be close to ground water with your digging by now. Thanks, tglx