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 87AA0C433EF for ; Thu, 21 Apr 2022 16:13:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 481A083EC0; Thu, 21 Apr 2022 18:12:07 +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="MreHcqcT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A537283E75; Thu, 21 Apr 2022 18:11:42 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (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 C075683E66 for ; Thu, 21 Apr 2022 18:11: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=3OoJhYgYKBt09RBTKKFNNFKD.BNLT-ANNSKHRSR.CDMW.CD@flex--ascull.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id c62-20020a1c3541000000b0038ec265155fso4676573wma.6 for ; Thu, 21 Apr 2022 09:11:39 -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=4Q+2ilo4NKrRIBqHb4D069f8iTQVK2DiRWl/y7f4hOw=; b=MreHcqcTef0pdPCrfO98GaTFIDjTyg5GWNDTyBHgvNILHmX2Jusut0gOzkRP1Ar78K WKpxm8w0AwrcfPmW0iAFPUEZiQXtLd8im1HhwbDQniNZvLlM/4hgg3gHI7Mq5Sy1Jx5J VGAJcCmo6RuX6Tl0n/Cl38iWBGr2Bi/6jQvT9GHWFpr5qR7V7bkMCrtr0knjmlgi0pUN hV1sqBXOjDI7NfTcpk6UsZ4KeLW/8Cywu/H9hQShL8UY33+wlUHDAYTRkiulBMJAinqE EgUQID7peH6jwQNooT+hkXvtGkyyaYYUBqXHM0c06Bvd2ORPpdcqsLbnIO8hpDaTX0q2 IKUA== 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=4Q+2ilo4NKrRIBqHb4D069f8iTQVK2DiRWl/y7f4hOw=; b=hcw0UvUs+dE4+SGGcMmAtfZex3wSOzXphPR8NvBZCea0yvGH9sAI9m9HYGWRyaRJX1 MrUiKgyu3omrFACl6sckgI9bCZfYrrvn02qsI24xUHym20XsL6KhxZZXZdnOkrxb66Gp 2aMahe7jxmGB/a5FmFvQh+J9Z70OrT1Z3pV7PMOD/7P/uyMpfXhTgtUlI5ylTXU/YHlv fXICdU9kb3YyInX6Ht6rNfEqysdMCSoscRfKwoC4syINoFlJuUv0Lz14fJsxLtvFGwxy eZYajg9QeTs6vP0uGrKDeHcLbTg9h8R+qgrHLPYPxFR70ho4IW8SNutnzoHYTURBOCyq YPbw== X-Gm-Message-State: AOAM530ha/wzqWY5Di1d5a7kL7IA8n9v7U6BMAvBSL+C34Q6breBeiFq rIAqhjxBzrTOaYQnB/KWrQgfO5jH+7YdeDs7Xj2g75m6nN4LS8+APXAX67+aV6lkQIzeUB6YV/r pVDEoWo3YoUyerNQnOGjfpZVSVeuIoucWhKZVXOBDjGdOYKFLhyngS33H0ZE= X-Google-Smtp-Source: ABdhPJzRYKmJWeI/X04fvWp4QVwCPDaWxoA9sujgUDPw5cwx4zu+o3Kbm0y0BvOfUuaNB5wW0WdaJbnFjZU= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a1c:35c7:0:b0:38e:4c59:6788 with SMTP id c190-20020a1c35c7000000b0038e4c596788mr65777wma.1.1650557498951; Thu, 21 Apr 2022 09:11:38 -0700 (PDT) Date: Thu, 21 Apr 2022 16:11:07 +0000 In-Reply-To: <20220421161116.1202023-1-ascull@google.com> Message-Id: <20220421161116.1202023-10-ascull@google.com> Mime-Version: 1.0 References: <20220421161116.1202023-1-ascull@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 09/18] pci: Check region ranges are addressable From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.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 8bbeb62f2e..0424cd339e 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1013,7 +1013,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.36.0.rc2.479.g8af0fa9b8e-goog