Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp448681ybl; Tue, 28 Jan 2020 06:09:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxrojQQOrNMhc3pmaKaX8lgEapVCH4NKfLAFXgPVrmddU61G7Dph0Uo1zE9w8jdB3xhO341 X-Received: by 2002:a05:6830:16d8:: with SMTP id l24mr16721899otr.268.1580220591319; Tue, 28 Jan 2020 06:09:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580220591; cv=none; d=google.com; s=arc-20160816; b=iJcEYOuyZrVJ/MBioVfuvLOPAEtTCyekXgK2ZcyFhMudIe3Thl177eMxCfJF4ZlL7B 2wm7PtHNROUFjB8avZf2TJ9vqsXuGDU0yzniLD0DsPFrHiONOBk70z0dYZsttbr9d8zS 0UaO+1Xf4H0cboQS26TmZoSCtELbWqbLWYW6Cf69y3llurtNX5+/Kp1Qgeyvf/7jPV3C 0CAWnOFV90LnW0Z4fwimQytlrXlVtr/KfZThWjq/DpAX727ICI5xKQ/yaJ9Jh0WTzUgR mjEh9bfmLLHcJIbBkw+hvzfVijASZkmwDlGbUASPWoMI+sXCxofbFTgIo6c8UCDcOHry 5P+g== 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=/nyqiw1DzYvx3p6xRRzrHGMAK/I+u6zwvyELKB/bwPc=; b=Ap6OtputpFQZq7Pqooeq08+zHJ0Yduw4+5RgK8XhwVJVGbLnxeuATj/sAu+bo4nAZI SyN8RKNg9uHW6Ci5u3Iqp3SUwXD4WAnBdFuWiXI2vw7HsUE9HYsXHJclGfMipUne5Sk2 b4AjXohFmK9Ibdi93EmzMJyqQIO13rg1lNhDPX8p86hG5SNIxrZcTy6WE5RLxeUnSL/d 98eR0Az9QRRK+EV2GMAWJl7MukM5j5NYQTOvttmz6eF7j0g5dzhNrV3lI/IZAVXa/vmW XVSIqqBNZ2H+n8ozKljeqNmR6kW9LtenEhc1s5Qo/cQwZqD2cch51I6rhDmUcvNHirMI P0Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rlNw7l5h; 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 h203si5305480oif.3.2020.01.28.06.09.22; Tue, 28 Jan 2020 06:09:51 -0800 (PST) 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=rlNw7l5h; 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 S1727972AbgA1OD7 (ORCPT + 99 others); Tue, 28 Jan 2020 09:03:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:50712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727942AbgA1ODu (ORCPT ); Tue, 28 Jan 2020 09:03:50 -0500 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 347D624683; Tue, 28 Jan 2020 14:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580220229; bh=gTKXZqGSWTCaq/2mjRbkSq8dGOn8KG/W2Ti1fQPskK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rlNw7l5hjOPp3t8xT6uTo7jgzjHSk3P41QtL8fwPVWSUiKA8K2CszvH3AQl4I+k4k /q+Mx+Fm9yPc+lq1Wo4uv3+gg9Yh1Lep9tkntFvHJdMMZoiIuLKrujhGuGe9YpU39d Fr8b6axcSgKVw/nx+Fa6LCKtYU+yjEyXjQW6Gi88= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Stezenbach , Alexander Potapenko , "Rafael J. Wysocki" Subject: [PATCH 5.4 041/104] PM: hibernate: fix crashes with init_on_free=1 Date: Tue, 28 Jan 2020 15:00:02 +0100 Message-Id: <20200128135823.321759348@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135817.238524998@linuxfoundation.org> References: <20200128135817.238524998@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: Alexander Potapenko commit 18451f9f9e5810b8bd1245c5ae166f257e0e2b9d upstream. Upon resuming from hibernation, free pages may contain stale data from the kernel that initiated the resume. This breaks the invariant inflicted by init_on_free=1 that freed pages must be zeroed. To deal with this problem, make clear_free_pages() also clear the free pages when init_on_free is enabled. Fixes: 6471384af2a6 ("mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options") Reported-by: Johannes Stezenbach Signed-off-by: Alexander Potapenko Cc: 5.3+ # 5.3+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- kernel/power/snapshot.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1147,24 +1147,24 @@ void free_basic_memory_bitmaps(void) void clear_free_pages(void) { -#ifdef CONFIG_PAGE_POISONING_ZERO struct memory_bitmap *bm = free_pages_map; unsigned long pfn; if (WARN_ON(!(free_pages_map))) return; - memory_bm_position_reset(bm); - pfn = memory_bm_next_pfn(bm); - while (pfn != BM_END_OF_MAP) { - if (pfn_valid(pfn)) - clear_highpage(pfn_to_page(pfn)); - + if (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) || want_init_on_free()) { + memory_bm_position_reset(bm); pfn = memory_bm_next_pfn(bm); + while (pfn != BM_END_OF_MAP) { + if (pfn_valid(pfn)) + clear_highpage(pfn_to_page(pfn)); + + pfn = memory_bm_next_pfn(bm); + } + memory_bm_position_reset(bm); + pr_info("free pages cleared after restore\n"); } - memory_bm_position_reset(bm); - pr_info("free pages cleared after restore\n"); -#endif /* PAGE_POISONING_ZERO */ } /**