From patchwork Wed Jun 30 07:12:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12351351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BB14C11F69 for ; Wed, 30 Jun 2021 07:14:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9F6461CC0 for ; Wed, 30 Jun 2021 07:14:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9F6461CC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bc0xVC0W8FMrC7DKUx7762tsP3MKrFk2ciorKJQsUpg=; b=HNww6SJ4B+EqQi oJOzDaTW3tb5mb6HDwkAxhQs8xAnS2QkMKUSST0tXG4O9hy5jLlW87UkeVTG98YMJMPss48wMW2Ld kiV6E0E7wNGZLxXfAbuuF58Lvz0OAzUOqNZyGK2zmWh1IwNygQP+NONRlA17AVJmn/FAkuY4bqocT 57glq5CoCQCLFO/PgW7XYpHlmkQdcxW8k36TTZoX/wMdgPeGGLoOQW+p9Ehbb+Nx2saSxFDIUmP6w 3m/U85Q+eXAFQQV3zWK2L0uTX2+vcg5Mvg3Ud4KhZkbZKM8DK0GjiXrPHYFjJ9PdxAel9N1NjgsLa VBSFTgn5Cd5EMO8rCbVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUP0-00D06W-SN; Wed, 30 Jun 2021 07:12:55 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUOZ-00D01q-40 for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 07:12:28 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E83961C8D; Wed, 30 Jun 2021 07:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625037146; bh=UYXA0kQV/AwFpjI1/LxwK1KTy94Uxqh1rAP3oKcin5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ew/tukz+Z7GwlvQVFx7D/8kpQR7lebc9n3EiMj4QhF14U1zai38mvLjCr2Vy/RyTc YLtrZ+zFteQ0ZArsndyKDFuldXfWEYyEVz++jNr8622DIWCGRww+9k40E1qIrz7dWv T/bLBeh2gICo9HPMQR9vg/Xxt+QDBsgkxqXlT8XjEpfXWI6DFtG+3qUoqX1ipAoLbX AWQkdHuaA2zt88oS2H5MCIK4uo1UhElfVljNlYT+Ml5rl7c4F5O2RECVuGfqS9tzKv U5ztTH6hmM2uUMj/98xA1WQ+9DeXAr2Q57bEa93MhvvaIH6vkCEHVhplMTfX+0WDix 5/RdkymPa1sBA== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , Tony Lindgren , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 3/4] memblock: ensure there is no overflow in memblock_overlaps_region() Date: Wed, 30 Jun 2021 10:12:10 +0300 Message-Id: <20210630071211.21011-4-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210630071211.21011-1-rppt@kernel.org> References: <20210630071211.21011-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_001227_228668_0AE5192B X-CRM114-Status: GOOD ( 11.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mike Rapoport 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 --- mm/memblock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 2e25d69739e0..67e0e24f8cc9 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)) @@ -1794,7 +1796,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); }