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 9F4A9C433EF for ; Sun, 20 Mar 2022 11:44:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1075A83B25; Sun, 20 Mar 2022 12:43:45 +0100 (CET) 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="LEqK14hu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8AC85839CA; Sun, 20 Mar 2022 12:42:08 +0100 (CET) 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 3223D83AE2 for ; Sun, 20 Mar 2022 12:42:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3DBM3YgYKBicDVFXOOJRRJOH.FRPX-ERRWOLVWV.GHQa.GH@flex--ascull.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id r64-20020a1c2b43000000b0038b59eb1940so6165578wmr.0 for ; Sun, 20 Mar 2022 04:42:05 -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=VzXZ5fOXDOHdMHznmXDsLNQCt5EZYvuIwAswzLwYnYQ=; b=LEqK14huulAjmTcOcTFbBNYZpBsr8E+Sll63irxfaxBnWqfpAu5GKfM/ylHyb28uNc uZpN+Y/PqcdcWVx0jx4C7sflZvbdgkyQ7u2CMZxJu32sgakek86dJ9UuVcuP06cmAIJ9 AO/3kpywv8a50JODQRpF39dGqD/9CLtQYrZ+jDLo6MpkiTkWOiDxMsM9d7npPWGlda3+ 4TNa0lDarossmAnhtFEl5dCSH0JSr7DIH0+tgd61koblWtvZkyeVxI8xj5yz+7lPkaYo 8uFRAaY4lCUJp8B8fq0jp1hpYzFVrgDOuFyG2j5NCiw52At0EyelicaUK2G+cfdcKya2 sZ3Q== 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=VzXZ5fOXDOHdMHznmXDsLNQCt5EZYvuIwAswzLwYnYQ=; b=SiR5UZUrA+yCi67ROUSFDO5BqZ7lWGyy1Hy4bu+F2ElTNxDlcfqIQznk17XUSl/f9n 8SGZNW/USxAlIZ7EfIKPCvAg3H9bbPHjV/9dVcot4LeVvIWthIisVtErsACCCZuauJOx A1OpT5YR3Sd3low7UlmefTnjgoh3P/OK3kS4fSxiIKTOtfJAsfZkQQrvQNera/amsFy6 gPYM5qidri8DlXyKP6HXYy8rH6HpWBbvxMsMINu8Jj/kEwXRRWSRd6LOj7GfhrPxXJCu /00/hGNZUbmCH6QjHbIhsEKg1aHnq862eEwi/H/xz52KNdKmwDYp51FfTJ87SbF/U+T8 33Zw== X-Gm-Message-State: AOAM530v6ETydjYw0HFcqOWwA3UOdRz2vyG9rrR2lnhSQlRpMFp1R0xO Gh8/+bHTEnJhtQVjN4/tax1Ou4d6UtGQso7mCy0pKmH+whCZVWjObcnd+GJZb1Nzc1amZ486cR2 mvZifR26TNAYBHcd6fhBru8VvEGkBDcJXR15IkTZ39B5vVkvZQVLhToyP2pQ= X-Google-Smtp-Source: ABdhPJyOhkMHBv5ExaH1gK6ER/tXUDwZSHI7uk3IeFjUtc3yPf/ls4JeFLsteCxfXZDtULiCmpL+Hk/gnqQ= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:19c6:b0:38c:712d:f1c7 with SMTP id u6-20020a05600c19c600b0038c712df1c7mr15383967wmq.126.1647776524827; Sun, 20 Mar 2022 04:42:04 -0700 (PDT) Date: Sun, 20 Mar 2022 11:41:15 +0000 In-Reply-To: <20220320114118.2237795-1-ascull@google.com> Message-Id: <20220320114118.2237795-9-ascull@google.com> Mime-Version: 1.0 References: <20220320114118.2237795-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [PATCH 08/11] 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-Mailman-Approved-At: Sun, 20 Mar 2022 12:43:23 +0100 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 --- 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 33dda00002..54a05d7567 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.35.1.894.gb6a874cedc-goog