From mboxrd@z Thu Jan 1 00:00:00 1970 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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B1E9C433F5 for ; Tue, 29 Mar 2022 17:01:19 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E82CE84053; Tue, 29 Mar 2022 19:00:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="h6c9njrs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E51D884012; Tue, 29 Mar 2022 18:59:46 +0200 (CEST) Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 47F6984025 for ; Tue, 29 Mar 2022 18:59:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3_TpDYgYKBpg2K4MDD8GG8D6.4GEM-3GGLDAKLK.56FP.56@flex--ascull.bounces.google.com Received: by mail-wr1-x449.google.com with SMTP id j67-20020adf9149000000b00203e6b7d151so5197193wrj.13 for ; Tue, 29 Mar 2022 09:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LWo1NNTAI4XfbIeyxSswF2gPbEPBoxjIELRbS84F95E=; b=h6c9njrsv8vzjD/oFCu/K0yNVR0/jRUysbRSaR8nY/kzzXBA7hgUeEvz/b7PBHERqF GsAsX88Rwg/Stpx/qEs+4kjv6Oy7eujLV34Uw6HEtQ3fHMUu7H/azx34H3WtE88uHkxW sCHekABA2c9FpfL2KiykK1pFWza785UMguidiv1QoNGbZ+yRiiNo3nfN2Me287737m58 DGniUeOtcQR4kQlzuLTweOmzluetHiDe4emidFuhnp8fRWRvdIRZHvY4+HY1j/vgPH6N SbRggX70gItnRXjSXR7XFFojiiLSDWudvtMFpp7jw/QtvXfFfF6qEbF0+2FEt8SaxFuB wuZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LWo1NNTAI4XfbIeyxSswF2gPbEPBoxjIELRbS84F95E=; b=LuSLJX1SdgaWADrke6Zx4wvkjpKDUFWcjhKvcUgHoRpQEfaWhteXFZkryyuvYYobk5 OdjjE/UxI+v97lTrw/lhHTWgFoRxz23IoJS/PXKyl6F25ofW1IrJdQkpiIMgizrorlFE zT1ay1AkunEIZrN6Hievafp83QLEnpvoc1d809cNMaPbDhdzqdFwPvWUjVFezonlqB6Q PqHQGjqvS0h1ckF/8Wt2rxBbSOpSVUXeYV6cnjU1sUZI+AbdaS1nz1ImkNiNVH1UnIKp 9H2DIRibm7GjjCOX/utM6cSuKXn8vP9JgVE5nXQW8TfOC/EqRFPBhh0Tcvf4+vxxNEgr RHOA== X-Gm-Message-State: AOAM531p70nSolX0icBh64v2J7Ys8/v7OjwrjBPBn3ppO8W6D4k5Zq16 rNhpFjaeihkJn3KjMtxH1/GKnEh2X3ojb89B32ahyHCCju4M8epXC67jJrJa2bSNOW6OI+wR4Qs ipNbN460Z9bQNyq1q6BqAKQJdvgtQYd8ihQ+ZYDsDFKGiuMLADRAcCZKjrZg= X-Google-Smtp-Source: ABdhPJweH9S+k0KildUpOsp2+MczYP8a0YSRhmigUhUfudk/tAn715rF8CPyoW409Cbv/MwYMHXs3nSjBXE= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:3d86:b0:38d:581:89ad with SMTP id bi6-20020a05600c3d8600b0038d058189admr185567wmb.42.1648573181693; Tue, 29 Mar 2022 09:59:41 -0700 (PDT) Date: Tue, 29 Mar 2022 16:58:52 +0000 In-Reply-To: <20220329165900.1139885-1-ascull@google.com> Message-Id: <20220329165900.1139885-11-ascull@google.com> Mime-Version: 1.0 References: <20220329165900.1139885-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 10/18] pci: Check region ranges are addressable From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, adelva@google.com, keirf@google.com, ptosi@google.com, Andrew Scull Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean When parsing the `ranges` DT node, check that both extremes of the regions are addressable without overflow. This assumption can then be safely made when processing the regions. Signed-off-by: Andrew Scull Reviewed-by: Bin Meng --- drivers/pci/pci-uclass.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 719656eb3a..d84d97d676 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1017,7 +1017,22 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node, if (!IS_ENABLED(CONFIG_SYS_PCI_64BIT) && type == PCI_REGION_MEM && upper_32_bits(pci_addr)) { - debug(" - beyond the 32-bit boundary, ignoring\n"); + debug(" - pci_addr beyond the 32-bit boundary, ignoring\n"); + continue; + } + + if (!IS_ENABLED(CONFIG_PHYS_64BIT) && upper_32_bits(addr)) { + debug(" - addr beyond the 32-bit boundary, ignoring\n"); + continue; + } + + if (~((pci_addr_t)0) - pci_addr < size) { + debug(" - PCI range exceeds max address, ignoring\n"); + continue; + } + + if (~((phys_addr_t)0) - addr < size) { + debug(" - phys range exceeds max address, ignoring\n"); continue; } -- 2.35.1.1021.g381101b075-goog