Skip to content

Commit

Permalink
x86/pkeys: Skip 'init_pkru' debugfs file creation when pkeys not supp…
Browse files Browse the repository at this point in the history
…orted

The PKRU hardware is permissive by default: all reads and writes are
allowed.  The in-kernel policy is restrictive by default: deny all
unnecessary access until explicitly requested.

That policy can be modified with a debugfs file: "x86/init_pkru".
This file is created unconditionally, regardless of PKRU support in
the hardware, which is a little silly.

Avoid creating the file when pkeys are not available.  This also
removes the need to check for pkey support at runtime, which would be
required once the new pkey modification infrastructure is put in place
later in this series.

Signed-off-by: Dave Hansen <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
hansendc authored and suryasaimadhu committed Jun 4, 2021
1 parent 8124c8a commit 314a1e1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arch/x86/mm/pkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ static const struct file_operations fops_init_pkru = {

static int __init create_init_pkru_value(void)
{
/* Do not expose the file if pkeys are not supported. */
if (!cpu_feature_enabled(X86_FEATURE_OSPKE))
return 0;

debugfs_create_file("init_pkru", S_IRUSR | S_IWUSR,
arch_debugfs_dir, NULL, &fops_init_pkru);
return 0;
Expand Down

0 comments on commit 314a1e1

Please sign in to comment.