[PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE

Aruna Ramakrishna posted 5 patches 1 year, 8 months ago
arch/x86/include/asm/fpu/signal.h             |   2 +-
arch/x86/include/asm/sighandling.h            |  10 +-
arch/x86/kernel/fpu/signal.c                  |  27 +-
arch/x86/kernel/fpu/xstate.c                  |  13 +
arch/x86/kernel/fpu/xstate.h                  |   1 +
arch/x86/kernel/signal.c                      |  42 +-
arch/x86/kernel/signal_32.c                   |  12 +-
arch/x86/kernel/signal_64.c                   |  14 +-
tools/testing/selftests/mm/Makefile           |   5 +-
tools/testing/selftests/mm/pkey-helpers.h     |  11 +-
.../selftests/mm/pkey_sighandler_tests.c      | 479 ++++++++++++++++++
tools/testing/selftests/mm/protection_keys.c  |  10 -
12 files changed, 581 insertions(+), 45 deletions(-)
create mode 100644 tools/testing/selftests/mm/pkey_sighandler_tests.c
[PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE
Posted by Aruna Ramakrishna 1 year, 8 months ago
v5 updates:
- No major changes, mostly a resend of v4 - except for updating the
  commit description for patch 5/5

v4 updates (based on review feedback from Thomas Gleixner):
- Simplified update_pkru_in_sigframe()
- Changed sigpkru to enable minimally required keys (init_pkru and
  current
  pkru)
- Modified pkey_sighandler_tests.c to use kselfttest framework
- Fixed commit descriptions
- Fixed sigreturn use case (pointed out by Jeff Xu)
- Added a new sigreturn test case

v3 updates (based on review feedback from Ingo Molnar and Dave Hansen):
- Split the original patch into 3:
        - function interface changes
        - helper functions
        - functional change to write pkru on sigframe
- Enabled all pkeys before XSAVE - i.e. wrpkru(0), rather than assuming
that the alt sig stack is always protected by pkey 0.
- Added a few test cases in pkey_sighandler_tests.c.

I had some trouble adding these tests to
tools/testing/selftests/mm/protection_keys.c, so they're in a separate
file.

Aruna Ramakrishna (4):
  x86/pkeys: Add PKRU as a parameter in signal handling functions
  x86/pkeys: Add helper functions to update PKRU on sigframe
  x86/pkeys: Update PKRU to enable minimally required pkeys before XSAVE
  x86/pkeys: Restore altstack before sigcontext

Keith Lucas (1):
  selftests/mm: Add new testcases for pkeys

 arch/x86/include/asm/fpu/signal.h             |   2 +-
 arch/x86/include/asm/sighandling.h            |  10 +-
 arch/x86/kernel/fpu/signal.c                  |  27 +-
 arch/x86/kernel/fpu/xstate.c                  |  13 +
 arch/x86/kernel/fpu/xstate.h                  |   1 +
 arch/x86/kernel/signal.c                      |  42 +-
 arch/x86/kernel/signal_32.c                   |  12 +-
 arch/x86/kernel/signal_64.c                   |  14 +-
 tools/testing/selftests/mm/Makefile           |   5 +-
 tools/testing/selftests/mm/pkey-helpers.h     |  11 +-
 .../selftests/mm/pkey_sighandler_tests.c      | 479 ++++++++++++++++++
 tools/testing/selftests/mm/protection_keys.c  |  10 -
 12 files changed, 581 insertions(+), 45 deletions(-)
 create mode 100644 tools/testing/selftests/mm/pkey_sighandler_tests.c


base-commit: a38297e3fb012ddfa7ce0321a7e5a8daeb1872b6
prerequisite-patch-id: d84439301b44c03df2555d3722ec512001ae52f2
-- 
2.39.3
Re: [PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE
Posted by Aruna Ramakrishna 1 year, 7 months ago

> On Jun 6, 2024, at 3:40 PM, Aruna Ramakrishna <aruna.ramakrishna@oracle.com> wrote:
> 
> v5 updates:
> - No major changes, mostly a resend of v4 - except for updating the
>  commit description for patch 5/5
> 
> v4 updates (based on review feedback from Thomas Gleixner):
> - Simplified update_pkru_in_sigframe()
> - Changed sigpkru to enable minimally required keys (init_pkru and
>  current
>  pkru)
> - Modified pkey_sighandler_tests.c to use kselfttest framework
> - Fixed commit descriptions
> - Fixed sigreturn use case (pointed out by Jeff Xu)
> - Added a new sigreturn test case
> 
> v3 updates (based on review feedback from Ingo Molnar and Dave Hansen):
> - Split the original patch into 3:
>        - function interface changes
>        - helper functions
>        - functional change to write pkru on sigframe
> - Enabled all pkeys before XSAVE - i.e. wrpkru(0), rather than assuming
> that the alt sig stack is always protected by pkey 0.
> - Added a few test cases in pkey_sighandler_tests.c.
> 
> I had some trouble adding these tests to
> tools/testing/selftests/mm/protection_keys.c, so they're in a separate
> file.
> 
> Aruna Ramakrishna (4):
>  x86/pkeys: Add PKRU as a parameter in signal handling functions
>  x86/pkeys: Add helper functions to update PKRU on sigframe
>  x86/pkeys: Update PKRU to enable minimally required pkeys before XSAVE
>  x86/pkeys: Restore altstack before sigcontext
> 
> Keith Lucas (1):
>  selftests/mm: Add new testcases for pkeys
> 
> arch/x86/include/asm/fpu/signal.h             |   2 +-
> arch/x86/include/asm/sighandling.h            |  10 +-
> arch/x86/kernel/fpu/signal.c                  |  27 +-
> arch/x86/kernel/fpu/xstate.c                  |  13 +
> arch/x86/kernel/fpu/xstate.h                  |   1 +
> arch/x86/kernel/signal.c                      |  42 +-
> arch/x86/kernel/signal_32.c                   |  12 +-
> arch/x86/kernel/signal_64.c                   |  14 +-
> tools/testing/selftests/mm/Makefile           |   5 +-
> tools/testing/selftests/mm/pkey-helpers.h     |  11 +-
> .../selftests/mm/pkey_sighandler_tests.c      | 479 ++++++++++++++++++
> tools/testing/selftests/mm/protection_keys.c  |  10 -
> 12 files changed, 581 insertions(+), 45 deletions(-)
> create mode 100644 tools/testing/selftests/mm/pkey_sighandler_tests.c
> 
> 
> base-commit: a38297e3fb012ddfa7ce0321a7e5a8daeb1872b6
> prerequisite-patch-id: d84439301b44c03df2555d3722ec512001ae52f2
> -- 
> 2.39.3
> 


Thomas/Ingo/Dave,

Could you please review this patch and give me your feedback? Jeff Xu has made a couple suggestions (the main one is about enabling all pkeys before XSAVE) and I was wondering if you had any suggestions/comments before I send out a v6.

Thanks very much for your time,
Aruna
Re: [PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE
Posted by Dave Hansen 1 year, 7 months ago
On 6/26/24 09:51, Aruna Ramakrishna wrote:
> Could you please review this patch and give me your feedback? Jeff Xu 
> has made a couple suggestions (the main one is about enabling all pkeys 
> before XSAVE) and I was wondering if you had any suggestions/comments 
> before I send out a v6.

Please just post a v6.
Re [PATCH v5 0/5] x86/pkeys: update PKRU to enable pkey 0 before XSAVE
Posted by jeffxu@chromium.org 1 year, 8 months ago
Hi

On Thu, Jun 06, 2024 at 10:40:30PM +0000, Aruna Ramakrishna wrote:
> v5 updates:
> - No major changes, mostly a resend of v4 - except for updating the
>   commit description for patch 5/5
> 
> v4 updates (based on review feedback from Thomas Gleixner):
> - Simplified update_pkru_in_sigframe()
> - Changed sigpkru to enable minimally required keys (init_pkru and
>   current
>   pkru)
> - Modified pkey_sighandler_tests.c to use kselfttest framework
> - Fixed commit descriptions
> - Fixed sigreturn use case (pointed out by Jeff Xu)
> - Added a new sigreturn test case
> 
> v3 updates (based on review feedback from Ingo Molnar and Dave Hansen):
> - Split the original patch into 3:
>         - function interface changes
>         - helper functions
>         - functional change to write pkru on sigframe
> - Enabled all pkeys before XSAVE - i.e. wrpkru(0), rather than assuming
> that the alt sig stack is always protected by pkey 0.
> - Added a few test cases in pkey_sighandler_tests.c.
> 
> I had some trouble adding these tests to
> tools/testing/selftests/mm/protection_keys.c, so they're in a separate
> file.
> 

Please add me to the future thread of this patch ! Thanks

I added a few more people to the email list. We've dealt with similar
situations in the past ([1] [2]), so it might be a good idea to
keep them updated. Also, ChromeOS and Chrome will use the functionality
provided by this patch series.

[1] https://lore.kernel.org/all/202208221331.71C50A6F@keescook/

[2] https://docs.google.com/document/d/1DjPhBq-5gRKtTeaknQDTWfvqRBCONmYqkU1I6k-3Ai8/edit?resourcekey=0-GGQta3_yhKqK7xV5SxIrVQ&tab=t.0

Thanks!
-Jeff