Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2492033ybg; Sun, 27 Oct 2019 19:55:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKEX9yE3o91IZr/wJMwK1Z1zYnxrpsNkhZiaU/6+tsLBnAYLxMagoMWLphhtz11jPMasUg X-Received: by 2002:a50:e445:: with SMTP id e5mr17036870edm.257.1572231359253; Sun, 27 Oct 2019 19:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572231359; cv=none; d=google.com; s=arc-20160816; b=BU6JwdwryOB7YYG/0oT274Pdm3oAWqkzBarOfGAZLId2VwQ69Q1zUQe3/+iMEqOy2Y TM+xOERwip/wAg7xkkO9iAdbr4NuALE7w0fFhRGwRbN36UGHzozSTSqzmekBv0Ltv6Xf 03FI4Vx9WZpya09l/HAzbPeKjW7tNTH5+1l8P8HZO3ucyixmpRQiy1wLHiik5h6qQoSD ikHCTYsDYJl7GlRoq0XMY/xxpPLhns6bDWhQzrlrTOQr0X5ywmfId4Y9uIniOPjFoxwP hc/NgLaVmb27Ps8kk5+ZHg1/IEfXvYXKobMmoFCgFoK93uleHVNxvipy6CcQL4AsQVV2 a/RA== 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=VDnhJG6rEa5UeqUKUYh7Juk0Jm57tWje0kK0CcfS6Wk=; b=ykZ1APKYAEkrEWaZQ3eFJK81Aqt8bEjFJbSSQ42PwQuwp7zgcXa87v84vrARKiXSXV 8Z/Icc6VpC6pHPgFPP2ejVxRFkcFVlptAOLLqFR9ZtuuVkf/Ow8r6MS2RDWmZNiDYamC eQpN40CYDFeQUAsMaU+iKF2OjUzX2QQO7TuGZvXD9aPuRMEpFeLTm9ME+CCHRvFTEjd+ 3ET+Fthnciv2pWrLfqs19J93WfbBe0pQ+odN8sXnrl56CeKnkFJh3QKL5O+5zmeICU0M 41fweYT/kxIn0fIiVVpP6L1eZQyYIrBuey2XeE+zGJ6aY+6o2R89GyGiEjWwsIdhstvK Kutw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MsDZHRFH; 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 x25si5511585eju.357.2019.10.27.19.55.34; Sun, 27 Oct 2019 19:55: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=MsDZHRFH; 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 S1728555AbfJ0VMJ (ORCPT + 99 others); Sun, 27 Oct 2019 17:12:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:58802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbfJ0VMH (ORCPT ); Sun, 27 Oct 2019 17:12:07 -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 23A3520873; Sun, 27 Oct 2019 21:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572210726; bh=CgIvwC7qTH85RQI6kmwZ38ooNUQA/hoQ21zTCtaVeX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MsDZHRFHUm73x1S691R497Ah0r97gqiZ/B/ZxR/1dTptbhuAtOpS8ok1Tsgz4pPP8 /guJmSJA3kF32ocr8JGo7LudpSeGAxmoyDxemFokeDj03083w1ifvknaFcr5iX8rnh ezB3HKMWBj7gGndrsVqm5txwIR1SEkSDb417Ub7Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Naoya Horiguchi , Michal Hocko , "Rafael J. Wysocki" , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 098/119] drivers/base/memory.c: dont access uninitialized memmaps in soft_offline_page_store() Date: Sun, 27 Oct 2019 22:01:15 +0100 Message-Id: <20191027203348.834120266@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203259.948006506@linuxfoundation.org> References: <20191027203259.948006506@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: David Hildenbrand commit 641fe2e9387a36f9ee01d7c69382d1fe147a5e98 upstream. Uninitialized memmaps contain garbage and in the worst case trigger kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get touched. Right now, when trying to soft-offline a PFN that resides on a memory block that was never onlined, one gets a misleading error with CONFIG_PAGE_POISONING: :/# echo 5637144576 > /sys/devices/system/memory/soft_offline_page [ 23.097167] soft offline: 0x150000 page already poisoned But the actual result depends on the garbage in the memmap. soft_offline_page() can only work with online pages, it returns -EIO in case of ZONE_DEVICE. Make sure to only forward pages that are online (iow, managed by the buddy) and, therefore, have an initialized memmap. Add a check against pfn_to_online_page() and similarly return -EIO. Link: http://lkml.kernel.org/r/20191010141200.8985-1-david@redhat.com Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") [visible after d0dc12e86b319] Signed-off-by: David Hildenbrand Acked-by: Naoya Horiguchi Acked-by: Michal Hocko Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: [4.13+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -552,6 +552,9 @@ store_soft_offline_page(struct device *d pfn >>= PAGE_SHIFT; if (!pfn_valid(pfn)) return -ENXIO; + /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ + if (!pfn_to_online_page(pfn)) + return -EIO; ret = soft_offline_page(pfn_to_page(pfn), 0); return ret == 0 ? count : ret; }