From nobody Sun Nov 24 21:44:12 2024 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 050C41684B0; Fri, 1 Nov 2024 10:34:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457277; cv=none; b=FnAErZOj1Np7yHWe4RJcKeS2RzCn6HrrPIWrVWDP0EUjfv91/2aWz2J0UfVDR/sD2LACraOP+tfqaoGK9cszUn60SB20s/O7B8/4zlse3E4ouL5ad1SnMsX4Cyhs2wyDaN/SNlIJZXJbJMHYFgoCtuVxL7ObquafgTVBO9CGJqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457277; c=relaxed/simple; bh=QjqhTr6xGprLYFtR5iTHjjkzJHwlEBt6FOAhfwylLn4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RqSmEtfxKwdn93pgw7dfLe6ENdDRfmbfsi1LHdmFYxygn2GYztTcj0Ns9Hjp0Z9iyGL/hDLSeNQUljmU42NOUm2gsTywdqoaANf19xGlojc/Of3UYWHVF+6PPXKps2Wvcyx6TrG6hfEYP7uCBAaT2ByWHWHFMZOpItSjd1fxnGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=VUXzr+Yc; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="VUXzr+Yc" Received: from pps.filterd (m0431383.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A16a0WQ015129; Fri, 1 Nov 2024 03:34:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=Y 6psovTSE4eKOOM72cSkFxeniylPnh/+fjbT5hozeNc=; b=VUXzr+Ycip3Lf3qYw t5C8yI5Hfx3F0c5La4kxVK2+I0m+TGoraB1j6NggM2gcuo/B0cV+Lh/6SkZBHMif AiIuRxK9C1vDDceN/JCaFMAVqb6D/jczKpx6wAIpxp/y3FFb01b/AtvTW8de+SiW l+ZRrpMAwDbTXErSk1ihRoveK1byL3dae6ZzWUh/bvCdrq+73fE+Mb42x6CxELeH bVDHdypL1G10Uf3l6MWLNn2AgRozSbZA3+5smek9SzoO5HVJHz1eLZYtUvoDvCC7 ag28QyxVIqm7kN6kLZHfuoOCFU9+Mn2/r4qdtf/oGMtiHKL1r8tbeUIUIugfZKZY E+zWA== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 42msuk0fn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 Nov 2024 03:34:24 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 1 Nov 2024 03:34:22 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 1 Nov 2024 03:34:22 -0700 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 36B3F3F704C; Fri, 1 Nov 2024 03:34:22 -0700 (PDT) From: Shinas Rasheed To: , CC: , , , , , , , , , "Shinas Rasheed" , Veerasenareddy Burru , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Abhijit Ayarekar" , Satananda Burla Subject: [PATCH net v1 1/3] octeon_ep: Add checks to fix double free crashes. Date: Fri, 1 Nov 2024 03:34:13 -0700 Message-ID: <20241101103416.1064930-2-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241101103416.1064930-1-srasheed@marvell.com> References: <20241101103416.1064930-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: gy_uOJfeCAfpcie5eXqPb7QJUOBdNnhl X-Proofpoint-ORIG-GUID: gy_uOJfeCAfpcie5eXqPb7QJUOBdNnhl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 Content-Type: text/plain; charset="utf-8" From: Vimlesh Kumar Add required checks to avoid double free. Crashes were observed due to the same on reset scenarios Fixes: 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support= ") Signed-off-by: Vimlesh Kumar Signed-off-by: Shinas Rasheed --- .../ethernet/marvell/octeon_ep/octep_main.c | 39 +++++++++++-------- .../net/ethernet/marvell/octeon_ep/octep_tx.c | 2 + 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/= net/ethernet/marvell/octeon_ep/octep_main.c index 549436efc204..ff72b796bd25 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c @@ -154,9 +154,11 @@ static int octep_enable_msix_range(struct octep_device= *oct) */ static void octep_disable_msix(struct octep_device *oct) { - pci_disable_msix(oct->pdev); - kfree(oct->msix_entries); - oct->msix_entries =3D NULL; + if (oct->msix_entries) { + pci_disable_msix(oct->pdev); + kfree(oct->msix_entries); + oct->msix_entries =3D NULL; + } dev_info(&oct->pdev->dev, "Disabled MSI-X\n"); } =20 @@ -496,16 +498,18 @@ static void octep_free_irqs(struct octep_device *oct) { int i; =20 - /* First few MSI-X interrupts are non queue interrupts; free them */ - for (i =3D 0; i < CFG_GET_NON_IOQ_MSIX(oct->conf); i++) - free_irq(oct->msix_entries[i].vector, oct); - kfree(oct->non_ioq_irq_names); - - /* Free IRQs for Input/Output (Tx/Rx) queues */ - for (i =3D CFG_GET_NON_IOQ_MSIX(oct->conf); i < oct->num_irqs; i++) { - irq_set_affinity_hint(oct->msix_entries[i].vector, NULL); - free_irq(oct->msix_entries[i].vector, - oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]); + if (oct->msix_entries) { + /* First few MSI-X interrupts are non queue interrupts; free them */ + for (i =3D 0; i < CFG_GET_NON_IOQ_MSIX(oct->conf); i++) + free_irq(oct->msix_entries[i].vector, oct); + kfree(oct->non_ioq_irq_names); + + /* Free IRQs for Input/Output (Tx/Rx) queues */ + for (i =3D CFG_GET_NON_IOQ_MSIX(oct->conf); i < oct->num_irqs; i++) { + irq_set_affinity_hint(oct->msix_entries[i].vector, NULL); + free_irq(oct->msix_entries[i].vector, + oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]); + } } netdev_info(oct->netdev, "IRQs freed\n"); } @@ -635,8 +639,10 @@ static void octep_napi_delete(struct octep_device *oct) =20 for (i =3D 0; i < oct->num_oqs; i++) { netdev_dbg(oct->netdev, "Deleting NAPI on Q-%d\n", i); - netif_napi_del(&oct->ioq_vector[i]->napi); - oct->oq[i]->napi =3D NULL; + if (oct->oq[i]->napi) { + netif_napi_del(&oct->ioq_vector[i]->napi); + oct->oq[i]->napi =3D NULL; + } } } =20 @@ -666,7 +672,8 @@ static void octep_napi_disable(struct octep_device *oct) =20 for (i =3D 0; i < oct->num_oqs; i++) { netdev_dbg(oct->netdev, "Disabling NAPI on Q-%d\n", i); - napi_disable(&oct->ioq_vector[i]->napi); + if (oct->oq[i]->napi) + napi_disable(&oct->ioq_vector[i]->napi); } } =20 diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c b/drivers/ne= t/ethernet/marvell/octeon_ep/octep_tx.c index 06851b78aa28..157bf489ae19 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c @@ -323,6 +323,8 @@ void octep_free_iqs(struct octep_device *oct) int i; =20 for (i =3D 0; i < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); i++) { + if (!oct->iq[i]) + continue; octep_free_iq(oct->iq[i]); dev_dbg(&oct->pdev->dev, "Successfully destroyed IQ(TxQ)-%d.\n", i); --=20 2.25.1 From nobody Sun Nov 24 21:44:12 2024 Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08C3418953D; Fri, 1 Nov 2024 10:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457279; cv=none; b=cKFJptRHBcfio2dV1EKiIj7rRlqIJVY4hOCJccf5XrCZpeJt5ZbW63F9/N/umPm2LXIUEqarC2EwgZ1UUSrDutimG44nsWLFnlWlbPh+/bbDhWoB9w8sTMaJmbVeLKNopOpQp/6MM4RA7GFuZKk3rixucXAB/Ny7u2ytTcjfUW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457279; c=relaxed/simple; bh=7CEh2pgSVWlTpnqxUxjDRbI8zmDr6/bLH7zkmX+pNnc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pCOHfL2tIsO662Yjy6EqDDh9Z3N2sXfgoLZ9drp2FPkGGCcv36Zo1iI/tuFrMYA7qLVP0xWZM5dvFKvQ3ohDKDuIl845Xnrg7XJtiBcsJkjw+/D334Xibf27DwGzdmQX+lNY3QwXHavSQ0apa3JoA4qksC99ILZs6b7ikBXvkU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=Lb0Tfyel; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="Lb0Tfyel" Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A16rYv3025517; Fri, 1 Nov 2024 03:34:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=z lRbPW5YCEDK1yec4ABq8Ou+8EXNk0quIShm9NOr+Qw=; b=Lb0TfyelmFRpfMt2C 6Ab26Qwx4Miwd1YnUTH2fQzBrsl4MR4DmdAiVM9j1yp4ekxwn0tI+6006okl3Jzl dojaX/VVpzgPkWD8ZDy2hdPVAaFl4c5zvQOkoK+KEXL7IAcIMBSMpGiV3ePZrBrU foRH/PiJipMDPPylhEXRaaGkmk9Askegel50r5fK4ET21ObGc37jihJdksOIYxEo p9vgZ7rIlHZUmiJhxb63EGf+nCnQTjBdMzbJf/8wASjBN9oZfz72oEIrXu/NNxDg tiHFxpMJ2iPvfkwSNotxdvBW0g49BtCZ7impM4/T9tYYTBuDKbMRS2qIUbvHi7c4 ViJhA== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 42mt440ddh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 Nov 2024 03:34:26 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 1 Nov 2024 03:34:25 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 1 Nov 2024 03:34:25 -0700 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 9689A3F704C; Fri, 1 Nov 2024 03:34:24 -0700 (PDT) From: Shinas Rasheed To: , CC: , , , , , , , , , "Shinas Rasheed" , Veerasenareddy Burru , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Satananda Burla , Abhijit Ayarekar Subject: [PATCH net v1 2/3] octeon_ep: add checks to fix NULL pointer dereferences Date: Fri, 1 Nov 2024 03:34:14 -0700 Message-ID: <20241101103416.1064930-3-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241101103416.1064930-1-srasheed@marvell.com> References: <20241101103416.1064930-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: xKpQqWP8Z4NjEe2gl7_zkc2Or2Fo4AJN X-Proofpoint-ORIG-GUID: xKpQqWP8Z4NjEe2gl7_zkc2Or2Fo4AJN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 Content-Type: text/plain; charset="utf-8" Add Checks to avoid NULL pointer references that might happen in rare and corner cases Fixes: 6a610a46bad1 ("octeon_ep: add support for ndo ops") Fixes: 1f2c2d0cee02 ("octeon_ep: add hardware configuration APIs") Fixes: 0807dc76f3bf ("octeon_ep: support Octeon CN10K devices") Signed-off-by: Shinas Rasheed --- drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c | 9 ++++++++- drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c | 9 ++++++++- drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c b/drive= rs/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c index b5805969404f..b87336b2e4b9 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c @@ -617,7 +617,14 @@ static irqreturn_t octep_rsvd_intr_handler_cn93_pf(voi= d *dev) static irqreturn_t octep_ioq_intr_handler_cn93_pf(void *data) { struct octep_ioq_vector *vector =3D (struct octep_ioq_vector *)data; - struct octep_oq *oq =3D vector->oq; + struct octep_oq *oq; + + if (!vector) + return IRQ_HANDLED; + oq =3D vector->oq; + + if (!oq || !(oq->napi)) + return IRQ_HANDLED; =20 napi_schedule_irqoff(oq->napi); return IRQ_HANDLED; diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c b/drive= rs/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c index 5de0b5ecbc5f..65a8dc1d492b 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c @@ -638,7 +638,14 @@ static irqreturn_t octep_rsvd_intr_handler_cnxk_pf(voi= d *dev) static irqreturn_t octep_ioq_intr_handler_cnxk_pf(void *data) { struct octep_ioq_vector *vector =3D (struct octep_ioq_vector *)data; - struct octep_oq *oq =3D vector->oq; + struct octep_oq *oq; + + if (!vector) + return IRQ_HANDLED; + oq =3D vector->oq; + + if (!oq || !(oq->napi)) + return IRQ_HANDLED; =20 napi_schedule_irqoff(oq->napi); return IRQ_HANDLED; diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/= net/ethernet/marvell/octeon_ep/octep_main.c index ff72b796bd25..dc783c568e2c 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c @@ -1016,6 +1016,9 @@ static void octep_get_stats64(struct net_device *netd= ev, struct octep_iq *iq =3D oct->iq[q]; struct octep_oq *oq =3D oct->oq[q]; =20 + if (!iq || !oq) + return; + tx_packets +=3D iq->stats.instr_completed; tx_bytes +=3D iq->stats.bytes_sent; rx_packets +=3D oq->stats.packets; --=20 2.25.1 From nobody Sun Nov 24 21:44:12 2024 Received: from mx0a-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F04A0198A38; Fri, 1 Nov 2024 10:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.148.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457279; cv=none; b=S/7vVCmt2qnOOyRvxSeJs07yb4ppquglMYAGRDdYe4ddiHmen6WdCM78V2H2uNdyuTiZLztUhi7fK9AI9joktxXI3EUAUi1wGfrID0Y8GDHD2jOf5lAC1gTd/f9xgcsobJz3dwe0SiTTbyfFnITB0659bwgkcf/ngPgYNaDx0P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457279; c=relaxed/simple; bh=4gVyFl3aZzu1qejuO+Sxyt3R0RGE2BEjyOzgiP3k/b8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k0HiZasyVG/XDGKZYJCbEbrBlDS0Dv2Ca/miW2EDWoV9jKE0+HjzZEGoaVzi5WiO46iz/ApOSM/jeXScpzY8qxsjJKcDqsEK+U2D83jiL8NWrJK6i4WhGikYNjNT5CIK5IfnmvacGkf1DXM9zWpnx4eeZ4cHyvWPMf1JoVDN92s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=PsAV+hAE; arc=none smtp.client-ip=67.231.148.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="PsAV+hAE" Received: from pps.filterd (m0431384.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A19DP52009586; Fri, 1 Nov 2024 03:34:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=n JVtgcRhOVSaV5xJsgcnaEkB84NlO9i8LlP+KvEcN6E=; b=PsAV+hAEocm7sMuYw oGGM0dUNleRqJOaM4sjdbO4FUGTU8NFJdP6xpq845EUakvud0ICRs29LzOS/9xxg XPA8vVSIK1ZW85+fqGhz51xsNiptpe/ipAKc/U3rgC30PiGtdx1BhCkw3f70VNJ2 j1QFWGwpcYVLmlxKxvFNrNRM+QgS4/sHjxX/YofF94+LjcsaBeAxLu/WkKC+E3vD +K1yBGNY2vY0BNuZaEwuFyknzTu0IVejYKDoTP/sQ92+YUoCgR18oNnD4F5sMXVw uVvykEf66yJxf+6ZtF5wCN8aOPb4EVrI2SxFLWW2AHqwcKVT7QepSJm+TVd6EgX5 niyUQ== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 42mv5ng4a6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 01 Nov 2024 03:34:29 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 1 Nov 2024 03:34:27 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 1 Nov 2024 03:34:27 -0700 Received: from ubuntu-PowerEdge-T110-II.sclab.marvell.com (unknown [10.106.27.86]) by maili.marvell.com (Postfix) with ESMTP id 1F9B23F704C; Fri, 1 Nov 2024 03:34:27 -0700 (PDT) From: Shinas Rasheed To: , CC: , , , , , , , , , "Shinas Rasheed" , Veerasenareddy Burru , Satananda Burla , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski Subject: [PATCH net v1 3/3] octeon_ep_vf: add checks to fix NULL pointer dereferences Date: Fri, 1 Nov 2024 03:34:15 -0700 Message-ID: <20241101103416.1064930-4-srasheed@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241101103416.1064930-1-srasheed@marvell.com> References: <20241101103416.1064930-1-srasheed@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: iVv9dbxbxEkmGQNqyZJxTHocx3_7d_GN X-Proofpoint-GUID: iVv9dbxbxEkmGQNqyZJxTHocx3_7d_GN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 Content-Type: text/plain; charset="utf-8" Add checks to avoid NULL pointer dereferences that might happen in rare and corner cases Fixes: cb7dd712189f ("octeon_ep_vf: Add driver framework and device initial= ization") Signed-off-by: Shinas Rasheed --- .../ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c | 8 +++++++- .../ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c | 12 +++++++++++- .../ethernet/marvell/octeon_ep_vf/octep_vf_main.c | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c b/dr= ivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c index 88937fce75f1..f1b7eda3fa42 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c @@ -273,8 +273,14 @@ static irqreturn_t octep_vf_ioq_intr_handler_cn93(void= *data) struct octep_vf_oq *oq; u64 reg_val; =20 - oct =3D vector->octep_vf_dev; + if (!vector) + return IRQ_HANDLED; + oq =3D vector->oq; + if (!oq) + return IRQ_HANDLED; + + oct =3D vector->octep_vf_dev; /* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */ if (oq->q_no =3D=3D 0) { reg_val =3D octep_vf_read_csr64(oct, CN93_VF_SDP_R_MBOX_PF_VF_INT(0)); diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c b/dr= ivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c index 1f79dfad42c6..31c0d7c0492a 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c @@ -284,8 +284,14 @@ static irqreturn_t octep_vf_ioq_intr_handler_cnxk(void= *data) struct octep_vf_oq *oq; u64 reg_val; =20 - oct =3D vector->octep_vf_dev; + if (!vector) + return IRQ_HANDLED; + oq =3D vector->oq; + if (!oq) + return IRQ_HANDLED; + + oct =3D vector->octep_vf_dev; /* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */ if (oq->q_no =3D=3D 0) { reg_val =3D octep_vf_read_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0)); @@ -294,6 +300,10 @@ static irqreturn_t octep_vf_ioq_intr_handler_cnxk(void= *data) octep_vf_write_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0), reg_val); } } + + if (!(oq->napi)) + return IRQ_HANDLED; + napi_schedule_irqoff(oq->napi); return IRQ_HANDLED; } diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c b/dr= ivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c index 7e6771c9cdbb..79d9ffd593eb 100644 --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c @@ -790,6 +790,9 @@ static void octep_vf_get_stats64(struct net_device *net= dev, struct octep_vf_iq *iq =3D oct->iq[q]; struct octep_vf_oq *oq =3D oct->oq[q]; =20 + if (!iq || !oq) + return; + tx_packets +=3D iq->stats.instr_completed; tx_bytes +=3D iq->stats.bytes_sent; rx_packets +=3D oq->stats.packets; --=20 2.25.1