From patchwork Fri Sep 8 22:45:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 811885 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xpv0N4884z9sBW for ; Sat, 9 Sep 2017 09:38:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TjM/JcsC"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xpv0N2ttGzDrX0 for ; Sat, 9 Sep 2017 09:38:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TjM/JcsC"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::243; helo=mail-qt0-x243.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TjM/JcsC"; dkim-atps=neutral Received: from mail-qt0-x243.google.com (mail-qt0-x243.google.com [IPv6:2607:f8b0:400d:c0d::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3xpss06q44zDrd1 for ; Sat, 9 Sep 2017 08:47:16 +1000 (AEST) Received: by mail-qt0-x243.google.com with SMTP id q8so2360383qtb.1 for ; Fri, 08 Sep 2017 15:47:16 -0700 (PDT) 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=szSA3vc/2aGhree59A931PQDmK2SvKPQh8WK1LUr7uA=; b=TjM/JcsCvEvZ7YQdJDXzImHpfwa+TUHuHWY46v/EjEp6Noq96RYbnK8yEOB67NfK8k TA3tQ978CtjGPaAIpg8lwZU0D3SItvNJV+RZLtDSDpssI3blJepVq8IM7xCl6mVMN7UV ItcxfziyzNcClnSAP9TRTowu2kQqPBz5lj2h/WYE86ubYFdeJZF6Z+wv0jIVFm/bJYbQ Syuezq8lNne2l9wXbwoFx+9BNx9c2NAgztM+a2i/otrAvLffjG5WSmTTYri7nj8zR5Nq m/6/PhQ8Y4cZrImq13tGBi3ttZBxuSYIc3e/qnRdMOoaIMI7iVt4vx9VsWjXmJ7fNXcW Gffw== 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=szSA3vc/2aGhree59A931PQDmK2SvKPQh8WK1LUr7uA=; b=H2/5Ix0pKa8q9prq2gMq1zpi+cgtV82nZnhAHi/allrJy2VOQeiHxAXapkBcd4vs7C Ngs0C1yZRvCAeOJVo7fGbh6jlHOKgDQ14jCGn6wBWrOuQ+Si933q7p+UtnbnaP/Qxt1x YGWBcjiap4amRa1yFikNbI+in2PD8zB1oT76AIg/E2JYkb3cqF9JI23Ol70ziZuM5UWB l1LKhdvRhM0MuxDq/jEvvOpeCKzRughD5QLBnY7Owq+VQ0qKichBxBzAc1RKrd4QFsD8 itVeqwgivuge74h04tEkCvdJr1GucI2A48G6D5SPNi2HXTRaG47VHamuEg3UD3f6ZHm/ 1Gfw== X-Gm-Message-State: AHPjjUhtKXmgIeyXRydvvm5e2V9xsLE5npvjip5Sks6g/DPk5q9UTuL/ /mKmmsRZrG+IiA== X-Google-Smtp-Source: AOwi7QBnOjgaTMGiS88wkWHvyykFQdqoRNrRXxwKD1hzTuqOvQLGbTpNwazlIc3GETY94dOXf7cpaQ== X-Received: by 10.200.26.176 with SMTP id x45mr6940365qtj.181.1504910835086; Fri, 08 Sep 2017 15:47:15 -0700 (PDT) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id x124sm2033726qka.85.2017.09.08.15.47.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 15:47:14 -0700 (PDT) From: Ram Pai To: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 19/25] powerpc: implementation for arch_vma_access_permitted() Date: Fri, 8 Sep 2017 15:45:07 -0700 Message-Id: <1504910713-7094-28-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1504910713-7094-1-git-send-email-linuxram@us.ibm.com> References: <1504910713-7094-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ebiederm@xmission.com, linuxram@us.ibm.com, mhocko@kernel.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletions(-) diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h index 04e9221..9a56355 100644 --- a/arch/powerpc/include/asm/mmu_context.h +++ b/arch/powerpc/include/asm/mmu_context.h @@ -135,6 +135,10 @@ static inline void arch_bprm_mm_init(struct mm_struct *mm, { } +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS +bool arch_vma_access_permitted(struct vm_area_struct *vma, + bool write, bool execute, bool foreign); +#else /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write, bool execute, bool foreign) { @@ -142,7 +146,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, return true; } -#ifndef CONFIG_PPC64_MEMORY_PROTECTION_KEYS #define pkey_initialize() #define pkey_mm_init(mm) diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c index 24589d9..21c3b42 100644 --- a/arch/powerpc/mm/pkeys.c +++ b/arch/powerpc/mm/pkeys.c @@ -320,3 +320,46 @@ 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 process + * because we effectively have no access to AMR/IAMR for other + * processes 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 the VMA is from another process, then AMR/IAMR has no + * relevance and should not be enforced. + */ + 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) +{ + int pkey; + + if (!pkey_inited) + return true; + + /* allow access if the VMA is not one from this process */ + if (foreign || vma_is_foreign(vma)) + return true; + + pkey = vma_pkey(vma); + + if (!pkey) + return true; + + return pkey_access_permitted(pkey, write, execute); +}