[PATCH v3 3/4] powerpc/mm/ptdump: debugfs handler for W+X checks at runtime
Russell Currey
ruscur at russell.cc
Fri Oct 4 17:50:49 AEST 2019
Very rudimentary, just
echo 1 > [debugfs]/check_wx_pages
and check the kernel log. Useful for testing strict module RWX.
Also fixed a typo.
Signed-off-by: Russell Currey <ruscur at russell.cc>
---
arch/powerpc/mm/ptdump/ptdump.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c
index 2f9ddc29c535..0547cd9f264e 100644
--- a/arch/powerpc/mm/ptdump/ptdump.c
+++ b/arch/powerpc/mm/ptdump/ptdump.c
@@ -4,7 +4,7 @@
*
* This traverses the kernel pagetables and dumps the
* information about the used sections of memory to
- * /sys/kernel/debug/kernel_pagetables.
+ * /sys/kernel/debug/kernel_page_tables.
*
* Derived from the arm64 implementation:
* Copyright (c) 2014, The Linux Foundation, Laura Abbott.
@@ -409,16 +409,35 @@ void ptdump_check_wx(void)
else
pr_info("Checked W+X mappings: passed, no W+X pages found\n");
}
+
+static int check_wx_debugfs_set(void *data, u64 val)
+{
+ if (val != 1ULL)
+ return -EINVAL;
+
+ ptdump_check_wx();
+
+ return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(check_wx_fops, NULL, check_wx_debugfs_set, "%llu\n");
#endif
static int ptdump_init(void)
{
- struct dentry *debugfs_file;
-
populate_markers();
build_pgtable_complete_mask();
- debugfs_file = debugfs_create_file("kernel_page_tables", 0400, NULL,
- NULL, &ptdump_fops);
- return debugfs_file ? 0 : -ENOMEM;
+
+ if (!debugfs_create_file("kernel_page_tables", 0400, NULL,
+ NULL, &ptdump_fops))
+ return -ENOMEM;
+
+#ifdef CONFIG_PPC_DEBUG_WX
+ if (!debugfs_create_file("check_wx_pages", 0200, NULL,
+ NULL, &check_wx_fops))
+ return -ENOMEM;
+#endif
+
+ return 0;
}
device_initcall(ptdump_init);
--
2.23.0
More information about the Linuxppc-dev
mailing list