From patchwork Mon Dec 13 09:41:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFyay1QSyBUc2FpICjolKHmspvliZsp?= X-Patchwork-Id: 12673517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 199F6C433FE for ; Mon, 13 Dec 2021 09:44:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A1526B007B; Mon, 13 Dec 2021 04:42:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8518C6B007D; Mon, 13 Dec 2021 04:42:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7406B6B007E; Mon, 13 Dec 2021 04:42:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay039.a.hostedemail.com [64.99.140.39]) by kanga.kvack.org (Postfix) with ESMTP id 61F2B6B007B for ; Mon, 13 Dec 2021 04:42:11 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2893A607BE for ; Mon, 13 Dec 2021 09:42:01 +0000 (UTC) X-FDA: 78912279642.01.95F9DF1 Received: from mailgw02.mediatek.com (mailgw02.mediatek.com [216.200.240.185]) by imf22.hostedemail.com (Postfix) with ESMTP id 18239C0002 for ; Mon, 13 Dec 2021 09:41:59 +0000 (UTC) X-UUID: bf792127b1c44d6386fd0e4e6ae95b47-20211213 X-UUID: bf792127b1c44d6386fd0e4e6ae95b47-20211213 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1082172101; Mon, 13 Dec 2021 02:41:58 -0700 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 13 Dec 2021 01:41:56 -0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb02.mediatek.inc (172.21.101.103) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 13 Dec 2021 17:41:43 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 13 Dec 2021 17:41:42 +0800 From: Mark-PK Tsai To: CC: , , , , , , , , , , Subject: [PATCH 5.10 3/5] memblock: ensure there is no overflow in memblock_overlaps_region() Date: Mon, 13 Dec 2021 17:41:33 +0800 Message-ID: <20211213094135.1798-4-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20211213094135.1798-1-mark-pk.tsai@mediatek.com> References: <20211213094135.1798-1-mark-pk.tsai@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Stat-Signature: bnojap41sf9bd183cwwxopxxrpgzx44j Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of mark-pk.tsai@mediatek.com designates 216.200.240.185 as permitted sender) smtp.mailfrom=mark-pk.tsai@mediatek.com; dmarc=pass (policy=none) header.from=mediatek.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 18239C0002 X-HE-Tag: 1639388519-277156 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: From: Mike Rapoport [ Upstream commit 023accf5cdc1e504a9b04187ec23ff156fe53d90 ] There maybe an overflow in memblock_overlaps_region() if it is called with base and size such that base + size > PHYS_ADDR_MAX Make sure that memblock_overlaps_region() caps the size to prevent such overflow and remove now duplicated call to memblock_cap_size() from memblock_is_region_reserved(). Signed-off-by: Mike Rapoport Tested-by: Tony Lindgren Link: https://lore.kernel.org/lkml/20210630071211.21011-1-rppt@kernel.org/ Signed-off-by: Mark-PK Tsai --- mm/memblock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index c337df03b6a1..faa4de579b3d 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -182,6 +182,8 @@ bool __init_memblock memblock_overlaps_region(struct memblock_type *type, { unsigned long i; + memblock_cap_size(base, &size); + for (i = 0; i < type->cnt; i++) if (memblock_addrs_overlap(base, size, type->regions[i].base, type->regions[i].size)) @@ -1792,7 +1794,6 @@ bool __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t siz */ bool __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size) { - memblock_cap_size(base, &size); return memblock_overlaps_region(&memblock.reserved, base, size); }