From patchwork Mon May 21 06:41:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10414023 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 6067E60365 for ; Mon, 21 May 2018 06:42:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50B0528782 for ; Mon, 21 May 2018 06:42:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4533428795; Mon, 21 May 2018 06:42:35 +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 90B1C28782 for ; Mon, 21 May 2018 06:42:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21FF16B000D; Mon, 21 May 2018 02:42:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1F8036B000E; Mon, 21 May 2018 02:42:33 -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 099E46B0010; Mon, 21 May 2018 02:42:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id BAE886B000D for ; Mon, 21 May 2018 02:42:32 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id d9-v6so9566156plj.4 for ; Sun, 20 May 2018 23:42:32 -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=PeLwYoSsSkkC5zG9VWV+Mdot1W8GGjr2Se6MMmH48SY=; b=LUK3XUeM4cO3httpgJ8lmTZUesriTHXtMFor1rjfNVsfLJIoou44bkgX633o9UpV+d KIgHWpjdr3cbnFkIqNFvUGSp8NxekigzaY8h/PgWfYiXoB5IBVGNU/U12E51+cIf80oZ bFDrE8FXMa81PDQBDXXRzJ89VgneLMNbNQ+rWkuCRru+Vu8r0HDoWgDsgEsSBvWZ/qcq 4c6IYBRpLUpDu2AwhAkchbarDeTwXKUBqq8By8pMzqsHkonXSEfkhe4RfCYnrGbyeEgJ BVSNEE+TTaAHbSGslKpYzTQ8EWvK+qo49rD32EnPIwg868OLD4oYN9XALi/AbBJiK3YB SHrA== X-Gm-Message-State: ALKqPwfOb0cv/tpICBIQ1JlEd/jN9pg2zyIh9KMr4nmXbhZ+opfixt9b dt2zrxiInCZSEiM2yIo6J4QdTg21qfPf8u2stZWaPOn3vTIJV1trn/KuRSdjIXH9DRvx4YxAYMQ LMDArquHf7W76+Q1rTz3go4RIiQrQEtZRIYbe/ipT3H9cmLc3m/of6M3RB2nbJII= X-Received: by 2002:a63:91c4:: with SMTP id l187-v6mr14723605pge.261.1526884952411; Sun, 20 May 2018 23:42:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqy24QGDO+eo8VX1paLYb3+ndX0ZcF9YMmfo8CY2NRtI9z0UVphwrUr58690LNAvxVo6rzc X-Received: by 2002:a63:91c4:: with SMTP id l187-v6mr14723576pge.261.1526884951576; Sun, 20 May 2018 23:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526884951; cv=none; d=google.com; s=arc-20160816; b=rpqHQcd/uZJ+M+5PVzKWgos8JFwhLpLO6+qo6L2Hz6fUSuPIPhF0U+PB2/7ry4nMAU mbBn8Vf4sU4pggF/OyyagA74/6/poYlqRtvbx8+zuNXT5lsias8mjN5xgOpVL80E7yJ5 RxJUxqCWXnUktKWcVJiDTKJmDT7ZmG+lcdzXeCCeJOt4zGxPPw+O1qwzxvrjozQf1ukd D7+lUOPc9LCdZONnkIiXCWR29Sh1FkqvlXOJ4L8ntdz1GKsHPFkqxeCXGpvpazva/x6x ncwDNy4x8noOVmUfMNywldQ55WAYvXlNP12GXCI3EcZvEnprYO3ex6Jb1IWD6epq2U38 aEfA== 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=PeLwYoSsSkkC5zG9VWV+Mdot1W8GGjr2Se6MMmH48SY=; b=i2e2vbqQga8UzibkHhmNsdnv3zD3qE6UBmYab1jOoSHMMtpi/DR2I4moLyzs4MzTaH fva37ODbSLDEcQ+KTb+sHPvkM14tyY4vwII8v0VRUjh21fNV1tK+Yg4DVib+iHs6ZY8O pI+Nem6IaWyQWXuXXP419+zHWDFYR5sAlqIC2E9Q6Gm2A+hyqchUqzlRapwcOluyjqR5 kW+yX7xnHQmpfwZhIbhy0WchS9isrzMgC1st4zbVmV7Si05w8QkyPVMT81AEpBJz7pA8 4gvbDH765TndlCC7epeI6USzjeBe+7+HEewQZZm5RlONVaa+88fo+0PU/TGWpTEApePN s4Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SXc2nqO6; 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 n22-v6si13663348pfb.126.2018.05.20.23.42.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 23:42:31 -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=SXc2nqO6; 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 8C1FF2086A; Mon, 21 May 2018 06:42:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526884951; bh=vWEbUJfp+9nvIYL9Ff7Ywr0NJUQC5IoGH1x7iz/p2Rk=; h=Subject:To:Cc:From:Date:From; b=SXc2nqO6rUST1O7VjPMhbe0Fr4qZWHmzjL0/21b7Hn2Pfq3N1xkjwoR3IKcHijPQu gdlmwUrHFbVFdwbz/HJUg2RaQeI1AsjymXVwDDZu/K2Qs28pcTid2Dxygb9/QWh17c 2wF2UssR9r/O+aoeuepNEBT9eq9UdffZU9b5Riqk= Subject: Patch "x86/pkeys: Do not special case protection key 0" has been added to the 4.14-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:29 +0200 Message-ID: <1526884889215247@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.14-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.14 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.14/x86-pkeys-override-pkey-when-moving-away-from-prot_exec.patch queue-4.14/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;