Received: by 10.223.164.202 with SMTP id h10csp15260wrb; Mon, 6 Nov 2017 01:36:38 -0800 (PST) X-Google-Smtp-Source: ABhQp+SxZsHXUw7NNbi7Oi8494lRnMxwdBZdCe55wpjzYXdGhb/2wsBapSerZg8Rqg4Zr1mbMx/q X-Received: by 10.98.35.194 with SMTP id q63mr16037267pfj.15.1509960998713; Mon, 06 Nov 2017 01:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509960998; cv=none; d=google.com; s=arc-20160816; b=eTwr2Q/z6sceeYdmuveLrfGPpj/Z9WprcbSJwBk8rxwcV1N5hvHNyR2CHp+1D5zgLR 1whyFUMpkiBYqALxasrl4NSYgMq6tBEKrD95D7mPjSjiisfq+4titItnQP6KAJnCxP/d 6x0WQ2sCmVdQfb2uQKXruF5X2xukCcpVzjEDnwD0C7ZnC3FazjKHzDLevOmUKBhslIPy 34DjA2qmRR5ABZDNERAm6q7Viur5EaEUItuRK7I06G2B2wneLNdWpECtVPrOX1OkzZ0v eSPXLEgktJ7aCuHRruBq0kRYVkmG4YIaOFdNs+bqo4aH6s2Hwt7I63AodZIwnd1pV71V LMPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Jn/e9zJnvbxZAVDuJbkX1Zal8jeIcLE7qvQ3Prs5zNs=; b=DX6VpTyWzptbvr5ptR4vlNe6m+dwT/kmzNVqwAcELrVgiux/dsW3CqlNEH5zNU9D5z H1qEs/KoM2mtdj2a6LJ6vm/SAHz7bMR10oGUVDw+qfDdmiQBKySzyN91tWxxaJdCzZR+ k04tl5qnvhUFoar2Je38PFdfqAh9WdZgurGsTXDIjMqtvaIHnDXLEse7Bzlc2j3J8W9/ hV/navcx7y2bd8xXmOj4dH9+BzJ3b3EjAmRyL0hTYdjSGXeCYglLWSmmEmA7tEvwUBtz ySjfQO91y4l7J+nHvG8soPFhTaiDToTAMz58+TFMNTOkQhx3o8L4CDZsZ6keJwNlW3Yv NYLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BDj6y+0R; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w20si10690058plp.471.2017.11.06.01.36.25; Mon, 06 Nov 2017 01:36:38 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b=BDj6y+0R; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752442AbdKFJeq (ORCPT + 98 others); Mon, 6 Nov 2017 04:34:46 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:46140 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752275AbdKFI7K (ORCPT ); Mon, 6 Nov 2017 03:59:10 -0500 Received: by mail-qk0-f193.google.com with SMTP id o6so3053654qkh.3; Mon, 06 Nov 2017 00:59:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jn/e9zJnvbxZAVDuJbkX1Zal8jeIcLE7qvQ3Prs5zNs=; b=BDj6y+0Ryf6j9hPA2n7Pox3cQkthlge4IlGlA/alscSclKw6prh9Tf/uD47wAIA/tj zGjrOA1/mYVYxZtgDeU4W7tKqH8zWOKA4SHbxq2fYBdh7oD5YXyzSmM1RvogSWnULtPR BTEBphy3I/p29usgs+WhVwTeu44KAylwpWED8xvCygHRrz8uRPs40DmeXfWndGiTLfxx k+fmQG3jfzCCBM009TyTkqHCKYp6pUUkC/qxQVNNII1UO8z2phqcBPQuy3Ixo91hCcbT dY//f9F/HTFckVMHBEqpC68iuH4OuJBpP9VmXFtdXuWiTyu8ycsG/u9Uqx2uKhMsjolm OAoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Jn/e9zJnvbxZAVDuJbkX1Zal8jeIcLE7qvQ3Prs5zNs=; b=VLKXZfwF/NP3eduFXFNFrbf1q0r9EJK8CIW2bRhG80/1q2uOLaDcujbf2VnRDOCWZY NFokWJYZDW+5XimWnRLd3v6v2HhqnCrU2uuCCvfc3+/WnrMWQLXBDlb3EWMjxZt2LKKe JPKwymySehXlpj4qjJ6YoUZZVhSmDtDXKpUPa7N38tB7TnN/5PzG6yHkEFG8fD3Gsk+7 7y5RjZKA9D8gQwXcYg6XQlH8m3upRTM/Y4QyAkG/g3I5z1+wFclEbnQ5CSDxjTqubxTL Gds1MGmfrwmNPTieslGGfi5cSTtHW4j3mEaKIM2JQxtYnsntT04rtK2/pQbMzWsY3suV bLnA== X-Gm-Message-State: AJaThX7DTCWEYdZQ9RRJrCsn0xGHUI+Xz6iKYLf7rAdduL9rQePNmX17 8N2K996h/emMDuisHucjprw= X-Received: by 10.55.19.19 with SMTP id d19mr4610435qkh.189.1509958749147; Mon, 06 Nov 2017 00:59:09 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.59.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:08 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Cc: linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, benh@kernel.crashing.org, paulus@samba.org, khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com, hbabu@us.ibm.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, ebiederm@xmission.com, linuxram@us.ibm.com Subject: [PATCH v9 18/51] powerpc: implementation for arch_vma_access_permitted() Date: Mon, 6 Nov 2017 00:57:10 -0800 Message-Id: <1509958663-18737-19-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch provides the implementation for arch_vma_access_permitted(). Returns true if the requested access is allowed by pkey associated with the vma. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/mmu_context.h | 5 +++- arch/powerpc/mm/pkeys.c | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index a557735..95a3288 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -136,6 +136,10 @@ static inline void arch_bprm_mm_init(struct mm_struct *mm, { } +#ifdef CONFIG_PPC_MEM_KEYS +bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, + bool execute, bool foreign); +#else /* CONFIG_PPC_MEM_KEYS */ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, bool execute, bool foreign) { @@ -143,7 +147,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, return true; } -#ifndef CONFIG_PPC_MEM_KEYS #define pkey_initialize() #define pkey_mm_init(mm) #define thread_pkey_regs_save(thread) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index 13902be..3b221bd 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -375,3 +375,37 @@ bool arch_pte_access_permitted(u64 pte, bool write, bool execute) return pkey_access_permitted(pte_to_pkey_bits(pte), write, execute); } + +/* + * We only want to enforce protection keys on the current thread because we + * effectively have no access to AMR/IAMR for other threads or any way to tell + * which AMR/IAMR in a threaded process we could use. + * + * So do not enforce things if the VMA is not from the current mm, or if we are + * in a kernel thread. + */ +static inline bool vma_is_foreign(struct vm_area_struct *vma) +{ + if (!current->mm) + return true; + + /* if it is not our ->mm, it has to be foreign */ + if (current->mm != vma->vm_mm) + return true; + + return false; +} + +bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, + bool execute, bool foreign) +{ + if (static_branch_likely(&pkey_disabled)) + return true; + /* + * Do not enforce our key-permissions on a foreign vma. + */ + if (foreign || vma_is_foreign(vma)) + return true; + + return pkey_access_permitted(vma_pkey(vma), write, execute); +} -- 1.7.1 From 1586055917895043477@xxx Wed Dec 06 17:19:53 +0000 2017 X-GM-THRID: 1586031988596160854 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread