From patchwork Mon May 21 06:41:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10414027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A817A600CC for ; Mon, 21 May 2018 06:43:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97C0227FA9 for ; Mon, 21 May 2018 06:43:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C23A283DA; Mon, 21 May 2018 06:43:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D96F327FA9 for ; Mon, 21 May 2018 06:43:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE3A46B0269; Mon, 21 May 2018 02:43:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B92006B026A; Mon, 21 May 2018 02:43:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA8686B026B; Mon, 21 May 2018 02:43:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f71.google.com (mail-pg0-f71.google.com [74.125.83.71]) by kanga.kvack.org (Postfix) with ESMTP id 6CA7D6B0269 for ; Mon, 21 May 2018 02:43:16 -0400 (EDT) Received: by mail-pg0-f71.google.com with SMTP id q22-v6so3214779pgv.22 for ; Sun, 20 May 2018 23:43:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:to:cc:from:date :message-id:mime-version:content-transfer-encoding; bh=tFZPZ++V94MWSsRERTqQi2xmMyvbrrbzZfhqj0SvgYs=; b=A7Q9lLM5CvWBOL4lcvEicWT8WU0LxzgyAskewa1Z3Ek85RDPKs1Lmt2XkVt2ciWcyw 5F1QF7fHbkZ13j/N+KKBattar71tib0Z2TP82EjIXDhb5cVqfMfRmpYg5ZVezojVSjsZ g+8OeBjx2CHFiXdgbIsPccjTm0OHecBQhqj3pe4EMnV4F07aSvZWNyx8c60KXq29fybR Ad1pR5TvREbWJZrMaDSi1ORqixfWSt1S25Jhd9NO4a2HOxRl2rHyrMBizkacxIUPj8gB 9WvzArFXZIkER6LWU5Nzfqh3HNNb8R/I7hmIkycq29XbT4ucZHVjIDCjX4FbJBudDNvL 3a4w== X-Gm-Message-State: ALKqPwf7SP86i5YovviBlppscIMqT9MOWuICHw/b0oZE087HPysJ/Dtq Yz7vp5hMx4jg+36eZTB6RgPFAllCB6ZF+smC5vgGNzfgqLc1ThKdwIrBktwujhFeSa3fxvD1k6O VUZlYAaBB3G6hwo5aqt76w85VIYoZTbGz+R1UXMVe7DOKgshVuzwG0MxwZ+pFHjQ= X-Received: by 2002:a65:4502:: with SMTP id n2-v6mr14403081pgq.95.1526884996101; Sun, 20 May 2018 23:43:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrXK16JwamJqLEUr/wQt/LysvunZhiqJ4cOml8I6j/LOdIrIQNK4IbkfEbTWwoOyMiqrn5c X-Received: by 2002:a65:4502:: with SMTP id n2-v6mr14403060pgq.95.1526884995378; Sun, 20 May 2018 23:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526884995; cv=none; d=google.com; s=arc-20160816; b=f6pNEJUrqOMkEjA0OcVAzkh7+pb4qJoLH2kue42EUMg/g8Dx/bRTENlwJazNHQIpdK f7AgpDXAH+g8REWFEVet6qxZNAO4pxyymdfzDts2Q4YzchkgR1P+1ZPJXoib11TRjEkQ txbfC5K3I0CTBeCUnYyxpGAuOIbiMax8OQKNh88DAX3ru1LEgmDFdF5NWdxQr/eIZ9ZA Oy140xm28eZ/yj/U8/RaGTPw4sPFspe+dD/D7meVGwjpuLgA0Aj9gZhDUu0zgM0AiZw2 UfdZ7vKdW8gc4c0GNj1mY5gvIxCc8iLKSBAOFVEUD1r9aGILNiSyfC8GdB9Rg1oEldee Y8/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:from:cc:to :subject:dkim-signature:arc-authentication-results; bh=tFZPZ++V94MWSsRERTqQi2xmMyvbrrbzZfhqj0SvgYs=; b=KGFwvu2+UGispmhD7fIEl3L4dm9eqpTVbyw06ZLga+0Rw26P5MHP5tcbvA65VBLCZg 4lnbVRBNme7FevjIupZid1l7JuGT5Lq8xba1CsAYioWALvsT6X9gHkvev9AzdNRJdf/z 4mltPaVDqwXn1IbXt3Jn7g8zkP70gE2sdSGI/2mFD3lWRF3CQCEgPthGzL41PUWbR0rs DwYacg3n+4hrHHDuPIU4r7aja0ulQsuGgMiKxvC1fpLES0h+Zk3VJtbeEPZOK9lMCr3/ s3aNY3NmZ4TDsbcWP6WLTGf6DSj+ToQZgaSs+uOPqIkgxCdIvEqZ54/dY5c9oTzIhOzZ sDDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qSmsWwGL; spf=pass (google.com: domain of srs0=nia/=ii=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=SRS0=nia/=II=linuxfoundation.org=gregkh@kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id v12-v6si13683885plz.33.2018.05.20.23.43.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 23:43:15 -0700 (PDT) Received-SPF: pass (google.com: domain of srs0=nia/=ii=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qSmsWwGL; spf=pass (google.com: domain of srs0=nia/=ii=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=SRS0=nia/=II=linuxfoundation.org=gregkh@kernel.org Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C101120871; Mon, 21 May 2018 06:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526884995; bh=sv4hDwWGRF0wA1qkVZXSafqtwbyA6qj1L2+sf1N7pZw=; h=Subject:To:Cc:From:Date:From; b=qSmsWwGL1kanoYkWNNDgtcRv2mnDLNbwXpT91e06iCrbQgBrsWlwG4Q8wSu0sz6AU 0YyDQXBei2jbz17YPhJSP7tASNu8TsqSFnr091CrJ1v3eCU4jRvJMW+MtIlclHSsGD BhFrLskFk4KgmIWyTJxldNh7RHyC1zEWwsyR0sc4= Subject: Patch "x86/pkeys: Do not special case protection key 0" has been added to the 4.16-stable tree To: 1522112702-27853-1-git-send-email-linuxram@us.ibm.com, 20180509171358.47FD785E@viggo.jf.intel.com, akpm@linux-foundation.org, dave.hansen@intel.com, dave.hansen@linux.intel.com, gregkh@linuxfoundation.org, linux-mm@kvack.org, linuxram@us.ibm.com, mingo@kernel.org, mpe@ellerman.id.au, peterz@infradead.org, shuah@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org Cc: From: Date: Mon, 21 May 2018 08:41:52 +0200 Message-ID: <152688491212019@kroah.com> MIME-Version: 1.0 X-stable: commit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This is a note to let you know that I've just added the patch titled x86/pkeys: Do not special case protection key 0 to the 4.16-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: x86-pkeys-do-not-special-case-protection-key-0.patch and it can be found in the queue-4.16 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. From 2fa9d1cfaf0e02f8abef0757002bff12dfcfa4e6 Mon Sep 17 00:00:00 2001 From: Dave Hansen Date: Wed, 9 May 2018 10:13:58 -0700 Subject: x86/pkeys: Do not special case protection key 0 From: Dave Hansen commit 2fa9d1cfaf0e02f8abef0757002bff12dfcfa4e6 upstream. mm_pkey_is_allocated() treats pkey 0 as unallocated. That is inconsistent with the manpages, and also inconsistent with mm->context.pkey_allocation_map. Stop special casing it and only disallow values that are actually bad (< 0). The end-user visible effect of this is that you can now use mprotect_pkey() to set pkey=0. This is a bit nicer than what Ram proposed[1] because it is simpler and removes special-casing for pkey 0. On the other hand, it does allow applications to pkey_free() pkey-0, but that's just a silly thing to do, so we are not going to protect against it. The scenario that could happen is similar to what happens if you free any other pkey that is in use: it might get reallocated later and used to protect some other data. The most likely scenario is that pkey-0 comes back from pkey_alloc(), an access-disable or write-disable bit is set in PKRU for it, and the next stack access will SIGSEGV. It's not horribly different from if you mprotect()'d your stack or heap to be unreadable or unwritable, which is generally very foolish, but also not explicitly prevented by the kernel. 1. http://lkml.kernel.org/r/1522112702-27853-1-git-send-email-linuxram@us.ibm.com Signed-off-by: Dave Hansen Cc: Andrew Morton p Cc: Dave Hansen Cc: Linus Torvalds Cc: Michael Ellermen Cc: Peter Zijlstra Cc: Ram Pai Cc: Shuah Khan Cc: Thomas Gleixner Cc: linux-mm@kvack.org Cc: stable@vger.kernel.org Fixes: 58ab9a088dda ("x86/pkeys: Check against max pkey to avoid overflows") Link: http://lkml.kernel.org/r/20180509171358.47FD785E@viggo.jf.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/mmu_context.h | 2 +- arch/x86/include/asm/pkeys.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) Patches currently in stable-queue which might be from dave.hansen@linux.intel.com are queue-4.16/x86-pkeys-override-pkey-when-moving-away-from-prot_exec.patch queue-4.16/x86-pkeys-do-not-special-case-protection-key-0.patch --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -192,7 +192,7 @@ static inline int init_new_context(struc #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS if (cpu_feature_enabled(X86_FEATURE_OSPKE)) { - /* pkey 0 is the default and always allocated */ + /* pkey 0 is the default and allocated implicitly */ mm->context.pkey_allocation_map = 0x1; /* -1 means unallocated or invalid */ mm->context.execute_only_pkey = -1; --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h @@ -51,10 +51,10 @@ bool mm_pkey_is_allocated(struct mm_stru { /* * "Allocated" pkeys are those that have been returned - * from pkey_alloc(). pkey 0 is special, and never - * returned from pkey_alloc(). + * from pkey_alloc() or pkey 0 which is allocated + * implicitly when the mm is created. */ - if (pkey <= 0) + if (pkey < 0) return false; if (pkey >= arch_max_pkey()) return false;