Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2095165ybi; Sun, 16 Jun 2019 21:40:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6T+6RPhhxjxnaiyMPJmtJooY75HRiumkCjlr9xpKvimhdDHVTJYdsg/Qt0aEUSroS16bh X-Received: by 2002:a63:c006:: with SMTP id h6mr40511912pgg.285.1560746436602; Sun, 16 Jun 2019 21:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560746436; cv=none; d=google.com; s=arc-20160816; b=W7Lbtzj1owZK60/Q+wPdtUPnBD3P85BbfJojNKP5HQHTnjt2GcZ1448Jw5qSP918QV iEPyrkvKvcXfKxDkBzALi2FIVfOBbxSS1vRPM+fGvXUy284IhVmH+6+G8ndLusQo14XN /6uxA3HtL7G69yuVSe2toCpy+luQEVrXRa5oNyDQ59aUqoMBHE1NuKORDmrCNUoHKu0n saLYN4GtJyepOwWNlV6i3rs2y0IbMM8G6SZR+NhrpLj1e8+ngDRPeWmwHAJGlxqSs/1c ONoXRy6kFH1E7QtQxCVfrYrQF1xUZOEe59xQqH0wtpLYVdLjpoiG0R6khFD2P3pUixlh YGaQ== 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=pHHqDgSmDhkmuuAn61xIwvRBD6Ngo7T4bwQJ4yY+RH4=; b=KAa/OouqfjlqBVttQD+ntDaF2f0/FTqBbfUF8ds7SP8oJ8pBx5omvm5QnHnZnBLoYL s4okJ3eESF1DM0cTfgbNIwrEAi0SMTXQsgDaWMlChGeqmJO5BiUX38WrPCWZMoZFKS7T 2fC9ZiUDvrxU56nQnEcYZRL3iSsK29aUyT0veOFueWhjWvt7KMHp3LipGEs0zaMkGjsl TwXmnhoTD1IxkPlHqwEFYKnPCaXv6H+akvZz0gERHbqNmy/bLAbf/hJEgplDSvhGM3U1 Y+UVGUsr+09NHaHUZX05qf9tClk09KW8ekp2jSgHDxKLWXDUXZsjeumfv0Iw5OqtyLcZ W88w== 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 u188si9594706pfu.228.2019.06.16.21.40.21; Sun, 16 Jun 2019 21:40:36 -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 S1726311AbfFQEi0 (ORCPT + 99 others); Mon, 17 Jun 2019 00:38:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49822 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbfFQEiZ (ORCPT ); Mon, 17 Jun 2019 00:38:25 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5H4cG1F032120 for ; Mon, 17 Jun 2019 00:38:23 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2t62n726ht-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 17 Jun 2019 00:38:20 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 17 Jun 2019 05:38:03 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 17 Jun 2019 05:37:57 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5H4bukV29622568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Jun 2019 04:37:56 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C969352052; Mon, 17 Jun 2019 04:37:56 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8160B5204F; Mon, 17 Jun 2019 04:37:56 +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 7A68EA0208; Mon, 17 Jun 2019 14:37:55 +1000 (AEST) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: Andrew Morton , David Hildenbrand , Oscar Salvador , Michal Hocko , Pavel Tatashin , Wei Yang , Qian Cai , Thomas Gleixner , Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Konrad Rzeszutek Wilk , Jiri Kosina , Mukesh Ojha , Arun KS , Mike Rapoport , Baoquan He , Logan Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mm: Trigger bug on if a section is not found in __section_nr Date: Mon, 17 Jun 2019 14:36:27 +1000 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617043635.13201-1-alastair@au1.ibm.com> References: <20190617043635.13201-1-alastair@au1.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19061704-0020-0000-0000-0000034AAC24 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19061704-0021-0000-0000-0000219DEF14 Message-Id: <20190617043635.13201-2-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-17_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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906170042 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alastair D'Silva If a memory section comes in where the physical address is greater than that which is managed by the kernel, this function would not trigger the bug and instead return a bogus section number. This patch tracks whether the section was actually found, and triggers the bug if not. Signed-off-by: Alastair D'Silva --- mm/sparse.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index fd13166949b5..104a79fedd00 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -105,20 +105,23 @@ static inline int sparse_index_init(unsigned long section_nr, int nid) int __section_nr(struct mem_section* ms) { unsigned long root_nr; - struct mem_section *root = NULL; + struct mem_section *found = NULL; + struct mem_section *root; for (root_nr = 0; root_nr < NR_SECTION_ROOTS; root_nr++) { root = __nr_to_section(root_nr * SECTIONS_PER_ROOT); if (!root) continue; - if ((ms >= root) && (ms < (root + SECTIONS_PER_ROOT))) - break; + if ((ms >= root) && (ms < (root + SECTIONS_PER_ROOT))) { + found = root; + break; + } } - VM_BUG_ON(!root); + VM_BUG_ON(!found); - return (root_nr * SECTIONS_PER_ROOT) + (ms - root); + return (root_nr * SECTIONS_PER_ROOT) + (ms - found); } #else int __section_nr(struct mem_section* ms) -- 2.21.0