Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2538774yba; Mon, 6 May 2019 07:41:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqygcOvY8H62GuRGzMoLrSsQS5MaUNeduWHq2MkShjam7GfS6m/xhzVVyogGNfRvuMJrr3Sp X-Received: by 2002:a63:5907:: with SMTP id n7mr32635671pgb.416.1557153719557; Mon, 06 May 2019 07:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153719; cv=none; d=google.com; s=arc-20160816; b=qJTc9VupD/ZQa8JplJ2rqEXn1uzvFJvKs5EcTIZsumbeJOA7FbL5ZPlPEtcbD29Inw V4/UbdjU8/kn4dEJsxGuHEPFpXJyroVyxzcrkVMYm8tfzuMNng9pYc7GBMDokFYVVW0C 3F3wqk1bvgn7Q8yXP4OIjAHKPKhqZ3u3A1KGuwjlL1ga5OdrGOWziI0wsNYl7JPc4xJf ijwTnC16Ua8uQUiKxGx3LVvEYEslfayTaJmtr19985ur0Kzgep8vKjdWonb1n7pco9yi hs95lE7tOLWXBKR76a8m5W4TaCefq9/D/vI7cdGZgcTUlOm3hE8KGaXzgqXMuyx89wKB ki8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A/ViwPqPZ8XDerEqYzAjsabmolZiMLuXB4+r48a3+sk=; b=SwXXGxfztS+/+doylHp4N5i+o1jXKOCSyHuuGdf+cK0bO83Saj3DTrUKdqudf6p19l sD1rtAp3JSZRtfwODoWqYUabHT1xdiJ61cn0SQzigLdSw0k9mqe5x0arughgEIMPf+pV eki10WXCa1UnMHp5ShhuD675ife7SUOacnVsmSKOlDGljjhp0kFEAYr/1tu1oh/LPVeK zqWP3YY5XLpRmVWzRIf7zi4SlOoObm3RRTYjpEar0nVdNDY1qtfCp56geNireLkStHam ZXoCG7YejCMBAVbrDgw7SvTPUa5vYV8GoFkLcGOgtA4XsuEy9nuR31ZoFdB8MtFpdFA/ TjfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PRJOQFaF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s12si14715100plp.420.2019.05.06.07.41.44; Mon, 06 May 2019 07:41:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PRJOQFaF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727663AbfEFOim (ORCPT + 99 others); Mon, 6 May 2019 10:38:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:59890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbfEFOik (ORCPT ); Mon, 6 May 2019 10:38:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DEC7C214AE; Mon, 6 May 2019 14:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153519; bh=egkP3sJ+gY1BD2t3nH5Y9gV7Pntrz0MosAeGmt+n9bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRJOQFaFDsct95FYkpTOzcNEn4NuX5GF3TKjboh4souPl/43dqg/2yP0WaPdMoblh XQCWQud7TGKA1ke0HyxQRh77mdtrdHOU6pWiP7eUVYQh9CwvyUYnuTAN+PJ4Sy7zEj kMt1Ui42sELmgY1PlDUfu0xGW5lsKimhrDwoL9I0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Borislav Petkov , Catalin Marinas , Andy Lutomirski , Brijesh Singh , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , x86-ml Subject: [PATCH 5.0 119/122] x86/mm: Fix a crash with kmemleak_scan() Date: Mon, 6 May 2019 16:32:57 +0200 Message-Id: <20190506143105.074769856@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qian Cai commit 0d02113b31b2017dd349ec9df2314e798a90fa6e upstream. The first kmemleak_scan() call after boot would trigger the crash below because this callpath: kernel_init free_initmem mem_encrypt_free_decrypted_mem free_init_pages unmaps memory inside the .bss when DEBUG_PAGEALLOC=y. kmemleak_init() will register the .data/.bss sections and then kmemleak_scan() will scan those addresses and dereference them looking for pointer references. If free_init_pages() frees and unmaps pages in those sections, kmemleak_scan() will crash if referencing one of those addresses: 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 Call Trace: scan_gray_list kmemleak_scan kmemleak_scan_thread kthread ret_from_fork Since kmemleak_free_part() is tolerant to unknown objects (not tracked by kmemleak), it is fine to call it from free_init_pages() even if not all address ranges passed to this function are known to kmemleak. [ bp: Massage. ] Fixes: b3f0907c71e0 ("x86/mm: Add .bss..decrypted section to hold shared variables") Signed-off-by: Qian Cai Signed-off-by: Borislav Petkov Reviewed-by: Catalin Marinas Cc: Andy Lutomirski Cc: Brijesh Singh Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/20190423165811.36699-1-cai@lca.pw Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/init.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -766,6 +767,11 @@ void free_init_pages(const char *what, u if (debug_pagealloc_enabled()) { pr_info("debug: unmapping init [mem %#010lx-%#010lx]\n", begin, end - 1); + /* + * Inform kmemleak about the hole in the memory since the + * corresponding pages will be unmapped. + */ + kmemleak_free_part((void *)begin, end - begin); set_memory_np(begin, (end - begin) >> PAGE_SHIFT); } else { /*