Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3831341ybe; Mon, 16 Sep 2019 01:58:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNt58N+wG3EmCTzHNYiD8wLZg6uQgVUjrElQHg006yscumoZ+lMirLJUamEoPS1ViskS75 X-Received: by 2002:a50:a557:: with SMTP id z23mr6110918edb.99.1568624339149; Mon, 16 Sep 2019 01:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568624339; cv=none; d=google.com; s=arc-20160816; b=rkXrlD9TuXa65Fyp2c9olvFg6IPByEG4SoQ9OcIAhhSDWSf5ZSRwCr77Fxp8EwyVaX MoQwzAoSPbalo62V/NT+624nb3oAPmbiZGMadr38VBwBHUU/zZv0tvFQ7i+8XrCFGEZj 6XIxbEch/qyV0CHT7JTZRBlD63S6BJ7i0OgI5e9ZyxGFSDv96sf+TLyr1aVegQV9zJzb EeGsb2zSy8GwTJkHRkV9Bevan5u9ArvUWBqtkoD84/CViFew6r5L7ClWp5VLPEHL0l7b uV3q12qp8tvW99Z/QiPvFmyYFugZMpn6QwmvcRg5g2Aw8dHmJyvAPUTG+bPUF7aljBGR 2BZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=dFoT6couqRHyzEBvu5+NtOqrCE+J5kfbUJC7XN5+Spc=; b=YvdjkVOaUkOi5ciaxhSFu41MSY5ZfFW8v0YX4abNGfV9PBEDtYqsIylao55ph9O6Os MAQ24yA0Gf5ovVzVomi1qRL53GkxVskxueJ8JnGoA7yw8P4Tb9Ea0YPzIGoxjdSxE+Po w8OtQ4jy+51YnpgC6hzrbvoZxiJRcdIALGCbnSCqqpsEk6XLHQGExsOIE4Mb6mT/SPa1 cgCkdGaHsjvXyebY4SM9bP+1GwEylPutNlynlOdmg6vEqCflxP2lAt0+irvfYJpBG3Fp kHEyYxsrQ2d0z9L/GbfOZFwQLtmGvKbKdIlBbjB1tSQ7p0hxBj0kK5CahPrCZjwQqF6s h9KQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si4099925eds.363.2019.09.16.01.58.33; Mon, 16 Sep 2019 01:58: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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729536AbfIPGIW (ORCPT + 99 others); Mon, 16 Sep 2019 02:08:22 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:29812 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725270AbfIPGIV (ORCPT ); Mon, 16 Sep 2019 02:08:21 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8G6820p072998 for ; Mon, 16 Sep 2019 02:08:19 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2v2338jjg3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Sep 2019 02:08:19 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Sep 2019 07:08:17 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 16 Sep 2019 07:08:12 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8G68BQ852101308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Sep 2019 06:08:11 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 84B4A11C05C; Mon, 16 Sep 2019 06:08:11 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30C4B11C04A; Mon, 16 Sep 2019 06:08:11 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 16 Sep 2019 06:08:11 +0000 (GMT) Received: from adsilva.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id DA4ADA01B5; Mon, 16 Sep 2019 16:08:09 +1000 (AEST) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: Andrew Morton , David Hildenbrand , Oscar Salvador , Michal Hocko , Pavel Tatashin , Wei Yang , Dan Williams , Qian Cai , Jason Gunthorpe , Logan Gunthorpe , Ira Weiny , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] mm: Add a bounds check in devm_memremap_pages() Date: Mon, 16 Sep 2019 16:05:40 +1000 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190916060544.21824-1-alastair@au1.ibm.com> References: <20190916060544.21824-1-alastair@au1.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19091606-0012-0000-0000-0000034C696C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19091606-0013-0000-0000-00002186DDF2 Message-Id: <20190916060544.21824-3-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-09-16_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=968 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909160067 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alastair D'Silva 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(). Signed-off-by: Alastair D'Silva --- mm/memremap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/memremap.c b/mm/memremap.c index 86432650f829..fd00993caa3e 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -269,6 +269,13 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) mem_hotplug_begin(); + error = check_hotplug_memory_addressable(res->start, + resource_size(res)); + if (error) { + mem_hotplug_done(); + goto err_checkrange; + } + /* * For device private memory we call add_pages() as we only need to * allocate and initialize struct page for the device memory. More- @@ -324,6 +331,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) err_add_memory: kasan_remove_zero_shadow(__va(res->start), resource_size(res)); + err_checkrange: err_kasan: untrack_pfn(NULL, PHYS_PFN(res->start), resource_size(res)); err_pfn_remap: -- 2.21.0