Bug 23202 - tst-pkeys fails on POWER
Summary: tst-pkeys fails on POWER
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.27
: P3 normal
Target Milestone: 2.32
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 23885 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-18 13:31 UTC by Florian Weimer
Modified: 2023-07-02 16:08 UTC (History)
5 users (show)

See Also:
Host:
Target: powerpc64
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2018-05-18 13:31:32 UTC
misc/tst-pkeys fails on POWER if they kernel implements memory protection keys because pkey_set and pkey_get are the stub implementations.

I have implementations for these functions on POWER (translating them into AMR register accesses), but the kernel support has issues:

https://lists.ozlabs.org/pipermail/linuxppc-dev/2018-May/173157.html
Comment 1 Florian Weimer 2018-05-18 14:28:00 UTC
Another problem (currently not covered by tst-pkeys):

https://lists.ozlabs.org/pipermail/linuxppc-dev/2018-May/173160.html
Comment 2 Florian Weimer 2018-06-14 20:10:26 UTC
To fix this, we need an implement of pkey_set and pkey_get for POWER:

https://sourceware.org/ml/libc-alpha/2018-05/msg00760.html

We need some kernel fixes, especially for fork and execve:

https://lists.ozlabs.org/pipermail/linuxppc-dev/2018-June/174612.html

And then there are some incorrect assumptions encoded in tst-pkeys itself (I have a patch).
Comment 3 Florian Weimer 2018-11-15 12:06:08 UTC
*** Bug 23885 has been marked as a duplicate of this bug. ***
Comment 4 Florian Weimer 2018-11-15 12:35:55 UTC
Ideally, we'd get a PKEY_DISABLE_READ flag to support POWER better for pkey_get:

From: Florian Weimer <fweimer@redhat.com>
Subject: pkeys: Reserve PKEY_DISABLE_READ
To: linux-api@vger.kernel.org, linux-mm@kvack.org
Cc: dave.hansen@intel.com, linuxram@us.ibm.com
Date: Thu, 08 Nov 2018 13:05:09 +0100

https://marc.info/?l=linux-mm&m=154167872212711

I haven't seen a kernel patch for this yet.
Comment 5 Sourceware Commits 2020-02-14 19:57:01 UTC
The master branch has been updated by Florian Weimer <fw@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a803367bab167f5ec4fde1f0d0ec447707c29520

commit a803367bab167f5ec4fde1f0d0ec447707c29520
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Feb 14 20:55:39 2020 +0100

    powerpc64: Add memory protection key support [BZ #23202]
    
    The 32-bit protection key behavior is somewhat unclear on 32-bit powerpc,
    so this change is restricted to the 64-bit variants.
    
    Flag translation is needed because of hardware differences between the
    POWER implementation (read and write flags) and the Intel implementation
    (write and read+write flags).
Comment 6 Florian Weimer 2020-02-14 19:59:05 UTC
misc/tst-pkeys still needs to be updated with different test expectations.
Comment 7 Sourceware Commits 2020-02-19 14:40:43 UTC
The master branch has been updated by Tulio Magno Quites Machado Filho <tuliom@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8d42bf859a289944749d9f978c076cd318119867

commit 8d42bf859a289944749d9f978c076cd318119867
Author: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
Date:   Mon Feb 17 09:09:52 2020 -0300

    Fix tst-pkey expectations on pkey_get [BZ #23202]
    
    From the GNU C Library manual, the pkey_set can receive a combination of
    PKEY_DISABLE_WRITE and PKEY_DISABLE_ACCESS.  However PKEY_DISABLE_ACCESS
    is more restrictive than PKEY_DISABLE_WRITE and includes its behavior.
    
    The test expects that after setting
    (PKEY_DISABLE_WRITE|PKEY_DISABLE_ACCESS) pkey_get should return the
    same.  This may not be true as PKEY_DISABLE_ACCESS will succeed in
    describing the state of the key in this case.
    
    The pkey behavior during signal handling is different between x86 and
    POWER.  This change make the test compatible with both architectures.
    
    Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Comment 8 Tulio Magno Quites Machado Filho 2020-02-20 20:58:03 UTC
There is still a scenario where tst-pkeys fail on POWER: when Linux <= 4.18.

More information here: https://www.sourceware.org/ml/libc-alpha/2020-02/msg00819.html

The support for pkeys on POWER was enabled on Linux 4.16. However, it had issues that have been fixed on Linux 4.19.
Calls to pkey_alloc() succeed in that scenario, making it hard to detect the support for pkeys.
Comment 9 Florian Weimer 2023-07-02 16:08:25 UTC
Fixed in 2.32.