From: Shinas Rasheed <srasheed@marvell.com>
To: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <hgani@marvell.com>, <sedara@marvell.com>, <vimleshk@marvell.com>,
<wizhao@redhat.com>, <horms@kernel.org>, <kongyen@redhat.com>,
<pabeni@redhat.com>, <kheib@redhat.com>, <mschmidt@redhat.com>,
"Shinas Rasheed" <srasheed@marvell.com>,
Veerasenareddy Burru <vburru@marvell.com>,
Satananda Burla <sburla@marvell.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>
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 [thread overview]
Message-ID: <20241101103416.1064930-4-srasheed@marvell.com> (raw)
In-Reply-To: <20241101103416.1064930-1-srasheed@marvell.com>
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 initialization")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
.../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/drivers/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;
- oct = vector->octep_vf_dev;
+ if (!vector)
+ return IRQ_HANDLED;
+
oq = vector->oq;
+ if (!oq)
+ return IRQ_HANDLED;
+
+ oct = vector->octep_vf_dev;
/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */
if (oq->q_no == 0) {
reg_val = 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/drivers/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;
- oct = vector->octep_vf_dev;
+ if (!vector)
+ return IRQ_HANDLED;
+
oq = vector->oq;
+ if (!oq)
+ return IRQ_HANDLED;
+
+ oct = vector->octep_vf_dev;
/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */
if (oq->q_no == 0) {
reg_val = 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/drivers/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 *netdev,
struct octep_vf_iq *iq = oct->iq[q];
struct octep_vf_oq *oq = oct->oq[q];
+ if (!iq || !oq)
+ return;
+
tx_packets += iq->stats.instr_completed;
tx_bytes += iq->stats.bytes_sent;
rx_packets += oq->stats.packets;
--
2.25.1
prev parent reply other threads:[~2024-11-01 10:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-01 10:34 [PATCH net v1 0/3] Double free fixes and NULL pointer checks Shinas Rasheed
2024-11-01 10:34 ` [PATCH net v1 1/3] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
2024-11-01 10:34 ` [PATCH net v1 2/3] octeon_ep: add checks to fix NULL pointer dereferences Shinas Rasheed
2024-11-05 12:25 ` Simon Horman
2024-11-01 10:34 ` Shinas Rasheed [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241101103416.1064930-4-srasheed@marvell.com \
--to=srasheed@marvell.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hgani@marvell.com \
--cc=horms@kernel.org \
--cc=kheib@redhat.com \
--cc=kongyen@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sburla@marvell.com \
--cc=sedara@marvell.com \
--cc=vburru@marvell.com \
--cc=vimleshk@marvell.com \
--cc=wizhao@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®