Skip to content

Commit 314a1e1

Browse files
hansendcsuryasaimadhu
authored andcommitted
x86/pkeys: Skip 'init_pkru' debugfs file creation when pkeys not supported
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]
1 parent 8124c8a commit 314a1e1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/x86/mm/pkeys.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ static const struct file_operations fops_init_pkru = {
192192

193193
static int __init create_init_pkru_value(void)
194194
{
195+
/* Do not expose the file if pkeys are not supported. */
196+
if (!cpu_feature_enabled(X86_FEATURE_OSPKE))
197+
return 0;
198+
195199
debugfs_create_file("init_pkru", S_IRUSR | S_IWUSR,
196200
arch_debugfs_dir, NULL, &fops_init_pkru);
197201
return 0;

0 commit comments

Comments
 (0)