Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2785424ybg; Mon, 28 Oct 2019 02:19:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbI/rSD5DvBUdEf8wb76dFY6jJnRjf6qkIe2lEg2kIc4jnp1PvLKNHnYk1RU/n9lHjeP2I X-Received: by 2002:aa7:c757:: with SMTP id c23mr6324326eds.209.1572254363473; Mon, 28 Oct 2019 02:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572254363; cv=none; d=google.com; s=arc-20160816; b=rGEW5pGfVnreWEzIglB2b7yJBjqdttUnm9A3y6e/8BWQ7oYUcvWBhZRa0NxVkH6l8t r4p3bAJWpjGeaQA/sSqWPjRU3XB7+2U1xGnnwkK8BHcun5HhO5xKjy+fSBtXHVmupclu Yw+u3wUJK9JFdfHpVJOYK/Txb79lv21N72PBUrLADArQWPDAjcaA3fDuBzDc1SYrwrmL sDG45+2tuI+SPUdz6m4AkQFVPjUcitS+GgqMGPVM8yZEcWU71HG/vCHgSfI8ruAjHU/s l7TA66FNOFkibw3zQkmBwIDYkTgdp//34UuYOGfIQDB63DEHX3uFZFHrQy/PRsa4aPi8 AZGw== 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=w7SFkz12XAZH+wYoHZSzRFQ6rKjsGuZIiusKfhKl6pQ=; b=WSs4HO1HJKf/WGIUeT7X9dS2TGPnGuizwNqtNd+1pVu0jaiJ1Tw4yfxWVMdmt1gbMN ybVeI7Xfb7cTFU9T59ebxMtV1C9d1Vif9GRX+KTEazVo/9hCcug/1U7dMZdxAnfpw+57 XRodWndABZYImy+xDWkD51BDAWf5rb4kmGp8iy07adtT73mGvQLaj3H/5sbV9WBxl/jS Y4RHuq4KbFAuANnE9sfKLWbAAMLF4Cz3A/Pg315p5f1OUmx9pj5br0q+Hqj0QPT6ck5o RbLlr+3DDGEkkLJchv6fGb1cA8MQAu3QI1EjzUZscyY8pxcTJDIwU1dX8HluIZTH7Phe 6MqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i3TDF5Ux; 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 p9si7020430edc.96.2019.10.28.02.19.00; Mon, 28 Oct 2019 02:19:23 -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=i3TDF5Ux; 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 S1732382AbfJ0VXn (ORCPT + 99 others); Sun, 27 Oct 2019 17:23:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:44884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732375AbfJ0VXk (ORCPT ); Sun, 27 Oct 2019 17:23:40 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (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 C757C20717; Sun, 27 Oct 2019 21:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211419; bh=bm6SBd9KSkotabOnfPkgf/B5SunoLXDIwjWNJjcpgZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i3TDF5UxQPTSFBgiuW6tU09qnj8OLlSnGjkoMYZZqDDM+Vv9+Br1Qaxg39CYSjC1v QloO/Wc1S2bkt1Z9ExMFJxl8O/sbNGbuQCS1vklwTHmAKZLuVpuHf1hOHJTlLySdQp yZ5BhNKBM76NQtieTeKEc+MYTT8B551CvVW5yp+8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , David Hildenbrand , Michal Hocko , Vlastimil Babka , Thomas Gleixner , "Peter Zijlstra (Intel)" , Miles Chen , Mike Rapoport , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 146/197] mm/page_owner: dont access uninitialized memmaps when reading /proc/pagetypeinfo Date: Sun, 27 Oct 2019 22:01:04 +0100 Message-Id: <20191027203359.574805998@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@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 a26ee565b6cd8dc2bf15ff6aa70bbb28f928b773 upstream. Uninitialized memmaps contain garbage and in the worst case trigger kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get touched. For example, when not onlining a memory block that is spanned by a zone and reading /proc/pagetypeinfo with CONFIG_DEBUG_VM_PGFLAGS and CONFIG_PAGE_POISONING, we can trigger a kernel BUG: :/# echo 1 > /sys/devices/system/memory/memory40/online :/# echo 1 > /sys/devices/system/memory/memory42/online :/# cat /proc/pagetypeinfo > test.file page:fffff2c585200000 is uninitialized and poisoned raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) There is not page extension available. ------------[ cut here ]------------ kernel BUG at include/linux/mm.h:1107! invalid opcode: 0000 [#1] SMP NOPTI Please note that this change does not affect ZONE_DEVICE, because pagetypeinfo_showmixedcount_print() is called from mm/vmstat.c:pagetypeinfo_showmixedcount() only for populated zones, and ZONE_DEVICE is never populated (zone->present_pages always 0). [david@redhat.com: move check to outer loop, add comment, rephrase description] Link: http://lkml.kernel.org/r/20191011140638.8160-1-david@redhat.com Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319 Signed-off-by: Qian Cai Signed-off-by: David Hildenbrand Acked-by: Michal Hocko Acked-by: Vlastimil Babka Cc: Thomas Gleixner Cc: "Peter Zijlstra (Intel)" Cc: Miles Chen Cc: Mike Rapoport Cc: Qian Cai Cc: Greg Kroah-Hartman Cc: [4.13+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_owner.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -258,7 +258,8 @@ void pagetypeinfo_showmixedcount_print(s * not matter as the mixed block count will still be correct */ for (; pfn < end_pfn; ) { - if (!pfn_valid(pfn)) { + page = pfn_to_online_page(pfn); + if (!page) { pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES); continue; } @@ -266,13 +267,13 @@ void pagetypeinfo_showmixedcount_print(s block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages); block_end_pfn = min(block_end_pfn, end_pfn); - page = pfn_to_page(pfn); pageblock_mt = get_pageblock_migratetype(page); for (; pfn < block_end_pfn; pfn++) { if (!pfn_valid_within(pfn)) continue; + /* The pageblock is online, no need to recheck. */ page = pfn_to_page(pfn); if (page_zone(page) != zone)