@@ -328,3 +328,43 @@ void pks_key_free(int pkey)
mutex_unlock(&pks_lock);
}
EXPORT_SYMBOL_GPL(pks_key_free);
+
+static int pks_keys_allocated_show(struct seq_file *m, void *p)
+{
+ int i;
+
+ mutex_lock(&pks_lock);
+ for (i = PKS_KERN_DEFAULT_KEY; i < PKS_NUM_KEYS; i++) {
+ /* It is ok for pks_key_users[i] to be NULL */
+ if (test_bit(i, &pks_key_allocation_map))
+ seq_printf(m, "%d: %s\n", i, pks_key_users[i]);
+ }
+ mutex_unlock(&pks_lock);
+
+ return 0;
+}
+
+static int pks_keys_allocated_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, pks_keys_allocated_show, NULL);
+}
+
+static const struct file_operations pks_keys_allocated_fops = {
+ .open = pks_keys_allocated_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static int __init pks_keys_initcall(void)
+{
+ if (cpu_feature_enabled(X86_FEATURE_PKS)) {
+ /* Create a debugfs file to show allocated PKS keys. */
+ debugfs_create_file("pks_keys_allocated", 0400,
+ arch_debugfs_dir, NULL,
+ &pks_keys_allocated_fops);
+ }
+
+ return 0;
+}
+late_initcall(pks_keys_initcall);