Re: [PATCH v2 4/4] mm: Add debug code for SANITIZE_FREED_PAGES

From: PaX Team
Date: Mon May 04 2015 - 17:52:32 EST


On 4 May 2015 at 23:16, Anisse Astier wrote:

> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index c29e3a0..ba8aa25 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -975,6 +975,31 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags,
> for (i = 0; i < (1 << order); i++)
> clear_highpage(page + i);
> #endif
> +#ifdef CONFIG_SANITIZE_FREED_PAGES_DEBUG
> + for (i = 0; i < (1 << order); i++) {
> + struct page *p = page + i;
> + int j;
> + bool err = false;
> + void *kaddr = kmap_atomic(p);
> +
> + for (j = 0; j < PAGE_SIZE; j++) {

did you mean to use memchr_inv(kaddr, 0, PAGE_SIZE) instead? ;)

> + if (((char *)kaddr)[j] != 0) {
> + pr_err("page %p is not zero on alloc! %s\n",
> + page_address(p), (gfp_flags &
> + __GFP_ZERO) ?
> + "fixing." : "");
> + if (gfp_flags & __GFP_ZERO) {
> + err = true;
> + kunmap_atomic(kaddr);
> + clear_highpage(p);
> + }
> + break;
> + }
> + }
> + if (!err)
> + kunmap_atomic(kaddr);
> + }
> +#endif
>
> if (order && (gfp_flags & __GFP_COMP))
> prep_compound_page(page, order);
> --
> 1.9.3
>
>



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/