Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8626030rwb; Thu, 24 Nov 2022 02:02:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ok8Lq71BJ+1ld/7k13vDsznov2sZd1d05f9XWo6JbcTeJdrEr6XjWiwuUfOgubhJjXLln X-Received: by 2002:a17:902:ce06:b0:188:fd3f:cb06 with SMTP id k6-20020a170902ce0600b00188fd3fcb06mr12693082plg.23.1669284134082; Thu, 24 Nov 2022 02:02:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669284134; cv=none; d=google.com; s=arc-20160816; b=p/sd33ldaB9pEhzrV4e83qvUPg7EQ9Ruc+lHyqqdUf27QBf9HpuzlooUM7o/Xa1y+C 6HHyQOFVHiaT6scwymzqPVzT/q0N5Gm1IJTK5iyED/j/c3PUMVbz66LXBwjfIL7xdAxo cvfAGIa00BZyb+NIiS85YxI4trmfWioyhFjTLAeII8LyHtefNLY8NX94sJLE8v2i7m9h bvftdcMOyBhq1f82qsfcjHx8J1ttKBVVCA07wP4efBHASEHfk53hVcwCXtag7YzGv5hk +qF+bo8h3eOxBy6C0PKgxFq+5DjeWZDYRpf7ha30+Gw4qY63u0u5Sy6gYqgJhaMaUn24 lRTw== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=eQStuUnlt0Xi8+G0lvXlH+oX7HClAQ9C4gwpOhHA7hY=; b=R39JIrkbKIqsqA5QOoZX7E9uIf+Z8NXWCqyeiW3V4xXLEVP+Hl0gZmtPRkJyxhWdPJ LUCJPTaOVpZZON+tVnL1dlDw+y3wsNqjg4zVVCGqbHfwf5CsTci9H8nDvnDqw20o7Xo6 4YqNt6ZASoFCdw8+jzWwG/swPPo3TuTtE8RwRgmn801/aBTvoD8/bVOXiChlEnH0m1gg rUK6Pe3LDwGA5+wr4UEulDK+CxmYthi6/atQP6bifK/xzqYNsMS1ObSXZmXaujEf3fXV WnhsNF13d8kdSjVgtBqUEXoX9I9G1AQZYqqbRyPoHsP/shy0WvfgnJDz0Oqn8YNJoEb2 b3oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=aOvnV10Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a63464d000000b0047702d2fe08si885804pgk.493.2022.11.24.02.02.01; Thu, 24 Nov 2022 02:02:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=aOvnV10Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229757AbiKXIpf (ORCPT + 87 others); Thu, 24 Nov 2022 03:45:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbiKXIp0 (ORCPT ); Thu, 24 Nov 2022 03:45:26 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 228A6ACEB8; Thu, 24 Nov 2022 00:45:24 -0800 (PST) Received: from ykarpov.intra.ispras.ru (unknown [10.10.2.71]) by mail.ispras.ru (Postfix) with ESMTPSA id C015040D4004; Thu, 24 Nov 2022 08:45:22 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru C015040D4004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1669279522; bh=eQStuUnlt0Xi8+G0lvXlH+oX7HClAQ9C4gwpOhHA7hY=; h=From:To:Cc:Subject:Date:From; b=aOvnV10ZPyWJ2iwZLcC0pLwFLC91vmZcs2bdk1Dp7enXZXbm+sunvG4IBXICyuw33 LcsFVC9L/SmsUmvN6ygZGIFF34E4i58AgiuhNqTFOxiYB3N5HZSiM6ElKQSf1zfGLu OwXafYxbqzSIIi4k6bhiqumEzjc5pH1BcSe6bPUM= From: Yuri Karpov To: "David S . Miller" Cc: Yuri Karpov , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH] net: ethernet: nixge: fix NULL dereference Date: Thu, 24 Nov 2022 11:43:03 +0300 Message-Id: <20221124084303.2075092-1-YKarpov@ispras.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function nixge_hw_dma_bd_release() dereference of NULL pointer priv->rx_bd_v is possible for the case of its allocation failure in nixge_hw_dma_bd_init(). Move for() loop with priv->rx_bd_v dereference under the check for its validity. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 492caffa8a1a ("net: ethernet: nixge: Add support for National Instruments XGE netdev") Signed-off-by: Yuri Karpov --- drivers/net/ethernet/ni/nixge.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c index 19d043b593cc..62320be4de5a 100644 --- a/drivers/net/ethernet/ni/nixge.c +++ b/drivers/net/ethernet/ni/nixge.c @@ -249,25 +249,26 @@ static void nixge_hw_dma_bd_release(struct net_device *ndev) struct sk_buff *skb; int i; - for (i = 0; i < RX_BD_NUM; i++) { - phys_addr = nixge_hw_dma_bd_get_addr(&priv->rx_bd_v[i], - phys); - - dma_unmap_single(ndev->dev.parent, phys_addr, - NIXGE_MAX_JUMBO_FRAME_SIZE, - DMA_FROM_DEVICE); - - skb = (struct sk_buff *)(uintptr_t) - nixge_hw_dma_bd_get_addr(&priv->rx_bd_v[i], - sw_id_offset); - dev_kfree_skb(skb); - } + if (priv->rx_bd_v) { + for (i = 0; i < RX_BD_NUM; i++) { + phys_addr = nixge_hw_dma_bd_get_addr(&priv->rx_bd_v[i], + phys); + + dma_unmap_single(ndev->dev.parent, phys_addr, + NIXGE_MAX_JUMBO_FRAME_SIZE, + DMA_FROM_DEVICE); + + skb = (struct sk_buff *)(uintptr_t) + nixge_hw_dma_bd_get_addr(&priv->rx_bd_v[i], + sw_id_offset); + dev_kfree_skb(skb); + } - if (priv->rx_bd_v) dma_free_coherent(ndev->dev.parent, sizeof(*priv->rx_bd_v) * RX_BD_NUM, priv->rx_bd_v, priv->rx_bd_p); + } if (priv->tx_skb) devm_kfree(ndev->dev.parent, priv->tx_skb); -- 2.34.1