Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2754654pxj; Mon, 31 May 2021 09:55:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6JpMa/tD4CJAQ5UqMsc7YOs30BVrEaf8J87QSJMV/QH6SuMoZf5wNY0uK3hnXCBR/0bHY X-Received: by 2002:a05:6402:3101:: with SMTP id dc1mr11686150edb.324.1622480127094; Mon, 31 May 2021 09:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622480127; cv=none; d=google.com; s=arc-20160816; b=hKLaKwbdVX0Cb/OTB1NkeAL8Zd9NGAWILSq6UpW4LYIlyY7IG5YJepJIHj57y7otsQ 4NU7e/NJO1242lrLS6mkN85ycd5Q+zc0nugefeeOpZ3bU8wre0EWXMwPlNCZGENTbXgJ gSSUSxurJMr1F5/XHx7fxIv9WzA/2ejRlN/6jvgSQeHvJd0AWjS43iVmP0Sq6dQgK/yN dMYcNOjHuOUdD2vzkBRFf6fHHoZS73SwntYxsLCKUeuDFh39s1IBmdo9L8FzLSWdMDs+ khqpdJhr2el2P9KzztIcqKmz3Kz7xTSESwH/DjTL0CFCumfnEDxsekcYS9uA9ppBr17Z a4aw== 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=StDZEViRmNuulWCtK+8gy3tEqemfo6mVNqJFm9uiu2w=; b=rj0bydWY1qVmN9VKwOI/huYcs74r7Kr41E2lixD2LJr4G/r7fpHNmoFFeK6IP+HHiD f5srgBNX6mA3tKqnoB5GVH2bguNhtYQ/TI/4ue1kncc8Fvw+2e7YxTUFUHV6YMVSpFq6 ZGwrvgxvK99UsXrT/KRQ2rVh+AxouroKQ8+y+Ddn+YWZqJCCUQbZC4jLxmZuFybkumEw ZPwisLrvCMk+iP7wf2AM9NbqkAKxud42yqew7pi9YPLJFCCbc0z1Jw4/7vSL/T3z/kX0 6hCYnXACR8ODFC4njz9pkF+WGO59hdcan4YX0NtpTFmaMpjUCBfodWS9dzLEaPFlaig4 xu2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rMK9lKEZ; 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 kl25si12935480ejc.370.2021.05.31.09.55.04; Mon, 31 May 2021 09:55:27 -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=rMK9lKEZ; 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 S232226AbhEaQxd (ORCPT + 99 others); Mon, 31 May 2021 12:53:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:51048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbhEaO7W (ORCPT ); Mon, 31 May 2021 10:59:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5ABDC61462; Mon, 31 May 2021 14:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469675; bh=DNOU7Ire3QsPKNVLBmPXwU/3EefUuQa36zGP6CxesFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMK9lKEZyG6PLWGMh8zVS4y1uzzSSPwWCmkYn4guNwtALw8v7Xbg/pw08niJ77fp/ Wkxw344hWpuo38DwH+s6vNm/OdSO05SjdxibgXhCoUIA9bL1FemAa3Nrs7CYSVMhLF YtrBaEZRsAdtGBup0w+lj6DJsYN/5uCDw8PSvVNw= 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.12 253/296] gve: Add NULL pointer checks when freeing irqs. Date: Mon, 31 May 2021 15:15:08 +0200 Message-Id: <20210531130712.266054327@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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 64192942ca53..21a5d058dab4 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