Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2680301pxj; Mon, 31 May 2021 08:07:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmNg36ebJrJgW6FwCjlWc56CVQHh7xUOzf/9jKmPlFWSbS04rMoTzj97FmZ3C6JOSXhm92 X-Received: by 2002:a05:6402:1111:: with SMTP id u17mr26162282edv.87.1622473620413; Mon, 31 May 2021 08:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473620; cv=none; d=google.com; s=arc-20160816; b=hE7tucc9ggAQNbPPyBMRyW/SB/N/nlyPlKvoaZHP+41qG7Je+yaZqrUqNW3whQPcxv 2+jZRL7JtHTKXM2delIffsb+NakmwVLSudPjhqB7cIhDXZnrnGvExmOUEAvjcVMZsFic hMFI/OxCmW5Kg7i1ghDUzDVocrHXFYuvbTiCEcf0xrlk8yUkGMdkaBj5faPqVOT1+ndj XNVrmTOSGQu47JdMMylyLBwbIF5wNJ1xjrzEOu6R4ViGKKDB/qE2MO1OHPkXRLyHEJwN ZopaSbyrJHWcYN0LwUTmMGykspOA/4xHkV7tWjyBTpZXo6flz4QZE9gi8t5k4pCq8LVX kgJQ== 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=qk0gLK0geNwG3nvzq98umx9mqXitU0WlcWQM0XXiP5w=; b=OzCV6ZpqfePdL8Mx4GZu1qIxx2qBC91P8qmAX34GvySdVUEt9TCvtVC9iDtS7aBz2t FiUUUCvNx116Dp1gAPqTTZUdBpg8E6NF5cKw6GL28LQvZXWft0+Jovql0gDeakPE+KdE ufByFlLyJQUxN7Ch3TnOen9c7zpChuZ39WGWr3sIsWjFo60abVSuRf80NBkcd29qt1eI EU3ueXRn234S5SlIhU23XZC8Z21zUBDLKNUfcqh6YS6cejGPNNNLgBh3Hx7Pqj+/FIpH WErs5yM9x3/ryf5gwnvwifol5ZG667euHNtGGol7Qd01X3sOQaFcKQoypQ1IwnFQ1+TV MBwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mxe3u8JP; 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 lt15si3166637ejb.536.2021.05.31.08.06.37; Mon, 31 May 2021 08:07:00 -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=Mxe3u8JP; 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 S232179AbhEaPHX (ORCPT + 99 others); Mon, 31 May 2021 11:07:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:40258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232244AbhEaOHg (ORCPT ); Mon, 31 May 2021 10:07:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 248186140A; Mon, 31 May 2021 13:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468372; bh=vf2R1pwzOzf+f1ro2bIxCj3uHCxoj+ts+iVokRCQiOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mxe3u8JPKX6bC7D9ODe2FxuRGZL4jH21YpWbx2zZ0KRBw/pGTdMwoEP03X6ysLgH6 w2RxVsXBd0n7krXSqFzZqB99Ur1hujn8VTzJ1QSYAv2brDK1jRbrMDJWs21uaEeJ/f +8LIDfBVMJr7j0Pxcle+5UVxyeERIzAUTMDj6b6k= 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.10 218/252] gve: Add NULL pointer checks when freeing irqs. Date: Mon, 31 May 2021 15:14:43 +0200 Message-Id: <20210531130705.417386172@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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 a8fcf1227391..839102ea6aa1 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -301,20 +301,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