[{"id":1789100,"web_url":"http://patchwork.ozlabs.org/comment/1789100/","msgid":"<20171018144256.72bdd785@firefly.ozlabs.ibm.com>","date":"2017-10-18T03:42:56","subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","submitter":{"id":9347,"url":"http://patchwork.ozlabs.org/api/people/9347/","name":"Balbir Singh","email":"bsingharora@gmail.com"},"content":"On Fri,  8 Sep 2017 15:44:57 -0700\nRam Pai <linuxram@us.ibm.com> wrote:\n\n> powerpc has hardware support to disable execute on a pkey.\n> This patch enables the ability to create execute-disabled\n> keys.\n> \n> Signed-off-by: Ram Pai <linuxram@us.ibm.com>\n> ---\n>  arch/powerpc/include/uapi/asm/mman.h |    6 ++++++\n>  arch/powerpc/mm/pkeys.c              |   16 ++++++++++++++++\n>  2 files changed, 22 insertions(+), 0 deletions(-)\n> \n> diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h\n> index ab45cc2..f272b09 100644\n> --- a/arch/powerpc/include/uapi/asm/mman.h\n> +++ b/arch/powerpc/include/uapi/asm/mman.h\n> @@ -45,4 +45,10 @@\n>  #define MAP_HUGE_1GB\t(30 << MAP_HUGE_SHIFT)\t/* 1GB   HugeTLB Page */\n>  #define MAP_HUGE_16GB\t(34 << MAP_HUGE_SHIFT)\t/* 16GB  HugeTLB Page */\n>  \n> +/* override any generic PKEY Permission defines */\n> +#define PKEY_DISABLE_EXECUTE   0x4\n> +#undef PKEY_ACCESS_MASK\n> +#define PKEY_ACCESS_MASK       (PKEY_DISABLE_ACCESS |\\\n> +\t\t\t\tPKEY_DISABLE_WRITE  |\\\n> +\t\t\t\tPKEY_DISABLE_EXECUTE)\n>  #endif /* _UAPI_ASM_POWERPC_MMAN_H */\n> diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c\n> index cc5be6a..2282864 100644\n> --- a/arch/powerpc/mm/pkeys.c\n> +++ b/arch/powerpc/mm/pkeys.c\n> @@ -24,6 +24,14 @@ void __init pkey_initialize(void)\n>  {\n>  \tint os_reserved, i;\n>  \n> +\t/*\n> +\t * we define PKEY_DISABLE_EXECUTE in addition to the arch-neutral\n> +\t * generic defines for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE.\n> +\t * Ensure that the bits a distinct.\n> +\t */\n> +\tBUILD_BUG_ON(PKEY_DISABLE_EXECUTE &\n> +\t\t     (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));\n\nWill these values every change? It's good to have I guess.\n\n> +\n>  \t/* disable the pkey system till everything\n>  \t * is in place. A patch further down the\n>  \t * line will enable it.\n> @@ -120,10 +128,18 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,\n>  \t\tunsigned long init_val)\n>  {\n>  \tu64 new_amr_bits = 0x0ul;\n> +\tu64 new_iamr_bits = 0x0ul;\n>  \n>  \tif (!is_pkey_enabled(pkey))\n>  \t\treturn -EINVAL;\n>  \n> +\tif ((init_val & PKEY_DISABLE_EXECUTE)) {\n> +\t\tif (!pkey_execute_disable_support)\n> +\t\t\treturn -EINVAL;\n> +\t\tnew_iamr_bits |= IAMR_EX_BIT;\n> +\t}\n> +\tinit_iamr(pkey, new_iamr_bits);\n> +\n\nWhere do we check the reserved keys?\n\nBalbir Singh.","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yGyck59Skz9t2h\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 18 Oct 2017 14:45:10 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yGyck42MGzDrTj\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 18 Oct 2017 14:45:10 +1100 (AEDT)","from mail-pg0-x242.google.com (mail-pg0-x242.google.com\n\t[IPv6:2607:f8b0:400e:c05::242])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yGyZN6cWNzDrTd\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tWed, 18 Oct 2017 14:43:08 +1100 (AEDT)","by mail-pg0-x242.google.com with SMTP id a192so3138568pge.9\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tTue, 17 Oct 2017 20:43:08 -0700 (PDT)","from firefly.ozlabs.ibm.com ([122.99.82.10])\n\tby smtp.gmail.com with ESMTPSA id\n\tz89sm21832612pff.21.2017.10.17.20.43.02\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 17 Oct 2017 20:43:06 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"qTFQ1o+o\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"qTFQ1o+o\"; dkim-atps=neutral","ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gmail.com\n\t(client-ip=2607:f8b0:400e:c05::242; helo=mail-pg0-x242.google.com;\n\tenvelope-from=bsingharora@gmail.com; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"qTFQ1o+o\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=date:from:to:cc:subject:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=j7iqgr7mpge9pYYl6P357yuiN6gIplXk8vYDV3rGSjY=;\n\tb=qTFQ1o+od698YW3fWD3KenhTPeSvli2ij+yDOeYpIJvhWw71K8O3kic0gFbH/SgcA7\n\tgoo4ggca1rcpoDOF8UiVR+OU5NgtpGuAT50ISwuxxOTH+NCjsvXHgqJ1NzeZnAvMMGMs\n\tL0bUwFhKhBaglCHJZO/3f40t06lLGQ4xVmjiKHQM4lD9hdUG9WwIV3L7ghk6J/xOv3O1\n\tX16xaITAHNqs1yWxvWsx43daltAOT2+LpDfjAtrGkLYd1xqNl2QabIug3QoLR5gO+PhL\n\tAGCg9JBwU1czb4Oz6FyoHH9BOt2V9yInamrz0kqJ44z4XxuqG+cHa7FwonlrOWh5t5km\n\taSJA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=j7iqgr7mpge9pYYl6P357yuiN6gIplXk8vYDV3rGSjY=;\n\tb=fDaAbna/xBziL2FFSKMqrdDrLt/VioErsitDtyaZQ3+V8U0LsyQlIl5mh46KzVFP60\n\tl2AQU4xaETWN581s6mXEyJVCdo/VTUiyW5ytM7M+PU1qUW2d/YzUrGQWQCP/NGxcd2+s\n\tZfciu4JUyyJ+QVxu3adIh8+b7qsJvi37AZepUZkBRN4CAHtTewA+ixNXYcE/5yIPRtR9\n\tF4++73KF7bXV2CBZlhcNuIp0f7C19rnjlMEotA2BpF2ab8pS2TSUYDUAvakJZjvp3kP4\n\tto1CzBjLMv8wEHCE7nOGiNVWRo1hrbnUByU+szbqPRZo7eW9PgYkuY+wtIXSVRg/SVVV\n\tnz2g==","X-Gm-Message-State":"AMCzsaVJ90mBR2srCCKGj1jjUr0CkvkkFT+7Z3Dbr7P0EqptlRTSHH1v\n\tstnEnGeQCdlu8yrtMPrEmgYRSAMw","X-Google-Smtp-Source":"AOwi7QB6hwnppvrMsYvviM8s63gQB/qLAATWZFN/NHc3bJcdrw6R/gu1Of1WwN+lXRPNVx3SoCcNSg==","X-Received":"by 10.98.15.197 with SMTP id 66mr13341931pfp.272.1508298186324; \n\tTue, 17 Oct 2017 20:43:06 -0700 (PDT)","Date":"Wed, 18 Oct 2017 14:42:56 +1100","From":"Balbir Singh <bsingharora@gmail.com>","To":"Ram Pai <linuxram@us.ibm.com>","Subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","Message-ID":"<20171018144256.72bdd785@firefly.ozlabs.ibm.com>","In-Reply-To":"<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>","X-Mailer":"Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-redhat-linux-gnu)","MIME-Version":"1.0","Content-Type":"text/plain; charset=US-ASCII","Content-Transfer-Encoding":"7bit","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"ebiederm@xmission.com, mhocko@kernel.org, paulus@samba.org,\n\taneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com,\n\tlinuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}},{"id":1789137,"web_url":"http://patchwork.ozlabs.org/comment/1789137/","msgid":"<20171018051547.GD5617@ram.oc3035372033.ibm.com>","date":"2017-10-18T05:15:47","subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","submitter":{"id":2667,"url":"http://patchwork.ozlabs.org/api/people/2667/","name":"Ram Pai","email":"linuxram@us.ibm.com"},"content":"On Wed, Oct 18, 2017 at 02:42:56PM +1100, Balbir Singh wrote:\n> On Fri,  8 Sep 2017 15:44:57 -0700\n> Ram Pai <linuxram@us.ibm.com> wrote:\n> \n> > powerpc has hardware support to disable execute on a pkey.\n> > This patch enables the ability to create execute-disabled\n> > keys.\n> > \n> > Signed-off-by: Ram Pai <linuxram@us.ibm.com>\n> > ---\n> >  arch/powerpc/include/uapi/asm/mman.h |    6 ++++++\n> >  arch/powerpc/mm/pkeys.c              |   16 ++++++++++++++++\n> >  2 files changed, 22 insertions(+), 0 deletions(-)\n> > \n> > diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h\n> > index ab45cc2..f272b09 100644\n> > --- a/arch/powerpc/include/uapi/asm/mman.h\n> > +++ b/arch/powerpc/include/uapi/asm/mman.h\n> > @@ -45,4 +45,10 @@\n> >  #define MAP_HUGE_1GB\t(30 << MAP_HUGE_SHIFT)\t/* 1GB   HugeTLB Page */\n> >  #define MAP_HUGE_16GB\t(34 << MAP_HUGE_SHIFT)\t/* 16GB  HugeTLB Page */\n> >  \n> > +/* override any generic PKEY Permission defines */\n> > +#define PKEY_DISABLE_EXECUTE   0x4\n> > +#undef PKEY_ACCESS_MASK\n> > +#define PKEY_ACCESS_MASK       (PKEY_DISABLE_ACCESS |\\\n> > +\t\t\t\tPKEY_DISABLE_WRITE  |\\\n> > +\t\t\t\tPKEY_DISABLE_EXECUTE)\n> >  #endif /* _UAPI_ASM_POWERPC_MMAN_H */\n> > diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c\n> > index cc5be6a..2282864 100644\n> > --- a/arch/powerpc/mm/pkeys.c\n> > +++ b/arch/powerpc/mm/pkeys.c\n> > @@ -24,6 +24,14 @@ void __init pkey_initialize(void)\n> >  {\n> >  \tint os_reserved, i;\n> >  \n> > +\t/*\n> > +\t * we define PKEY_DISABLE_EXECUTE in addition to the arch-neutral\n> > +\t * generic defines for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE.\n> > +\t * Ensure that the bits a distinct.\n> > +\t */\n> > +\tBUILD_BUG_ON(PKEY_DISABLE_EXECUTE &\n> > +\t\t     (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));\n> \n> Will these values every change? It's good to have I guess.\n> \n> > +\n> >  \t/* disable the pkey system till everything\n> >  \t * is in place. A patch further down the\n> >  \t * line will enable it.\n> > @@ -120,10 +128,18 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,\n> >  \t\tunsigned long init_val)\n> >  {\n> >  \tu64 new_amr_bits = 0x0ul;\n> > +\tu64 new_iamr_bits = 0x0ul;\n> >  \n> >  \tif (!is_pkey_enabled(pkey))\n> >  \t\treturn -EINVAL;\n> >  \n> > +\tif ((init_val & PKEY_DISABLE_EXECUTE)) {\n> > +\t\tif (!pkey_execute_disable_support)\n> > +\t\t\treturn -EINVAL;\n> > +\t\tnew_iamr_bits |= IAMR_EX_BIT;\n> > +\t}\n> > +\tinit_iamr(pkey, new_iamr_bits);\n> > +\n> \n> Where do we check the reserved keys?\n\nThe main gate keeper against spurious keys are the system calls.\nsys_pkey_mprotect(), sys_pkey_free() and sys_pkey_modify() are the one\nthat will check against reserved and unallocated keys.  Once it has\npassed the check, all other internal functions trust the key values\nprovided to them. I can put in additional checks but that will\nunnecessarily chew a few cpu cycles.\n\nAgree?\n\nBTW: you raise a good point though, I may have missed guarding against\nunallocated or reserved keys in sys_pkey_modify(). That was a power\nspecific system call that I have introduced to change the permissions on\na key.\n\nRP","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yH0fj1rKsz9sNw\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 18 Oct 2017 16:17:01 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yH0fj10zvzDrTq\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 18 Oct 2017 16:17:01 +1100 (AEDT)","from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n\t[148.163.158.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yH0dX2bTDzDrD6\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tWed, 18 Oct 2017 16:16:00 +1100 (AEDT)","from pps.filterd (m0098417.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9I5EGL1017515\n\tfor <linuxppc-dev@lists.ozlabs.org>; Wed, 18 Oct 2017 01:15:57 -0400","from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2dnsgfqxw0-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Wed, 18 Oct 2017 01:15:57 -0400","from localhost\n\tby e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from <linuxram@us.ibm.com>;\n\tTue, 17 Oct 2017 23:15:56 -0600","from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20)\n\tby e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tTue, 17 Oct 2017 23:15:52 -0600","from b03ledav005.gho.boulder.ibm.com\n\t(b03ledav005.gho.boulder.ibm.com [9.17.130.236])\n\tby b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9I5Fqsi31785058; Tue, 17 Oct 2017 22:15:52 -0700","from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 0F916BE03E;\n\tTue, 17 Oct 2017 23:15:52 -0600 (MDT)","from ram.oc3035372033.ibm.com (unknown [9.85.176.245])\n\tby b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTPS id\n\t40EA5BE039; Tue, 17 Oct 2017 23:15:50 -0600 (MDT)"],"Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=us.ibm.com\n\t(client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=linuxram@us.ibm.com; receiver=<UNKNOWN>)","Date":"Tue, 17 Oct 2017 22:15:47 -0700","From":"Ram Pai <linuxram@us.ibm.com>","To":"Balbir Singh <bsingharora@gmail.com>","Subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>\n\t<20171018144256.72bdd785@firefly.ozlabs.ibm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20171018144256.72bdd785@firefly.ozlabs.ibm.com>","User-Agent":"Mutt/1.5.20 (2009-12-10)","X-TM-AS-GCONF":"00","x-cbid":"17101805-0024-0000-0000-0000175A56ED","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007910; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000237; SDB=6.00932748; UDB=6.00469744;\n\tIPR=6.00713038; \n\tBA=6.00005643; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009;\n\tZB=6.00000000; \n\tZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017587;\n\tXFM=3.00000015; UTC=2017-10-18 05:15:55","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17101805-0025-0000-0000-00004D261617","Message-Id":"<20171018051547.GD5617@ram.oc3035372033.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-17_15:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=2\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1710180075","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Reply-To":"Ram Pai <linuxram@us.ibm.com>","Cc":"ebiederm@xmission.com, mhocko@kernel.org, paulus@samba.org,\n\taneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com,\n\tlinuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}},{"id":1792966,"web_url":"http://patchwork.ozlabs.org/comment/1792966/","msgid":"<87h8up88n1.fsf@linux.vnet.ibm.com>","date":"2017-10-24T04:36:18","subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","submitter":{"id":664,"url":"http://patchwork.ozlabs.org/api/people/664/","name":"Aneesh Kumar K.V","email":"aneesh.kumar@linux.vnet.ibm.com"},"content":"Ram Pai <linuxram@us.ibm.com> writes:\n\n> powerpc has hardware support to disable execute on a pkey.\n> This patch enables the ability to create execute-disabled\n> keys.\n\nCan you summarize here how this works?  Access to IAMR is\nprivileged so how will keys framework work with IAMR? \n\n-aneesh","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yLgVk0gkvz9s7v\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 24 Oct 2017 15:37:50 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yLgVj6ZkqzDqkm\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 24 Oct 2017 15:37:49 +1100 (AEDT)","from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com\n\t[148.163.156.1])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yLgTG1bhRzDqZ3\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tTue, 24 Oct 2017 15:36:33 +1100 (AEDT)","from pps.filterd (m0098399.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9O4YAtL110885\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 00:36:31 -0400","from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2dsng1523u-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 00:36:31 -0400","from localhost\n\tby e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from\n\t<aneesh.kumar@linux.vnet.ibm.com>; Tue, 24 Oct 2017 05:36:29 +0100","from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196)\n\tby e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted; \n\tTue, 24 Oct 2017 05:36:25 +0100","from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com\n\t[9.149.105.232])\n\tby b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9O4aP0725034876; Tue, 24 Oct 2017 04:36:25 GMT","from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 389F652041;\n\tTue, 24 Oct 2017 04:30:37 +0100 (BST)","from skywalker (unknown [9.85.148.119])\n\tby d06av21.portsmouth.uk.ibm.com (Postfix) with SMTP id 1A62D52047;\n\tTue, 24 Oct 2017 04:30:32 +0100 (BST)","(nullmailer pid 14129 invoked by uid 1000);\n\tTue, 24 Oct 2017 04:36:18 -0000"],"Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com\n\t(client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=aneesh.kumar@linux.vnet.ibm.com; receiver=<UNKNOWN>)","From":"\"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>","To":"Ram Pai <linuxram@us.ibm.com>, mpe@ellerman.id.au,\n\tlinuxppc-dev@lists.ozlabs.org","Subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","In-Reply-To":"<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>","Date":"Tue, 24 Oct 2017 10:06:18 +0530","MIME-Version":"1.0","Content-Type":"text/plain","X-TM-AS-GCONF":"00","x-cbid":"17102404-0008-0000-0000-000004A32C74","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17102404-0009-0000-0000-00001E35943A","Message-Id":"<87h8up88n1.fsf@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-24_01:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=1\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1710240065","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"linuxram@us.ibm.com, mhocko@kernel.org, paulus@samba.org,\n\tebiederm@xmission.com, bauerman@linux.vnet.ibm.com,\n\tkhandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}},{"id":1793004,"web_url":"http://patchwork.ozlabs.org/comment/1793004/","msgid":"<87wp3lvxpg.fsf@linux.vnet.ibm.com>","date":"2017-10-24T06:58:35","subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","submitter":{"id":664,"url":"http://patchwork.ozlabs.org/api/people/664/","name":"Aneesh Kumar K.V","email":"aneesh.kumar@linux.vnet.ibm.com"},"content":"Ram Pai <linuxram@us.ibm.com> writes:\n\n> On Wed, Oct 18, 2017 at 02:42:56PM +1100, Balbir Singh wrote:\n>> On Fri,  8 Sep 2017 15:44:57 -0700\n>> Ram Pai <linuxram@us.ibm.com> wrote:\n>> \n>> > powerpc has hardware support to disable execute on a pkey.\n>> > This patch enables the ability to create execute-disabled\n>> > keys.\n>> > \n>> > Signed-off-by: Ram Pai <linuxram@us.ibm.com>\n>> > ---\n>> >  arch/powerpc/include/uapi/asm/mman.h |    6 ++++++\n>> >  arch/powerpc/mm/pkeys.c              |   16 ++++++++++++++++\n>> >  2 files changed, 22 insertions(+), 0 deletions(-)\n>> > \n>> > diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h\n>> > index ab45cc2..f272b09 100644\n>> > --- a/arch/powerpc/include/uapi/asm/mman.h\n>> > +++ b/arch/powerpc/include/uapi/asm/mman.h\n>> > @@ -45,4 +45,10 @@\n>> >  #define MAP_HUGE_1GB\t(30 << MAP_HUGE_SHIFT)\t/* 1GB   HugeTLB Page */\n>> >  #define MAP_HUGE_16GB\t(34 << MAP_HUGE_SHIFT)\t/* 16GB  HugeTLB Page */\n>> >  \n>> > +/* override any generic PKEY Permission defines */\n>> > +#define PKEY_DISABLE_EXECUTE   0x4\n>> > +#undef PKEY_ACCESS_MASK\n>> > +#define PKEY_ACCESS_MASK       (PKEY_DISABLE_ACCESS |\\\n>> > +\t\t\t\tPKEY_DISABLE_WRITE  |\\\n>> > +\t\t\t\tPKEY_DISABLE_EXECUTE)\n>> >  #endif /* _UAPI_ASM_POWERPC_MMAN_H */\n>> > diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c\n>> > index cc5be6a..2282864 100644\n>> > --- a/arch/powerpc/mm/pkeys.c\n>> > +++ b/arch/powerpc/mm/pkeys.c\n>> > @@ -24,6 +24,14 @@ void __init pkey_initialize(void)\n>> >  {\n>> >  \tint os_reserved, i;\n>> >  \n>> > +\t/*\n>> > +\t * we define PKEY_DISABLE_EXECUTE in addition to the arch-neutral\n>> > +\t * generic defines for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE.\n>> > +\t * Ensure that the bits a distinct.\n>> > +\t */\n>> > +\tBUILD_BUG_ON(PKEY_DISABLE_EXECUTE &\n>> > +\t\t     (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));\n>> \n>> Will these values every change? It's good to have I guess.\n>> \n>> > +\n>> >  \t/* disable the pkey system till everything\n>> >  \t * is in place. A patch further down the\n>> >  \t * line will enable it.\n>> > @@ -120,10 +128,18 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,\n>> >  \t\tunsigned long init_val)\n>> >  {\n>> >  \tu64 new_amr_bits = 0x0ul;\n>> > +\tu64 new_iamr_bits = 0x0ul;\n>> >  \n>> >  \tif (!is_pkey_enabled(pkey))\n>> >  \t\treturn -EINVAL;\n>> >  \n>> > +\tif ((init_val & PKEY_DISABLE_EXECUTE)) {\n>> > +\t\tif (!pkey_execute_disable_support)\n>> > +\t\t\treturn -EINVAL;\n>> > +\t\tnew_iamr_bits |= IAMR_EX_BIT;\n>> > +\t}\n>> > +\tinit_iamr(pkey, new_iamr_bits);\n>> > +\n>> \n>> Where do we check the reserved keys?\n>\n> The main gate keeper against spurious keys are the system calls.\n> sys_pkey_mprotect(), sys_pkey_free() and sys_pkey_modify() are the one\n> that will check against reserved and unallocated keys.  Once it has\n> passed the check, all other internal functions trust the key values\n> provided to them. I can put in additional checks but that will\n> unnecessarily chew a few cpu cycles.\n>\n> Agree?\n>\n> BTW: you raise a good point though, I may have missed guarding against\n> unallocated or reserved keys in sys_pkey_modify(). That was a power\n> specific system call that I have introduced to change the permissions on\n> a key.\n\nWhy do you need a power specific syscall? We should ideally not require\nanything powerpc specific in the application to use memory keys. If it\nis for exectue only key, the programming model should remain same as the\nother keys.\n\nNOTE: I am not able to find patch that add sys_pkey_modify()\n\n-aneesh","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yLkfm2zZgz9s82\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 24 Oct 2017 18:00:00 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yLkfm1fzHzDr28\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 24 Oct 2017 18:00:00 +1100 (AEDT)","from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n\t[148.163.158.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yLkdQ55hrzDqhg\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tTue, 24 Oct 2017 17:58:50 +1100 (AEDT)","from pps.filterd (m0098416.ppops.net [127.0.0.1])\n\tby mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9O6s8QU080468\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 02:58:47 -0400","from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110])\n\tby mx0b-001b2d01.pphosted.com with ESMTP id 2dt0na08jx-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 02:58:47 -0400","from localhost\n\tby e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from\n\t<aneesh.kumar@linux.vnet.ibm.com>; Tue, 24 Oct 2017 07:58:45 +0100","from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198)\n\tby e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted; \n\tTue, 24 Oct 2017 07:58:43 +0100","from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60])\n\tby b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9O6wgDV22347962; Tue, 24 Oct 2017 06:58:42 GMT","from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 6203F4203F;\n\tTue, 24 Oct 2017 07:54:07 +0100 (BST)","from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 1721842041;\n\tTue, 24 Oct 2017 07:54:03 +0100 (BST)","from skywalker (unknown [9.85.148.119])\n\tby d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP;\n\tTue, 24 Oct 2017 07:54:02 +0100 (BST)","(nullmailer pid 20601 invoked by uid 1000);\n\tTue, 24 Oct 2017 06:58:35 -0000"],"Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com\n\t(client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=aneesh.kumar@linux.vnet.ibm.com; receiver=<UNKNOWN>)","From":"\"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>","To":"Ram Pai <linuxram@us.ibm.com>, Balbir Singh <bsingharora@gmail.com>","Subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","In-Reply-To":"<20171018051547.GD5617@ram.oc3035372033.ibm.com>","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>\n\t<20171018144256.72bdd785@firefly.ozlabs.ibm.com>\n\t<20171018051547.GD5617@ram.oc3035372033.ibm.com>","Date":"Tue, 24 Oct 2017 12:28:35 +0530","MIME-Version":"1.0","Content-Type":"text/plain","X-TM-AS-GCONF":"00","x-cbid":"17102406-0016-0000-0000-000004F92ED2","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17102406-0017-0000-0000-000028349EAE","Message-Id":"<87wp3lvxpg.fsf@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-24_03:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=5\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1710240097","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Cc":"mhocko@kernel.org, paulus@samba.org, ebiederm@xmission.com,\n\tbauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org,\n\tkhandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}},{"id":1793008,"web_url":"http://patchwork.ozlabs.org/comment/1793008/","msgid":"<20171024072044.GH5454@ram.oc3035372033.ibm.com>","date":"2017-10-24T07:20:44","subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","submitter":{"id":2667,"url":"http://patchwork.ozlabs.org/api/people/2667/","name":"Ram Pai","email":"linuxram@us.ibm.com"},"content":"On Tue, Oct 24, 2017 at 12:28:35PM +0530, Aneesh Kumar K.V wrote:\n> Ram Pai <linuxram@us.ibm.com> writes:\n> \n> > On Wed, Oct 18, 2017 at 02:42:56PM +1100, Balbir Singh wrote:\n> >> On Fri,  8 Sep 2017 15:44:57 -0700\n> >> Ram Pai <linuxram@us.ibm.com> wrote:\n> >> \n> >> > powerpc has hardware support to disable execute on a pkey.\n> >> > This patch enables the ability to create execute-disabled\n> >> > keys.\n> >> > \n> >> > Signed-off-by: Ram Pai <linuxram@us.ibm.com>\n> >> > ---\n> >> >  arch/powerpc/include/uapi/asm/mman.h |    6 ++++++\n> >> >  arch/powerpc/mm/pkeys.c              |   16 ++++++++++++++++\n> >> >  2 files changed, 22 insertions(+), 0 deletions(-)\n> >> > \n> >> > diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h\n> >> > index ab45cc2..f272b09 100644\n> >> > --- a/arch/powerpc/include/uapi/asm/mman.h\n> >> > +++ b/arch/powerpc/include/uapi/asm/mman.h\n> >> > @@ -45,4 +45,10 @@\n> >> >  #define MAP_HUGE_1GB\t(30 << MAP_HUGE_SHIFT)\t/* 1GB   HugeTLB Page */\n> >> >  #define MAP_HUGE_16GB\t(34 << MAP_HUGE_SHIFT)\t/* 16GB  HugeTLB Page */\n> >> >  \n> >> > +/* override any generic PKEY Permission defines */\n> >> > +#define PKEY_DISABLE_EXECUTE   0x4\n> >> > +#undef PKEY_ACCESS_MASK\n> >> > +#define PKEY_ACCESS_MASK       (PKEY_DISABLE_ACCESS |\\\n> >> > +\t\t\t\tPKEY_DISABLE_WRITE  |\\\n> >> > +\t\t\t\tPKEY_DISABLE_EXECUTE)\n> >> >  #endif /* _UAPI_ASM_POWERPC_MMAN_H */\n> >> > diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c\n> >> > index cc5be6a..2282864 100644\n> >> > --- a/arch/powerpc/mm/pkeys.c\n> >> > +++ b/arch/powerpc/mm/pkeys.c\n> >> > @@ -24,6 +24,14 @@ void __init pkey_initialize(void)\n> >> >  {\n> >> >  \tint os_reserved, i;\n> >> >  \n> >> > +\t/*\n> >> > +\t * we define PKEY_DISABLE_EXECUTE in addition to the arch-neutral\n> >> > +\t * generic defines for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE.\n> >> > +\t * Ensure that the bits a distinct.\n> >> > +\t */\n> >> > +\tBUILD_BUG_ON(PKEY_DISABLE_EXECUTE &\n> >> > +\t\t     (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));\n> >> \n> >> Will these values every change? It's good to have I guess.\n> >> \n> >> > +\n> >> >  \t/* disable the pkey system till everything\n> >> >  \t * is in place. A patch further down the\n> >> >  \t * line will enable it.\n> >> > @@ -120,10 +128,18 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,\n> >> >  \t\tunsigned long init_val)\n> >> >  {\n> >> >  \tu64 new_amr_bits = 0x0ul;\n> >> > +\tu64 new_iamr_bits = 0x0ul;\n> >> >  \n> >> >  \tif (!is_pkey_enabled(pkey))\n> >> >  \t\treturn -EINVAL;\n> >> >  \n> >> > +\tif ((init_val & PKEY_DISABLE_EXECUTE)) {\n> >> > +\t\tif (!pkey_execute_disable_support)\n> >> > +\t\t\treturn -EINVAL;\n> >> > +\t\tnew_iamr_bits |= IAMR_EX_BIT;\n> >> > +\t}\n> >> > +\tinit_iamr(pkey, new_iamr_bits);\n> >> > +\n> >> \n> >> Where do we check the reserved keys?\n> >\n> > The main gate keeper against spurious keys are the system calls.\n> > sys_pkey_mprotect(), sys_pkey_free() and sys_pkey_modify() are the one\n> > that will check against reserved and unallocated keys.  Once it has\n> > passed the check, all other internal functions trust the key values\n> > provided to them. I can put in additional checks but that will\n> > unnecessarily chew a few cpu cycles.\n> >\n> > Agree?\n> >\n> > BTW: you raise a good point though, I may have missed guarding against\n> > unallocated or reserved keys in sys_pkey_modify(). That was a power\n> > specific system call that I have introduced to change the permissions on\n> > a key.\n> \n> Why do you need a power specific syscall? We should ideally not require\n> anything powerpc specific in the application to use memory keys. If it\n> is for exectue only key, the programming model should remain same as the\n> other keys.\n\nThe programming model has not changed. It continues to be the\nsame. i.e \n\na) allocate a key  through sys_pkey_alloc()\nb) associate the key to a addressspace through sys_pkey_mprotect()\nc) change the permissions on the key by programming the AMR register as\n\tand when needed.\nd) free the key through sys_pkey_free() when done.\n\n\nthe problem is with the programming of execute-permission on the key. x86\ndoes not support the execute-permission and does not have the issue.\n\npowerpc supports execute-permission but unfortunately has not exposed\nthat capability to userspace, because IAMR cannot be programmed from\nuserspace. I have filled in that gap, by providing a power-specific\nsystem call called sys_pkey_modify().  It is a way to enable the exact \nsame programming model on keys for execute-permissions.\n\n\n> \n> NOTE: I am not able to find patch that add sys_pkey_modify()\n\nYes that patch was added only recently to my tree after consulting\nMichael Ellermen. I am yet to send out that patch. Will be doing so\nin my next version.\n\nRP\n\n> \n> -aneesh","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yLl8K3fyXz9s82\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 24 Oct 2017 18:22:09 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yLl8K2bSvzDqts\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 24 Oct 2017 18:22:09 +1100 (AEDT)","from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com\n\t[148.163.156.1])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yLl6y62qfzDqhg\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tTue, 24 Oct 2017 18:20:58 +1100 (AEDT)","from pps.filterd (m0098409.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9O7JZCk141645\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 03:20:56 -0400","from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2dsxvh6ft8-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 03:20:56 -0400","from localhost\n\tby e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from <linuxram@us.ibm.com>;\n\tTue, 24 Oct 2017 01:20:54 -0600","from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17)\n\tby e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tTue, 24 Oct 2017 01:20:50 -0600","from b03ledav002.gho.boulder.ibm.com\n\t(b03ledav002.gho.boulder.ibm.com [9.17.130.233])\n\tby b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9O7KnMa1442280; Tue, 24 Oct 2017 00:20:49 -0700","from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id CE8CC136048;\n\tTue, 24 Oct 2017 01:20:49 -0600 (MDT)","from ram.oc3035372033.ibm.com (unknown [9.85.182.80])\n\tby b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTPS id\n\t7AC5B136043; Tue, 24 Oct 2017 01:20:47 -0600 (MDT)"],"Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=us.ibm.com\n\t(client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=linuxram@us.ibm.com; receiver=<UNKNOWN>)","Date":"Tue, 24 Oct 2017 00:20:44 -0700","From":"Ram Pai <linuxram@us.ibm.com>","To":"\"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>","Subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>\n\t<20171018144256.72bdd785@firefly.ozlabs.ibm.com>\n\t<20171018051547.GD5617@ram.oc3035372033.ibm.com>\n\t<87wp3lvxpg.fsf@linux.vnet.ibm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<87wp3lvxpg.fsf@linux.vnet.ibm.com>","User-Agent":"Mutt/1.5.20 (2009-12-10)","X-TM-AS-GCONF":"00","x-cbid":"17102407-0008-0000-0000-000008C1261D","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007943; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000239; SDB=6.00935658; UDB=6.00471422;\n\tIPR=6.00715924; \n\tBA=6.00005657; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009;\n\tZB=6.00000000; \n\tZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017682;\n\tXFM=3.00000015; UTC=2017-10-24 07:20:52","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17102407-0009-0000-0000-0000447B9169","Message-Id":"<20171024072044.GH5454@ram.oc3035372033.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-24_03:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=2\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1710240102","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Reply-To":"Ram Pai <linuxram@us.ibm.com>","Cc":"mhocko@kernel.org, paulus@samba.org, ebiederm@xmission.com,\n\tbauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org,\n\tkhandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}},{"id":1795352,"web_url":"http://patchwork.ozlabs.org/comment/1795352/","msgid":"<20171028231835.GB5587@ram.oc3035372033.ibm.com>","date":"2017-10-28T23:18:35","subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","submitter":{"id":2667,"url":"http://patchwork.ozlabs.org/api/people/2667/","name":"Ram Pai","email":"linuxram@us.ibm.com"},"content":"On Tue, Oct 24, 2017 at 10:06:18AM +0530, Aneesh Kumar K.V wrote:\n> Ram Pai <linuxram@us.ibm.com> writes:\n> \n> > powerpc has hardware support to disable execute on a pkey.\n> > This patch enables the ability to create execute-disabled\n> > keys.\n> \n> Can you summarize here how this works?  Access to IAMR is\n> privileged so how will keys framework work with IAMR? \n> \n> -aneesh\n\nright. IAMR will have to programmed through a system call.\nI have introduced a sys_pkey_modify()  which takes a key value\nand the permission that it wants to enable/disable on that key.\nThis syscall is powerpc specific only for now, since no other\narch's need it.\n\nThe patch is at http://patchwork.ozlabs.org/patch/817961/","headers":{"Return-Path":"<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>","X-Original-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yPcCV1wtbz9t30\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSun, 29 Oct 2017 10:19:50 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yPcCV0gtBzDrd4\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSun, 29 Oct 2017 10:19:50 +1100 (AEDT)","from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n\t[148.163.158.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yPcBK2sTVzDqs4\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tSun, 29 Oct 2017 10:18:48 +1100 (AEDT)","from pps.filterd (m0098420.ppops.net [127.0.0.1])\n\tby mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9SNDXgU028884\n\tfor <linuxppc-dev@lists.ozlabs.org>; Sat, 28 Oct 2017 19:18:45 -0400","from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158])\n\tby mx0b-001b2d01.pphosted.com with ESMTP id 2dvp3crp8t-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Sat, 28 Oct 2017 19:18:45 -0400","from localhost\n\tby e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <linuxppc-dev@lists.ozlabs.org> from <linuxram@us.ibm.com>;\n\tSat, 28 Oct 2017 17:18:44 -0600","from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17)\n\tby e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tSat, 28 Oct 2017 17:18:40 -0600","from b03ledav005.gho.boulder.ibm.com\n\t(b03ledav005.gho.boulder.ibm.com [9.17.130.236])\n\tby b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9SNIeti6619466; Sat, 28 Oct 2017 16:18:40 -0700","from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 1B525BE038;\n\tSat, 28 Oct 2017 17:18:40 -0600 (MDT)","from ram.oc3035372033.ibm.com (unknown [9.85.153.11])\n\tby b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTPS id\n\t9581BBE039; Sat, 28 Oct 2017 17:18:38 -0600 (MDT)"],"Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=us.ibm.com\n\t(client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=linuxram@us.ibm.com; receiver=<UNKNOWN>)","Date":"Sat, 28 Oct 2017 16:18:35 -0700","From":"Ram Pai <linuxram@us.ibm.com>","To":"\"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>","Subject":"Re: [PATCH 09/25] powerpc: ability to create execute-disabled pkeys","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-18-git-send-email-linuxram@us.ibm.com>\n\t<87h8up88n1.fsf@linux.vnet.ibm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<87h8up88n1.fsf@linux.vnet.ibm.com>","User-Agent":"Mutt/1.5.20 (2009-12-10)","X-TM-AS-GCONF":"00","x-cbid":"17102823-0024-0000-0000-00001767737A","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007970; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000239; SDB=6.00937895; UDB=6.00472707;\n\tIPR=6.00718156; \n\tBA=6.00005662; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009;\n\tZB=6.00000000; \n\tZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017769;\n\tXFM=3.00000015; UTC=2017-10-28 23:18:42","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17102823-0025-0000-0000-00004D4A1BEC","Message-Id":"<20171028231835.GB5587@ram.oc3035372033.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-28_06:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tpriorityscore=1501\n\tmalwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0\n\tclxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0\n\tclassifier=spam adjust=0 reason=mlx scancount=1\n\tengine=8.0.1-1707230000\n\tdefinitions=main-1710280329","X-BeenThere":"linuxppc-dev@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Linux on PowerPC Developers Mail List\n\t<linuxppc-dev.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/linuxppc-dev>,\n\t<mailto:linuxppc-dev-request@lists.ozlabs.org?subject=subscribe>","Reply-To":"Ram Pai <linuxram@us.ibm.com>","Cc":"mhocko@kernel.org, paulus@samba.org, ebiederm@xmission.com,\n\tbauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org,\n\tkhandual@linux.vnet.ibm.com","Errors-To":"linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org","Sender":"\"Linuxppc-dev\"\n\t<linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org>"}}]