+#ifdef CONFIG_PROTECTABLE_MEMORY
+void lkdtm_WRITE_RO_PMALLOC(void)
+{
+ÂÂÂ struct gen_pool *pool;
+ÂÂÂ int *i;
+
+ÂÂÂ pool = pmalloc_create_pool("pool", 0);
+ÂÂÂ if (unlikely(!pool)) {
+ÂÂÂÂÂÂÂ pr_info("Failed preparing pool for pmalloc test.");
+ÂÂÂÂÂÂÂ return;
+ÂÂÂ }
+
+ÂÂÂ i = (int *)pmalloc(pool, sizeof(int), GFP_KERNEL);
+ÂÂÂ if (unlikely(!i)) {
+ÂÂÂÂÂÂÂ pr_info("Failed allocating memory for pmalloc test.");
+ÂÂÂÂÂÂÂ pmalloc_destroy_pool(pool);
+ÂÂÂÂÂÂÂ return;
+ÂÂÂ }
+
+ÂÂÂ *i = INT_MAX;
+ÂÂÂ pmalloc_protect_pool(pool);
+
+ÂÂÂ pr_info("attempting bad pmalloc write at %p\n", i);
+ÂÂÂ *i = 0;
Seems harmless, but I don't get why *i local variable needs to be set to 0 at the end of this function.
Otherwise,
Reviewed-by: Jay Freyensee <why2jjj.linux@xxxxxxxxx>