Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5431987ybe; Tue, 10 Sep 2019 03:40:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOQyN185khSDyaTiRiOV8bmFT0mLnjt1JUeFmapzV4KZDs0ymLgKgG0ZT5c85V6UkghVPf X-Received: by 2002:a50:ee98:: with SMTP id f24mr20981100edr.52.1568112056810; Tue, 10 Sep 2019 03:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568112056; cv=none; d=google.com; s=arc-20160816; b=gA1CyXSsolBz959kuVi65Vf6+HPSMutw4EWMkPspjGp/ntwON6YguX9HVNdOE9xko4 qtUKxQKZ+rvAOp+aC/phpEoIZb/B6gQdQuhgTZTSnkMh+8kXFU11nMEmwi4ngPxdbk85 RaDaIefMPl/OD8qJwoExeQZHs2WP0sj8d7sgOtyubSn5M5+0pZKc7uJ+V3Q0iXb08Gn2 sFxbL90J/p8UIlUxS63LTNjrQ77AsQG1qkfMAUMj0QAxBWrH2+LasIp/gH2DvaChdGwD hq8G/sGvAbt+C76uZloYSojawHj7ICJ8e48HJ0pmwQm3qJMqi4vn6RPOEMtSQNOT7fdQ dUIw== 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=ZTQjqeXFytHniMS8sP1sGnDDSt3G9PJBTBoUmom6/mw=; b=yuaRBbJWWL223WpqoeXAWcoRn+MvwrggOjeVFs/zgYloxa4g/XAk3kxwTRHLcDu4I0 q2qlwynjcbyt9mmyqNJQs8vp9/k665fXmjMtHt76eLN/vKgW0i/syIp7H7x+nO97binc skFaPpWpxQRgvUeJtEpwUlP5yVScv/ARlxxOJHOkJl4QhN+fZzeYW1TXk5E3/s6u6Eb5 H1QBjvgz9F7v/8a+nqNrvHjvTn5hCMIS1aKkiLVxcNQK9bKkhzQZwF3YgQ9VhEJ3YIIr IKRakZT0KbnEaXlrsKcftpV51Olb2Zi33Bxkb7WMl+7Vu7aGFIzkeX/6BBjlty17hQ8I JE2g== 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 f33si10934002edb.281.2019.09.10.03.40.32; Tue, 10 Sep 2019 03:40:56 -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 S2404070AbfIJCw7 (ORCPT + 99 others); Mon, 9 Sep 2019 22:52:59 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32906 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbfIJCw6 (ORCPT ); Mon, 9 Sep 2019 22:52:58 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x8A2q79A035544 for ; Mon, 9 Sep 2019 22:52:57 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2uv86vm6s2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 09 Sep 2019 22:52:56 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Sep 2019 03:52:54 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 10 Sep 2019 03:52:49 +0100 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x8A2qmit41746618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2019 02:52:48 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9918FA405F; Tue, 10 Sep 2019 02:52:48 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43F35A4054; Tue, 10 Sep 2019 02:52:48 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 10 Sep 2019 02:52:48 +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 021CBA01D3; Tue, 10 Sep 2019 12:52:47 +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 1/2] memory_hotplug: Add a bounds check to check_hotplug_memory_range() Date: Tue, 10 Sep 2019 12:52:20 +1000 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190910025225.25904-1-alastair@au1.ibm.com> References: <20190910025225.25904-1-alastair@au1.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19091002-0016-0000-0000-000002A94740 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19091002-0017-0000-0000-00003309CB7A Message-Id: <20190910025225.25904-2-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-09-10_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909100026 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alastair D'Silva On PowerPC, the address ranges allocated to OpenCAPI LPC memory are allocated from firmware. These address ranges may be higher than what older kernels permit, as we increased the maximum permissable address in commit 4ffe713b7587 ("powerpc/mm: Increase the max addressable memory to 2PB"). It is possible that the addressable range may change again in the future. In this scenario, we end up with a bogus section returned from __section_nr (see the discussion on the thread "mm: Trigger bug on if a section is not found in __section_nr"). Adding a check here means that we fail early and have an opportunity to handle the error gracefully, rather than rumbling on and potentially accessing an incorrect section. Further discussion is also on the thread ("powerpc: Perform a bounds check in arch_add_memory"). Signed-off-by: Alastair D'Silva --- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index f46ea71b4ffd..bc477e98a310 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -110,6 +110,7 @@ extern void __online_page_increment_counters(struct page *page); extern void __online_page_free(struct page *page); extern int try_online_node(int nid); +int check_hotplug_memory_addressable(u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size, struct mhp_restrictions *restrictions); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c73f09913165..3c5428b014f9 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1030,6 +1030,23 @@ int try_online_node(int nid) return ret; } +#ifndef MAX_POSSIBLE_PHYSMEM_BITS +#ifdef MAX_PHYSMEM_BITS +#define MAX_POSSIBLE_PHYSMEM_BITS MAX_PHYSMEM_BITS +#endif +#endif + +int check_hotplug_memory_addressable(u64 start, u64 size) +{ +#ifdef MAX_POSSIBLE_PHYSMEM_BITS + if ((start + size - 1) >> MAX_POSSIBLE_PHYSMEM_BITS) + return -E2BIG; +#endif + + return 0; +} +EXPORT_SYMBOL_GPL(check_hotplug_memory_addressable); + static int check_hotplug_memory_range(u64 start, u64 size) { /* memory range must be block size aligned */ @@ -1040,7 +1057,7 @@ static int check_hotplug_memory_range(u64 start, u64 size) return -EINVAL; } - return 0; + return check_hotplug_memory_addressable(start, size); } static int online_memory_block(struct memory_block *mem, void *arg) -- 2.21.0