Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 250a8988 authored by Laura Abbott's avatar Laura Abbott Committed by Kees Cook
Browse files

lkdtm: Update WRITE_AFTER_FREE test



The SLUB allocator may use the first word of a freed block to store the
freelist information. This may make it harder to test poisoning
features. Change the WRITE_AFTER_FREE test to better match what
the READ_AFTER_FREE test does and also print out a big more information.

Signed-off-by: default avatarLaura Abbott <labbott@fedoraproject.org>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent bc0b8cc6
Loading
Loading
Loading
Loading
+13 −4
Original line number Original line Diff line number Diff line
@@ -411,12 +411,21 @@ static void lkdtm_do_action(enum ctype which)
		break;
		break;
	}
	}
	case CT_WRITE_AFTER_FREE: {
	case CT_WRITE_AFTER_FREE: {
		int *base;
		size_t len = 1024;
		size_t len = 1024;
		u32 *data = kmalloc(len, GFP_KERNEL);
		/*
		 * The slub allocator uses the first word to store the free
		 * pointer in some configurations. Use the middle of the
		 * allocation to avoid running into the freelist
		 */
		size_t offset = (len / sizeof(*base)) / 2;


		kfree(data);
		base = kmalloc(len, GFP_KERNEL);
		schedule();
		pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]);
		memset(data, 0x78, len);
		kfree(base);
		pr_info("Attempting bad write to freed memory at %p\n",
			&base[offset]);
		base[offset] = 0x0abcdef0;
		break;
		break;
	}
	}
	case CT_READ_AFTER_FREE: {
	case CT_READ_AFTER_FREE: {