From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-f198.google.com (mail-ua0-f198.google.com [209.85.217.198]) by kanga.kvack.org (Postfix) with ESMTP id C4DC86B0005 for ; Thu, 8 Mar 2018 22:43:02 -0500 (EST) Received: by mail-ua0-f198.google.com with SMTP id w9so1163579uaa.17 for ; Thu, 08 Mar 2018 19:43:02 -0800 (PST) Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 33sor44634uam.284.2018.03.08.19.43.01 for (Google Transport Security); Thu, 08 Mar 2018 19:43:01 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20180308164545.GM1060@ram.oc3035372033.ibm.com> References: <871sguep4v.fsf@concordia.ellerman.id.au> <20180308164545.GM1060@ram.oc3035372033.ibm.com> From: Li Wang Date: Fri, 9 Mar 2018 11:43:00 +0800 Message-ID: Subject: Re: [bug?] Access was denied by memory protection keys in execute-only address Content-Type: multipart/alternative; boundary="f40304365f58c2d44b0566f296b5" Sender: owner-linux-mm@kvack.org List-ID: To: Ram Pai Cc: Michael Ellerman , Jan Stancek , ltp@lists.linux.it, linux-mm@kvack.org, "linuxppc-dev@lists.ozlabs.org" --f40304365f58c2d44b0566f296b5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 9, 2018 at 12:45 AM, Ram Pai wrote: > On Thu, Mar 08, 2018 at 11:19:12PM +1100, Michael Ellerman wrote: > > Li Wang writes: > > > Hi, > > > > > > ltp/mprotect04[1] crashed by SEGV_PKUERR on ppc64(LPAR on P730, Power= 8 > > > 8247-22L) with kernel-v4.16.0-rc4. > > > > > > 10000000-10020000 r-xp 00000000 fd:00 167223 mprotect04 > > > 10020000-10030000 r--p 00010000 fd:00 167223 mprotect04 > > > 10030000-10040000 rw-p 00020000 fd:00 167223 mprotect04 > > > 1001a380000-1001a3b0000 rw-p 00000000 00:00 0 [heap] > > > 7fffa6c60000-7fffa6c80000 --xp 00000000 00:00 0 =E2=80=8B > > > > > > =E2=80=8B&exec_func =3D 0x10030170=E2=80=8B > > > > > > =E2=80=8B&func =3D 0x7fffa6c60170=E2=80=8B > > > > > > =E2=80=8BWhile perform =E2=80=8B > > > "(*func)();" we get the > > > =E2=80=8Bsegmentation fault. > > > =E2=80=8B > > > > > > =E2=80=8Bstrace log:=E2=80=8B > > > > > > ------------------- > > > =E2=80=8Bmprotect(0x7fffaed00000, 131072, PROT_EXEC) =3D 0 > > > rt_sigprocmask(SIG_BLOCK, NULL, [], 8) =3D 0 > > > --- SIGSEGV {si_signo=3DSIGSEGV, si_code=3DSEGV_PKUERR, > si_addr=3D0x7fffaed00170} > > > ---=E2=80=8B > > > > Looks like a bug to me. > > > > Please Cc linuxppc-dev on powerpc bugs. > > > > I also can't reproduce this failure on my machine. > > Not sure what's going on? > > I could reproduce it on a power7 lpar. But not on a power8 lpar. > > The problem seems to be that the cpu generates a key exception if > the page with Read/Write-disable-but-execute-enable key is executed > on power7. If I enable read on that key, the exception disappears. > After adding read permission on that key, reproducer get PASS on my power8 machine too.=E2=80=8B =E2=80=8B(=E2=80=8Bmprotect(..,PROT_READ | PROT_EXEC))=E2=80=8B > > BTW: the testcase executes > =E2=80=8B=E2=80=8B > mprotect(..,PROT_EXEC). > The mprotect(, PROT_EXEC) system call internally generates a > execute-only key and associates it with the pages in the address-range. > Now since Li Wang claims that he can reproduce it on power8 as well, i > am wondering if the slightly different cpu behavior is dependent on the > version of the firmware/microcode? > =E2=80=8BI also run this reproducer on series ppc kvm machines, but none of= them get the FAIL. If you need some more HW info, pls let me know.=E2=80=8B > > > RP > > --=20 Li Wang liwang@redhat.com --f40304365f58c2d44b0566f296b5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Mar 9, 2018 at 12:45 AM, Ram Pai <linuxram@us.ibm.com&= gt; wrote:
On Thu, Mar 08, 2018 at 11:19:12PM +1100, Michael Ellerman= wrote:
> Li Wang <liw= ang@redhat.com> writes:
> > Hi,
> >
> > ltp/mprotect04[1] crashed by SEGV_PKUERR on ppc64(LPAR on P730, P= ower 8
> > 8247-22L) with kernel-v4.16.0-rc4.
> >
> > 10000000-10020000 r-xp 00000000 fd:00 167223=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0mprotect04
> > 10020000-10030000 r--p 00010000 fd:00 167223=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0mprotect04
> > 10030000-10040000 rw-p 00020000 fd:00 167223=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0mprotect04
> > 1001a380000-1001a3b0000 rw-p 00000000 00:00 0=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 [heap]
> > 7fffa6c60000-7fffa6c80000 --xp 00000000 00:00 0 =E2=80=8B
> >
> > =E2=80=8B&exec_func =3D 0x10030170=E2=80=8B
> >
> > =E2=80=8B&func =3D 0x7fffa6c60170=E2=80=8B
> >
> > =E2=80=8BWhile perform =E2=80=8B
> > "(*func)();" we get the
> > =E2=80=8Bsegmentation fault.
> > =E2=80=8B
> >
> > =E2=80=8Bstrace log:=E2=80=8B
> >
> > -------------------
> > =E2=80=8Bmprotect(0x7fffaed00000, 131072, PROT_EXEC) =3D 0
> > rt_sigprocmask(SIG_BLOCK, NULL, [], 8)=C2=A0 =3D 0
> > --- SIGSEGV {si_signo=3DSIGSEGV, si_code=3DSEGV_PKUERR, si_addr= =3D0x7fffaed00170}
> > ---=E2=80=8B
>
> Looks like a bug to me.
>
> Please Cc linuxppc-dev on powerpc bugs.
>
> I also can't reproduce this failure on my machine.
> Not sure what's going on?

I could reproduce it on a power7 lpar.=C2=A0 But not on a power= 8 lpar.

The problem seems to be that the cpu generates a key exception if
the page with Read/Write-disable-but-execute-enable key is executed on power7. If I enable read on that key, the exception disappears.

After adding read permission on that key, reproducer get PASS = on my power8 machine too.=E2=80=8B
=E2=80=8B(=E2=80=8Bmprotect(..,PROT_REA= D | PROT_EXEC))=E2=80=8B

=C2=A0

BTW: the testcase executes
=E2=80=8B=E2=80=8B
mprotect(..,P= ROT_EXEC).
The mprotect(, PROT_EXEC) system call internally generates a
execute-only key and associates it with the pages in the address-range.=C2= =A0

Now since Li Wang claims that he can reproduce it on power8 as well, i
am wondering if the slightly different cpu behavior is dependent on the
version of the firmware/microcode?

=E2=80=8BI also run= this reproducer on series ppc kvm machines, but none of them get the FAIL.=
If you need some more HW info, pls let me know.=E2=80=8B

=C2= =A0
=

RP




--
--f40304365f58c2d44b0566f296b5--