linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
To: Jan Stancek <jstancek@redhat.com>,
	linuxppc-dev@lists.ozlabs.org, sandipan@linux.ibm.com
Cc: Rachel Sibley <rasibley@redhat.com>, linuxram@us.ibm.com
Subject: Re: [bug] LTP mmap03 stuck in page fault loop after c46241a370a6 ("powerpc/pkeys: Check vma before returning key fault error to the user")
Date: Fri, 26 Jun 2020 14:39:33 +0530	[thread overview]
Message-ID: <a55e7ccd-09e8-726a-21d2-02b00b48d857@linux.ibm.com> (raw)
In-Reply-To: <ac99e243-0945-8be0-6ae4-73af29b7a199@linux.ibm.com>

On 6/26/20 1:17 PM, Aneesh Kumar K.V wrote:
> Hi Jan,
> 
> On 6/26/20 12:29 PM, Jan Stancek wrote:
>> Hi,
>>
>> LTP mmap03 is getting stuck in page fault loop after commit
>>    c46241a370a6 ("powerpc/pkeys: Check vma before returning key fault 
>> error to the user")
>>
>> System is ppc64le P9 lpar [1] running v5.8-rc2-34-g3e08a95294a4.
>>
>> Here's a minimized reproducer:
>> ------------------------- 8< -----------------------------
>> #include <fcntl.h>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <unistd.h>
>> #include <sys/mman.h>
>>
>> int main(int ac, char **av)
>> {
>>          int page_sz = getpagesize();
>>          int fildes;
>>          char *addr;
>>
>>          fildes = open("tempfile", O_WRONLY | O_CREAT, 0666);
>>          write(fildes, &fildes, sizeof(fildes));
>>          close(fildes);
>>
>>          fildes = open("tempfile", O_RDONLY);
>>          unlink("tempfile");
>>
>>          addr = mmap(0, page_sz, PROT_EXEC, MAP_FILE | MAP_PRIVATE, 
>> fildes, 0);
>>
>>          printf("%d\n", *addr);
>>          return 0;
>> }
>> ------------------------- >8 -----------------------------
> 
> Thanks for the report. This is execute only key where vma has the 
> implied read permission. So The patch do break this case. I will see how 
> best we can handle  PROT_EXEC and the multi threaded test that required 
> the change in the patch.
> 

Can you check with this change? While checking for access permission we 
are checking against UAMOR value which i think is wrong. We just need to 
look at the AMR and IAMR values to check whether access is permitted or 
not. Even if UAMOR deny the userspace management of the key, we should
do the correct access check.

modified   arch/powerpc/mm/book3s64/pkeys.c
@@ -353,9 +353,6 @@ static bool pkey_access_permitted(int pkey, bool 
write, bool execute)
  	int pkey_shift;
  	u64 amr;

-	if (!is_pkey_enabled(pkey))
-		return true;
-
  	pkey_shift = pkeyshift(pkey);
  	if (execute && !(read_iamr() & (IAMR_EX_BIT << pkey_shift)))
  		return true;




  reply	other threads:[~2020-06-26  9:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1402271372.18777802.1593153800272.JavaMail.zimbra@redhat.com>
2020-06-26  6:59 ` [bug] LTP mmap03 stuck in page fault loop after c46241a370a6 ("powerpc/pkeys: Check vma before returning key fault error to the user") Jan Stancek
2020-06-26  7:47   ` Aneesh Kumar K.V
2020-06-26  9:09     ` Aneesh Kumar K.V [this message]
2020-06-26  9:49       ` Jan Stancek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a55e7ccd-09e8-726a-21d2-02b00b48d857@linux.ibm.com \
    --to=aneesh.kumar@linux.ibm.com \
    --cc=jstancek@redhat.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=linuxram@us.ibm.com \
    --cc=rasibley@redhat.com \
    --cc=sandipan@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).