Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2711716pxj; Mon, 31 May 2021 08:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvLIxf3LhynWCLP/EdNQCI6HIthQBlFMr3bbpa96ZtspZwDNCzc0cF8Lr+i8htdwz8X9X6 X-Received: by 2002:a05:6402:5216:: with SMTP id s22mr25872126edd.232.1622476282771; Mon, 31 May 2021 08:51:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622476282; cv=none; d=google.com; s=arc-20160816; b=Loxwr19QYOaIpm+Ii0+jk+zhZLKxd85DliKmFC4fOSCrokCSBUjvdJIf5+/Z8Y6swf 65ZK3sMkeTJJiXYNFXxGeZFU7dZoyyNP6507oN1iP6tl8Q3b8aotk9KG4ITzdWL7sGwl Hx23ndHDKxGz+GqAo5EUT7i97Hr/+yrYTzzWIKyt0KJ/voyJKs4rQyVthIg8oV6mIz8W IGdXOmfx9ChHE/zE3H3fWUy7bVgj/nHYIgB2mECFnu9+c9MVPJJTwWGxNBOR3tdExn/L N29vVUrZH3MpwwuQqvog2JV0P/Poov7Lr2cEwYoh0bb1ch/btZQIU6doGP178cjK78hA kOQw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nbilSiFNetl6a5CFssRc/DuUopLeWMf1So3QHdr6sq8=; b=cT9h3+ODQTUTmz11VNX3Lq35Vk3y2VgaTqNSbz2tJJGrefvWhY0/i0wYmZj8JtC9QB LY7r2QRUcpc8GE4wlyT6Utx3eLuRnTpUeQd1pTwKySmsz0BjOXvvAvJA8na8NNJE2C2s VnIy4HoPQ2EDQRPBbPceVUDeEbUzXpYhEmKFjqE7aT6Aywr3HbX6A7iagpCI3IniC3T9 WxueJWXCgggJWi0JrizOF7MRr5Coql5F3r5EQ6vfUIXd9scDnF2th2oLJlmK9LxXQpQb Hhwt9JL92pFPF8T+oDsd6wMAnybFP0mgZ1RuetRzhZpUXE9yx6G5T62rkTfQf0JWhxjz PG8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BOezKMtD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si11615916edb.587.2021.05.31.08.51.00; Mon, 31 May 2021 08:51:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BOezKMtD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233946AbhEaPtc (ORCPT + 99 others); Mon, 31 May 2021 11:49:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:56238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231576AbhEaO1c (ORCPT ); Mon, 31 May 2021 10:27:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5989C61A36; Mon, 31 May 2021 13:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468858; bh=/6Zf6gd127aJEt9MOKlPzntrXz2WBMQtBzrAtlBIp6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BOezKMtDUMpDGbuexgAx/RRhBni3560zMgeXmpRbjvnhkcq2riKfjlln9Lv40utEk KtJp8tQNHoGlpz25empA7QAAg8APBIczA3BgzIhCbbvjy0MJ3DXb2T8bv+mAiYucne m6kzFLDRIQPU3ezYQpJ+ZYpjx2BRwzvvZmyk36Tk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Awogbemila , Willem de Brujin , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 154/177] gve: Add NULL pointer checks when freeing irqs. Date: Mon, 31 May 2021 15:15:11 +0200 Message-Id: <20210531130653.242254816@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Awogbemila [ Upstream commit 5218e919c8d06279884aa0baf76778a6817d5b93 ] When freeing notification blocks, we index priv->msix_vectors. If we failed to allocate priv->msix_vectors (see abort_with_msix_vectors) this could lead to a NULL pointer dereference if the driver is unloaded. Fixes: 893ce44df565 ("gve: Add basic driver framework for Compute Engine Virtual NIC") Signed-off-by: David Awogbemila Acked-by: Willem de Brujin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/google/gve/gve_main.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 9c74251f9b6a..77e79d2939ba 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -242,20 +242,22 @@ static void gve_free_notify_blocks(struct gve_priv *priv) { int i; - /* Free the irqs */ - for (i = 0; i < priv->num_ntfy_blks; i++) { - struct gve_notify_block *block = &priv->ntfy_blocks[i]; - int msix_idx = i; - - irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, - NULL); - free_irq(priv->msix_vectors[msix_idx].vector, block); + if (priv->msix_vectors) { + /* Free the irqs */ + for (i = 0; i < priv->num_ntfy_blks; i++) { + struct gve_notify_block *block = &priv->ntfy_blocks[i]; + int msix_idx = i; + + irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, + NULL); + free_irq(priv->msix_vectors[msix_idx].vector, block); + } + free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); } dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks), priv->ntfy_blocks, priv->ntfy_block_bus); priv->ntfy_blocks = NULL; - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); pci_disable_msix(priv->pdev); kvfree(priv->msix_vectors); priv->msix_vectors = NULL; -- 2.30.2