Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5084301ybl; Mon, 26 Aug 2019 22:23:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhWICftp8+4BLskHe14tCUW34p+t5GPIqDg+kAQtO1bgru4LdCvoT89aCov/HlHlKIfbFd X-Received: by 2002:a62:1bd5:: with SMTP id b204mr23666024pfb.14.1566883383759; Mon, 26 Aug 2019 22:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566883383; cv=none; d=google.com; s=arc-20160816; b=mw9YvdJTd3C6PByNqnVJlRcJ2yPiyGD86Qb42zkCFbCG2xvVfLsLEn0hd+fNZgJtOK t6h9HAsMzzlIYFFGQeb/ofaqfMBlai9JwgXVft0sRm/ZlDXgWiSlZYpoz67A4gzrU1Ii OoQY3qdvSnFH80k37KSd71JUKuHfRrz7dVCPPp/757EFu1IceRgNT/BqdaNXPym8xlA1 c+oi56+nBasUWsoDLmVjMVQDQL+v8e36HXkxUZes00yUBMtDrng1pRSK/LbGxjsqdZEH n3227Tvhpllv66gWJQCJAxH3zfB/CFjqQBrH4Eb1Fr8kvVAIu9RoCpn2Vlz1SmmIv6UN xwwg== 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:date:subject:cc:to:from; bh=lzOrtNvs8hAJ3ZLNdWXpNoHizKXlXS/A61dG+V7NpIY=; b=yDwgGkbcdIhz2li9d0YNt1n4kHRFfMIK8U5qSYzZ6VNjDCDsulWobpxhCFDj3F021D R8LKNW/3AUWjiAvW5M7kubRNkiSDbwjRgmzGoEyZxRn9SvOC0x7WJHTwjaDW8A+a9Bfk yXa59GcQElplb1h96sI479wPYeuJ+d5lzJuxyXc8QX4+OvKR3YOhlWF7QWbotfVcHz5C jOIY+yCRvUTWDb6q4LI8Hs221ot6ZK6UdTZlo4cKK0ZCQBtO7d9hpik9/7aiBhIUYVOO E82YDk6sW8f61h8t109Ifx9bRKOm9nN4Jo07vxuBROW/GlQhI1AJIzv0ejfaEjq/lG4D 9hsA== 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 n14si13043634pfq.108.2019.08.26.22.22.47; Mon, 26 Aug 2019 22:23:03 -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 S1726140AbfH0FVz (ORCPT + 99 others); Tue, 27 Aug 2019 01:21:55 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36908 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725811AbfH0FVy (ORCPT ); Tue, 27 Aug 2019 01:21:54 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7R5HoFw130212 for ; Tue, 27 Aug 2019 01:21:53 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2umswhf6d8-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 27 Aug 2019 01:21:53 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Aug 2019 06:21:51 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 27 Aug 2019 06:21:48 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x7R5LlXU49414226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Aug 2019 05:21:47 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 177BFA4057; Tue, 27 Aug 2019 05:21:47 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B7FA4A4040; Tue, 27 Aug 2019 05:21:46 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 27 Aug 2019 05:21:46 +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 54733A022E; Tue, 27 Aug 2019 15:21:43 +1000 (AEST) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Christophe Leroy , Andrew Morton , Michal Hocko , David Hildenbrand , Mike Rapoport , "Aneesh Kumar K.V" , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc: Perform a bounds check in arch_add_memory Date: Tue, 27 Aug 2019 15:20:46 +1000 X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19082705-4275-0000-0000-0000035DC4DF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19082705-4276-0000-0000-0000386FF3FD Message-Id: <20190827052047.31547-1-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-26_08:,, 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=936 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908270059 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alastair D'Silva It is possible for firmware to allocate memory ranges outside the range of physical memory that we support (MAX_PHYSMEM_BITS). This patch adds a bounds check to ensure that any hotplugged memory is addressable. Signed-off-by: Alastair D'Silva --- arch/powerpc/mm/mem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 9191a66b3bc5..de18fb73de30 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -111,6 +111,9 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, unsigned long nr_pages = size >> PAGE_SHIFT; int rc; + if ((start + size - 1) >> MAX_PHYSMEM_BITS) + return -EINVAL; + resize_hpt_for_hotplug(memblock_phys_mem_size()); start = (unsigned long)__va(start); -- 2.21.0