Bug 408091 - Missing pkey syscalls
Summary: Missing pkey syscalls
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.15 SVN
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-30 00:49 UTC by Mark Wielaard
Modified: 2019-06-06 16:20 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
linux x86 and amd64 memory protection key syscalls (8.79 KB, text/plain)
2019-05-30 01:00 UTC, Mark Wielaard
Details

Note You need to log in before you can comment on or make changes to this bug.
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