lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190416171104.GI31772@zn.tnic>
Date:   Tue, 16 Apr 2019 19:11:04 +0200
From:   Borislav Petkov <bp@...en8.de>
To:     Qian Cai <cai@....pw>
Cc:     dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
        catalin.marinas@....com, tglx@...utronix.de, mingo@...hat.com,
        x86@...nel.org, linux-kernel@...r.kernel.org,
        Brijesh Singh <brijesh.singh@....com>
Subject: Re: [PATCH] x86/mm/mem_encrypt: fix a crash with kmemleak_scan

+ Brijesh.

On Tue, Apr 09, 2019 at 12:05:02AM -0400, Qian Cai wrote:
> The first kmemleak_scan() after boot would trigger a crash below because
> 
> kernel_init
>   free_initmem
>     mem_encrypt_free_decrypted_mem
>       free_init_pages
> 
> unmapped some memory inside the .bss.
> 
> BUG: unable to handle kernel paging request at ffffffffbd402000
> CPU: 12 PID: 325 Comm: kmemleak Not tainted 5.1.0-rc4+ #4
> RIP: 0010:scan_block+0x58/0x160
> Call Trace:
>  scan_gray_list+0x1d9/0x280
>  kmemleak_scan+0x485/0xad0
>  kmemleak_scan_thread+0x9f/0xc4
>  kthread+0x1d2/0x1f0
>  ret_from_fork+0x35/0x40
> 
> Signed-off-by: Qian Cai <cai@....pw>
> ---
>  arch/x86/mm/mem_encrypt.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c
> index 385afa2b9e17..614ab156024f 100644
> --- a/arch/x86/mm/mem_encrypt.c
> +++ b/arch/x86/mm/mem_encrypt.c
> @@ -18,6 +18,7 @@
>  #include <linux/dma-direct.h>
>  #include <linux/swiotlb.h>
>  #include <linux/mem_encrypt.h>
> +#include <linux/kmemleak.h>
>  
>  #include <asm/tlbflush.h>
>  #include <asm/fixmap.h>
> @@ -369,6 +370,11 @@ void __init mem_encrypt_free_decrypted_mem(void)
>  		}
>  	}
>  
> +	/*
> +	 * Inform kmemleak about the hole in the .bss section since the
> +	 * corresponding pages will be unmapped with DEBUG_PAGEALLOC=y.
> +	 */
> +	kmemleak_free_part((void *)vaddr, vaddr_end - vaddr);
>  	free_init_pages("unused decrypted", vaddr, vaddr_end);

I don't understand what the logic here is: we have a couple of other
free_init_pages() calls but they don't have kmemleak_free_part() in
front.

Now, if kmemleak needs to be told that memory is getting freed, why
isn't kmemleak_free_part() called in free_init_pages() ?

This needs more explanation.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ