Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp86440pxv; Wed, 30 Jun 2021 00:14:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJFo5H6Qb2VcMJL2jpLTiQXeOL4uRDhYoKDtA+W6lb835lr9wIeoSiYUkeNlUgj+ltI4No X-Received: by 2002:aa7:c04e:: with SMTP id k14mr43758036edo.157.1625037263471; Wed, 30 Jun 2021 00:14:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625037263; cv=none; d=google.com; s=arc-20160816; b=aTSjbE4NY9CB+yHT/mc0yVteOtJtQrIJeWWMN3VNZhIDmEDPMq63ZUMYTttnABFPO+ naExM4/mYhMKO8jyZvuyP0fLaFiSU/mpPMEMjmRYW0D+qcysvlZOwOhhiumrz2BLoMSS 1wfSrOhCKhV/JgIkcGSBE8kBFT2Fufwi1b7a5+aZOQpe4PUU883/Zaw8gI9CAEwBvfyv 0Wq96/anuLxeYsw1ECjD0V5LqtqZfIysgkZmjeE7YFBsufwG5rbNSG2VH63PkCszb+p8 lH1jAnqVHA6itf2iVMAfGvkw8Dk1gabwraAMQJecvN6VUKTzn3uwnaGDj2DTIQordTo1 Us9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A2hetsXnUqN2/bwSmz42CW/P2axkRytCFBmRK7NpgM0=; b=gxORz/80uzocgV2cFlVYpWc91KE6U4na/bvLAdxzCBZyw5opr4ZeXQdQkbIVQ2naFV Qwk4/H2I94YUEWYyKbi3pX2dIfiGMyLVcv0QxlV26otgHoWM2qELC/qLQWtrkFFu2IkC FFeCmM/se4q3hwwxuSueNtZAjY5Hs1IT8iJm/lunxvZCeYA1sQz4m471SM+XfNUbYoqh RRVmbxlEaNrLQly+wzdSyMtNoWh84V9zkylqUU1/+JK6FF6yR12CykzYYxyq6Dos2RT8 EW1ojjfw/9qa8x0V44X0CjEt8i2/aJD46B/VIIsUn/BpUPZitXH6gMpQn6XnIWQLvvt3 qA4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ew/tukz+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si15985023edc.130.2021.06.30.00.14.00; Wed, 30 Jun 2021 00:14:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ew/tukz+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232861AbhF3HO5 (ORCPT + 99 others); Wed, 30 Jun 2021 03:14:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:52334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232816AbhF3HOz (ORCPT ); Wed, 30 Jun 2021 03:14:55 -0400 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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); } -- 2.28.0