From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85BB4C10F14 for ; Wed, 2 Oct 2019 22:14:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4799A21848 for ; Wed, 2 Oct 2019 22:14:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="x3yRh+ed" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4799A21848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D0FD56B0003; Wed, 2 Oct 2019 18:14:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBFC76B0006; Wed, 2 Oct 2019 18:14:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD4AB6B0007; Wed, 2 Oct 2019 18:14:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 9A9C66B0003 for ; Wed, 2 Oct 2019 18:14:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 4C866180AD7C3 for ; Wed, 2 Oct 2019 22:14:18 +0000 (UTC) X-FDA: 76000248996.06.gate89_429f8a544e82e X-HE-Tag: gate89_429f8a544e82e X-Filterd-Recvd-Size: 4820 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Oct 2019 22:14:17 +0000 (UTC) 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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)) { _