Bug 408091

Summary: Missing pkey syscalls
Product: [Developer tools] valgrind Reporter: Mark Wielaard <mark>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: ahajkova
Priority: NOR    
Version First Reported In: 3.15 SVN   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: linux x86 and amd64 memory protection key syscalls

Description Mark Wielaard 2019-05-30 00:49:13 UTC
Since linux 4.9 there are a couple of syscalls to handle memory protection keys.

Valgrind doesn't support memory protection keys and the RDPKRU/WRPKRU instructions to update the new PKRU register.

But the syscalls have some use without that support.
First pkey_alloc () can be used to check whether memory protection keys are usage:

       pkey_alloc() is always safe to call regardless of whether or not the
       operating system supports protection keys.  It can be used in lieu of
       any other mechanism for detecting pkey support and will simply fail
       with the error ENOSPC if the operating system has no pkey support.

Secondly pkey_mprotect can be used even without a real pkey:

If the key allocation fails due to lack of support for memory protection keys, the pkey_mprotect call can usually be skipped. In this case, the region will not be protected by default. It is also possible to call pkey_mprotect with a key value of -1, in which case it will behave in the same way as mprotect.
Comment 1 Mark Wielaard 2019-05-30 01:00:23 UTC
Created attachment 120386 [details]
linux x86 and amd64 memory protection key syscalls
Comment 2 Mark Wielaard 2019-06-06 16:20:28 UTC
commit e00335bd38c32439bb17b937ab374ca96b53a1f3
Author: Mark Wielaard <mark@klomp.org>
Date:   Thu May 30 00:29:58 2019 +0200

    linux x86 and amd64 memory protection key syscalls.
    
    This implements minimal support for the pkey_alloc, pkey_free and
    pkey_mprotect syscalls. pkey_alloc will simply indicate that pkeys
    are not supported. pkey_free always fails. pkey_mprotect works just
    like mprotect if the special pkey -1 is provided.
    
    https://bugs.kde.org/show_bug.cgi?id=408091