Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1374713ybn; Wed, 2 Oct 2019 15:16:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHu3MEvlamrZhbKStYRi+kw025fG3fTPNyGQw/u6+vin9VNQ+apXTTr8oYBuFLXMDYtGBw X-Received: by 2002:a50:f703:: with SMTP id g3mr6320644edn.43.1570054573781; Wed, 02 Oct 2019 15:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570054573; cv=none; d=google.com; s=arc-20160816; b=Mihb1J3FtRL5tUckN35zzSH7b5KVF639eYPBNi4HGXLkCXOmssQ5T2v5FNP2/ohcKV ugx7qGIO1ExKPjQgLgeE8iEjpFBMijuB5VLaHYhPcGyZbQNIV73XjuMNq5OtnGhELQoB qH8SN1PKZleO0a1LKghO5wclSxAa9TOkyzYP4MFCcgw/ojPuY0W77adLJIMsuilF17k/ qetv6PbYh99b344ZYIED2dEDH1JUCNdbb8DuL7opxL6gUGVSe9uIjYRUgwVar/R1VxUl nNz6Dv4svMG1ktX5EKVns5de6qHHFNvl78AYTp6VvIr2Q8BWtjhG1G9Q71046Rw3+su6 GfkA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=U3p6Wnm06IS4tTotjbedD0In5O3ZzpgFIlKxDoCAE78=; b=vI0UZW41Pq4+h2pP7TPAPWkcCWjsfylnGQHwKIZpc/sWOUlpwPm0ElX9NpfZfW6np/ adlfwyreGnhPJcZme2DTObhDZRCZw4KsSzTn5CqDiWGm1yUrPsx8LxkgZNMMraiuR24O DQnVbyeCznvlx8645+kxj946xKy4IZW/Ei5TfGKVmYrs3JB4JE9TYSsCTP3rJKk9inUg bkM6OxjTSgaqnR7CnJpiodGa64EX7s/8XWvVVgv5j7y1L8D4Gd1Y/kNNckTuRv58zx43 f6gumGb24eh+hPM9+ogWoT9F4DriJjVes9+/RmrkyvVUT3vVbnP27CXBPXDuRHSPu8x7 sz2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x3yRh+ed; 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 g11si236591ejj.11.2019.10.02.15.15.49; Wed, 02 Oct 2019 15:16:13 -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=x3yRh+ed; 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 S1727708AbfJBWOR (ORCPT + 99 others); Wed, 2 Oct 2019 18:14:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:52250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbfJBWOR (ORCPT ); Wed, 2 Oct 2019 18:14:17 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) (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 8175420659; Wed, 2 Oct 2019 22:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570054456; bh=kSN1Gyplw7RqXqxsJcmCMVoXdvIiOoy3KBYxUcNcQIg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=x3yRh+edFLTiTWrF/ExG8Ko/QBaRLNy2Q78XMIQfuf6mhooPQrPb7sYKoQRHgbNvu 9fYeX4S4q9iMk3zKcAxMIMoyk5ceWMnVLy3jTGcCBTJOFlQT42tw4CGWjwHqIEHpBc 6dwdmTJOkAs3aZYsITxs4nCguavz6OHjVwpJHYF8= Date: Wed, 2 Oct 2019 15:14:16 -0700 From: Andrew Morton To: David Hildenbrand Cc: "Alastair D'Silva" , alastair@d-silva.org, Oscar Salvador , Michal Hocko , Pavel Tatashin , Dan Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 1/1] memory_hotplug: Add a bounds check to __add_pages Message-Id: <20191002151416.42bc2e8228fdefc6eb802abc@linux-foundation.org> In-Reply-To: <01def17b-1df8-a63a-4cfc-91e99614a2f0@redhat.com> References: <20191001004617.7536-1-alastair@au1.ibm.com> <20191001004617.7536-2-alastair@au1.ibm.com> <01def17b-1df8-a63a-4cfc-91e99614a2f0@redhat.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Oct 2019 11:49:47 +0200 David Hildenbrand wrote: > > @@ -278,6 +278,22 @@ static int check_pfn_span(unsigned long pfn, unsigned long nr_pages, > > return 0; > > } > > > > +static int check_hotplug_memory_addressable(unsigned long pfn, > > + unsigned long nr_pages) > > +{ > > + const u64 max_addr = PFN_PHYS(pfn + nr_pages) - 1; > > + > > + if (max_addr >> MAX_PHYSMEM_BITS) { > > + const u64 max_allowed = (1ull << (MAX_PHYSMEM_BITS + 1)) - 1; > > + WARN(1, > > + "Hotplugged memory exceeds maximum addressable address, range=%#llx-%#llx, maximum=%#llx\n", > > + (u64)PFN_PHYS(pfn), max_addr, max_allowed); > > + return -E2BIG; > > + } > > + > > + return 0; > > +} > > + > > /* > > * Reasonably generic function for adding memory. It is > > * expected that archs that support memory hotplug will > > @@ -291,6 +307,10 @@ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, > > unsigned long nr, start_sec, end_sec; > > struct vmem_altmap *altmap = restrictions->altmap; > > > > + err = check_hotplug_memory_addressable(pfn, nr_pages); > > + if (err) > > + return err; > > + > > if (altmap) { > > /* > > * Validate altmap is within bounds of the total request > > > > I actually wanted to give my RB to v7, not v6 :) > Given that check_hotplug_memory_addressable() is now static, I'll assume that the old [2/2] mm-add-a-bounds-check-in-devm_memremap_pages.patch is now obsolete. From: Alastair D'Silva Subject: mm/memremap.c: add a bounds check in devm_memremap_pages() The call to check_hotplug_memory_addressable() validates that the memory is fully addressable. Without this call, it is possible that we may remap pages that is not physically addressable, resulting in bogus section numbers being returned from __section_nr(). Link: http://lkml.kernel.org/r/20190917010752.28395-3-alastair@au1.ibm.com Signed-off-by: Alastair D'Silva Acked-by: David Hildenbrand Cc: Dan Williams Cc: Ira Weiny Cc: Jason Gunthorpe Cc: Logan Gunthorpe Cc: Michal Hocko Cc: Oscar Salvador Cc: Pavel Tatashin Cc: Qian Cai Cc: Wei Yang Signed-off-by: Andrew Morton --- mm/memremap.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/mm/memremap.c~mm-add-a-bounds-check-in-devm_memremap_pages +++ a/mm/memremap.c @@ -185,6 +185,11 @@ void *memremap_pages(struct dev_pagemap int error, is_ram; bool need_devmap_managed = true; + error = check_hotplug_memory_addressable(res->start, + resource_size(res)); + if (error) + return ERR_PTR(error); + switch (pgmap->type) { case MEMORY_DEVICE_PRIVATE: if (!IS_ENABLED(CONFIG_DEVICE_PRIVATE)) { _