[{"id":1793234,"web_url":"http://patchwork.ozlabs.org/comment/1793234/","msgid":"<877evk4kgx.fsf@concordia.ellerman.id.au>","date":"2017-10-24T15:46:38","subject":"Re: [PATCH 23/25] powerpc: Deliver SEGV signal on pkey violation","submitter":{"id":46580,"url":"http://patchwork.ozlabs.org/api/people/46580/","name":"Michael Ellerman","email":"mpe@ellerman.id.au"},"content":"Ram Pai <linuxram@us.ibm.com> writes:\n\n> diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c\n> index ec74e20..f2a310d 100644\n> --- a/arch/powerpc/kernel/traps.c\n> +++ b/arch/powerpc/kernel/traps.c\n> @@ -265,6 +266,15 @@ void user_single_step_siginfo(struct task_struct *tsk,\n>  \tinfo->si_addr = (void __user *)regs->nip;\n>  }\n>  \n> +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n> +static void fill_sig_info_pkey(int si_code, siginfo_t *info, unsigned long addr)\n> +{\n> +\tif (info->si_signo != SIGSEGV || si_code != SEGV_PKUERR)\n\nJust checking si_code is sufficient there I think.\n\n> +\t\treturn;\n> +\tinfo->si_pkey = get_paca()->paca_pkey;\n> +}\n> +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n\nThis should define an empty version in the #else case, so we don't need\nthe ifdef below.\n\n> @@ -292,6 +302,18 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)\n>  \tinfo.si_signo = signr;\n>  \tinfo.si_code = code;\n>  \tinfo.si_addr = (void __user *) addr;\n> +\n> +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n> +\t/*\n> +\t * update the thread's pkey related fields.\n> +\t * core-dump handlers and other sub-systems\n> +\t * depend on those values.\n> +\t */\n> +\tthread_pkey_regs_save(&current->thread);\n\nYou shouldn't need to do this.\n\nWe're not putting any of the pkey regs in the signal frame, so you don't\nneed to save before we do that. [And if you did the right place to do it\nwould be in setup_sigcontext() (or the TM version).]\n\nFor ptrace and coredumps it should happen in pkey_get(), see eg.\nfpr_get() which does flush_fp_to_thread() as an example.\n\n> +\t/* update the violated-key value */\n> +\tfill_sig_info_pkey(code, &info, addr);\n> +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n\n> +\n>  \tforce_sig_info(signr, &info, current);\n>  }\n\ncheers","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 3yLyN54C7mz9s7p\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 25 Oct 2017 02:48:05 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yLyN53DznzDqyr\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 25 Oct 2017 02:48:05 +1100 (AEDT)","from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3yLyLg2JGnzDqfh\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tWed, 25 Oct 2017 02:46:51 +1100 (AEDT)","from authenticated.ozlabs.org (localhost [127.0.0.1])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPSA id 3yLyLd2KGRz9s7p;\n\tWed, 25 Oct 2017 02:46:48 +1100 (AEDT)"],"From":"Michael Ellerman <mpe@ellerman.id.au>","To":"Ram Pai <linuxram@us.ibm.com>, linuxppc-dev@lists.ozlabs.org","Subject":"Re: [PATCH 23/25] powerpc: Deliver SEGV signal on pkey violation","In-Reply-To":"<1504910713-7094-32-git-send-email-linuxram@us.ibm.com>","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-32-git-send-email-linuxram@us.ibm.com>","Date":"Tue, 24 Oct 2017 17:46:38 +0200","Message-ID":"<877evk4kgx.fsf@concordia.ellerman.id.au>","MIME-Version":"1.0","Content-Type":"text/plain","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, linuxram@us.ibm.com, mhocko@kernel.org,\n\tpaulus@samba.org, aneesh.kumar@linux.vnet.ibm.com,\n\tbauerman@linux.vnet.ibm.com, 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":1793330,"web_url":"http://patchwork.ozlabs.org/comment/1793330/","msgid":"<20171024171933.GJ5454@ram.oc3035372033.ibm.com>","date":"2017-10-24T17:19:33","subject":"Re: [PATCH 23/25] powerpc: Deliver SEGV signal on pkey violation","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 05:46:38PM +0200, Michael Ellerman wrote:\n> Ram Pai <linuxram@us.ibm.com> writes:\n> \n> > diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c\n> > index ec74e20..f2a310d 100644\n> > --- a/arch/powerpc/kernel/traps.c\n> > +++ b/arch/powerpc/kernel/traps.c\n> > @@ -265,6 +266,15 @@ void user_single_step_siginfo(struct task_struct *tsk,\n> >  \tinfo->si_addr = (void __user *)regs->nip;\n> >  }\n> >  \n> > +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n> > +static void fill_sig_info_pkey(int si_code, siginfo_t *info, unsigned long addr)\n> > +{\n> > +\tif (info->si_signo != SIGSEGV || si_code != SEGV_PKUERR)\n> \n> Just checking si_code is sufficient there I think.\n> \n> > +\t\treturn;\n> > +\tinfo->si_pkey = get_paca()->paca_pkey;\n> > +}\n> > +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n> \n> This should define an empty version in the #else case, so we don't need\n> the ifdef below.\n> \n> > @@ -292,6 +302,18 @@ void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)\n> >  \tinfo.si_signo = signr;\n> >  \tinfo.si_code = code;\n> >  \tinfo.si_addr = (void __user *) addr;\n> > +\n> > +#ifdef CONFIG_PPC64_MEMORY_PROTECTION_KEYS\n> > +\t/*\n> > +\t * update the thread's pkey related fields.\n> > +\t * core-dump handlers and other sub-systems\n> > +\t * depend on those values.\n> > +\t */\n> > +\tthread_pkey_regs_save(&current->thread);\n> \n> You shouldn't need to do this.\n> \n> We're not putting any of the pkey regs in the signal frame, so you don't\n> need to save before we do that. [And if you did the right place to do it\n> would be in setup_sigcontext() (or the TM version).]\n\nOne of the comments in the past was the ability to capture AMR\nregister status in core-dumps and also the ability to modify the\nAMR through ptrace. Thiago wrote a patch towards that. That patch\nis one of the subsequent patches sent in this series.\n\nI will move the code to pkey_get().\n\n> \n> For ptrace and coredumps it should happen in pkey_get(), see eg.\n> fpr_get() which does flush_fp_to_thread() as an example.\n\nOk.\n\n> \n> > +\t/* update the violated-key value */\n> > +\tfill_sig_info_pkey(code, &info, addr);\n> > +#endif /* CONFIG_PPC64_MEMORY_PROTECTION_KEYS */\n> \n> > +\n> >  \tforce_sig_info(signr, &info, current);\n> >  }\n> \n> cheers","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 3yM0T307Wqz9t2V\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 25 Oct 2017 04:22:31 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3yM0T25lCRzDqkp\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 25 Oct 2017 04:22:30 +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 3yM0Ps2HKKzDqhg\n\tfor <linuxppc-dev@lists.ozlabs.org>;\n\tWed, 25 Oct 2017 04:19:44 +1100 (AEDT)","from pps.filterd (m0098419.ppops.net [127.0.0.1])\n\tby mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv9OHGZEU037828\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 13:19:42 -0400","from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159])\n\tby mx0b-001b2d01.pphosted.com with ESMTP id 2dt85n00n8-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <linuxppc-dev@lists.ozlabs.org>; Tue, 24 Oct 2017 13:19:41 -0400","from localhost\n\tby e38.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 11:19:41 -0600","from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16)\n\tby e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tTue, 24 Oct 2017 11:19:38 -0600","from b03ledav005.gho.boulder.ibm.com\n\t(b03ledav005.gho.boulder.ibm.com [9.17.130.236])\n\tby b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v9OHJbmd8978690; Tue, 24 Oct 2017 10:19:37 -0700","from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id B42E5BE03B;\n\tTue, 24 Oct 2017 11:19:37 -0600 (MDT)","from ram.oc3035372033.ibm.com (unknown [9.85.182.80])\n\tby b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTPS id\n\tE3746BE039; Tue, 24 Oct 2017 11:19:35 -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, 24 Oct 2017 10:19:33 -0700","From":"Ram Pai <linuxram@us.ibm.com>","To":"Michael Ellerman <mpe@ellerman.id.au>","Subject":"Re: [PATCH 23/25] powerpc: Deliver SEGV signal on pkey violation","References":"<1504910713-7094-1-git-send-email-linuxram@us.ibm.com>\n\t<1504910713-7094-32-git-send-email-linuxram@us.ibm.com>\n\t<877evk4kgx.fsf@concordia.ellerman.id.au>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<877evk4kgx.fsf@concordia.ellerman.id.au>","User-Agent":"Mutt/1.5.20 (2009-12-10)","X-TM-AS-GCONF":"00","x-cbid":"17102417-0028-0000-0000-0000088BDA20","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007947; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000239; SDB=6.00935858; UDB=6.00471542;\n\tIPR=6.00716124; \n\tBA=6.00005658; 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.00017690;\n\tXFM=3.00000015; UTC=2017-10-24 17:19:40","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17102417-0029-0000-0000-0000380F895E","Message-Id":"<20171024171933.GJ5454@ram.oc3035372033.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-10-24_09:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=0\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-1710240236","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>"}}]