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 241C7C433F5 for ; Sun, 20 Mar 2022 11:44:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6346683B1A; Sun, 20 Mar 2022 12:43:42 +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="YasIVeLa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C41A839CA; Sun, 20 Mar 2022 12:42:06 +0100 (CET) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (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 1B28F83AE7 for ; Sun, 20 Mar 2022 12:42:03 +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=3ChM3YgYKBiUBTDVMMHPPHMF.DPNV-CPPUMJTUT.EFOY.EF@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id i127-20020a1c3b85000000b0038c9c48f1e7so1160047wma.2 for ; Sun, 20 Mar 2022 04:42:03 -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=8WXJwtDpy+gj/AQBdynnZAtweHLufiL/8YOPNuSJNpk=; b=YasIVeLaqcLeCmO3q/8Z2tMRUrMxUbLJn0tUKPNIgmfs1qI7krTIHpv+7My4jeXkXD Iu/u4RtNEQEc2mM479fjAvfG6EexXq0DUVpUxE3Ad7NIb493hJevoPwD0g61y0JU9AcZ MFm3wNBJNuCuj20ZSK/MfU8VS+pgrYAqOxNs3HUtVam5dTrVF3Vcy1g/j6/pQ0GR1qE9 gwyqFnT3ytMJWjZpgpL9CVGUKG7RYDwDlX6+jszgFf4xu83Ewh51cxdn2orGwCW93+k0 rrV0jJG9CZwWv832KfeRTimnntJYUqydIxHHIcbTA8y8Tf0rYc5rfI9Y2UE4Ys3HrKo+ 97HQ== 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=8WXJwtDpy+gj/AQBdynnZAtweHLufiL/8YOPNuSJNpk=; b=lvcqjDGtyFziB9XgxNuvYSovOrsqDwymfevrj7RpEula3HTtvMhOqcuXnXmHePDhOb bLYtkXtIcKmp+mZ9UxcMbAOBLovG/ynyR+Whn21RjzL7oK0EtFjj0+O17zz5CvOd36Bm aPok9Q/LPdZOYniuJu8MKz7/l3hKaaOUu4sNnQqxHk7mXGU8xUhmOWhhJ4ccwqXcyeLZ Qzt948SXkncgbETGVCqvtNGRky1cRCA8uotTiF2dnMVbB4CZw2SkH+zZ0zqN8yyaASy/ kUWoYSInFPQD5NrmUGjyw9U9fPq8AbbCy5xcU6GZ+Bphyx03A+K5YPiXy6kfdyCM9XwI 8iNg== X-Gm-Message-State: AOAM5325vCtcUICZlfeV8OOzJyCwIN0wW6bDligLD6HX6MmwFBv4Cmy3 e8/mowqo4RDdh1eGZPxzRQCoxdWXlf4Y6ZAfx+KT5kNs+gcb5SBImepfDBO+puKVbDvvA6OFHK3 8q5vZh7nSHzjZYoAowJttueYpNMAmTXLFsmmB5PVEJ+N+ejfen3LCceIcGU8= X-Google-Smtp-Source: ABdhPJxqnlCabGi/C9vO7kzC41E+AcmPf5o5ztVa3l/IM5R2KdQ0kUzdIJEnsMcLhOgVKOlUwvr7rfrCtDo= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:a08:b0:38c:93c8:36e9 with SMTP id z8-20020a05600c0a0800b0038c93c836e9mr6613377wmp.97.1647776522708; Sun, 20 Mar 2022 04:42:02 -0700 (PDT) Date: Sun, 20 Mar 2022 11:41:14 +0000 In-Reply-To: <20220320114118.2237795-1-ascull@google.com> Message-Id: <20220320114118.2237795-8-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 07/11] virtio: pci: Check virtio configs are mapped 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 The calls to `virtio_pci_map_capability()` return NULL on error. If this happens, later accesses to the pointers would be unsafe. Avoid this by failing if the configs were not successfully mapped. Signed-off-by: Andrew Scull --- drivers/virtio/virtio_pci_modern.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index 38a0da0a84..2f1a1cedbc 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -534,7 +534,19 @@ static int virtio_pci_probe(struct udevice *udev) return -EINVAL; } + /* Map configuration structures */ + priv->common = virtio_pci_map_capability(udev, &common_cap); + if (!priv->common) { + printf("(%s): could not map common config\n", udev->name); + return -EINVAL; + } + priv->notify_len = notify_cap.length; + priv->notify_base = virtio_pci_map_capability(udev, ¬ify_cap); + if (!priv->notify_base) { + printf("(%s): could not map notify config\n", udev->name); + return -EINVAL; + } /* * Device capability is only mandatory for devices that have @@ -543,13 +555,16 @@ static int virtio_pci_probe(struct udevice *udev) device = virtio_pci_find_capability(udev, VIRTIO_PCI_CAP_DEVICE_CFG, sizeof(struct virtio_pci_cap), &device_cap); - if (device) + if (device) { priv->device_len = device_cap.length; + priv->device = virtio_pci_map_capability(udev, &device_cap); + if (!priv->device) { + printf("(%s): could not map device config\n", + udev->name); + return -EINVAL; + } + } - /* Map configuration structures */ - priv->common = virtio_pci_map_capability(udev, &common_cap); - priv->notify_base = virtio_pci_map_capability(udev, ¬ify_cap); - priv->device = virtio_pci_map_capability(udev, &device_cap); debug("(%p): common @ %p, notify base @ %p, device @ %p\n", udev, priv->common, priv->notify_base, priv->device); -- 2.35.1.894.gb6a874cedc-goog