lkml.org 
[lkml]   [2020]   [Jul]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC PATCH 06/15] x86/pks: Add a debugfs file for allocated PKS keys
    Date
    From: Fenghua Yu <fenghua.yu@intel.com>

    The sysadmin may need to know which PKS keys are currently being used.

    Add a debugfs file to show the allocated PKS keys and their names.

    Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
    ---
    arch/x86/mm/pkeys.c | 40 ++++++++++++++++++++++++++++++++++++++++
    1 file changed, 40 insertions(+)

    diff --git a/arch/x86/mm/pkeys.c b/arch/x86/mm/pkeys.c
    index 16f735c12fcd..e565fadd74d7 100644
    --- a/arch/x86/mm/pkeys.c
    +++ b/arch/x86/mm/pkeys.c
    @@ -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);
    --
    2.25.1
    \
     
     \ /
      Last update: 2020-07-14 09:06    [W:2.943 / U:0.076 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site