Re: [PATCH 6/7] lkdtm: crash on overwriting protected pmalloc var

From: J Freyensee
Date: Tue Mar 06 2018 - 12:09:00 EST




On 3/6/18 9:05 AM, J Freyensee wrote:

 +#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;


Opps, disregard this, this is the last series of this patch series, not the most recent one :-(.



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>