diff mbox series

[3/5] x86/pkeys: skip 'init_pkru' debugfs file creation when pkeys not supported

Message ID 20210527235116.E5A35872@viggo.jf.intel.com (mailing list archive)
State New, archived
Headers show
Series x86/pkeys: PKRU manipulation bug fixes and cleanups | expand

Commit Message

Dave Hansen May 27, 2021, 11:51 p.m. UTC
From: Dave Hansen <dave.hansen@linux.intel.com>

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 <dave.hansen@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Babu Moger <babu.moger@amd.com>
Cc: Dave Kleikamp <dave.kleikamp@oracle.com>
Cc: Ram Pai <linuxram@us.ibm.com>
Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---

 b/arch/x86/mm/pkeys.c |    4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff -puN arch/x86/mm/pkeys.c~x86-pkeys-skip-debugfs-file arch/x86/mm/pkeys.c
--- a/arch/x86/mm/pkeys.c~x86-pkeys-skip-debugfs-file	2021-05-27 16:40:25.847705465 -0700
+++ b/arch/x86/mm/pkeys.c	2021-05-27 16:40:25.852705465 -0700
@@ -193,6 +193,10 @@  static const struct file_operations fops
 
 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;