From: cxxz16 <990492108@qq.com>
To: sgoutham@marvell.com, gakula@marvell.com, sbhatta@marvell.com,
hkelam@marvell.com, bbhushan2@marvell.com,
netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, andrew+netdev@lunn.ch,
linux-kernel@vger.kernel.org, cxxz16 <990492108@qq.com>
Subject: [Patch next] octeontx2-pf: fix potential double free in rvu_rep_create()
Date: Sun, 13 Apr 2025 14:16:39 +0800 [thread overview]
Message-ID: <tencent_20ED8A5A99ECCFE616B18F17D8056B5AF707@qq.com> (raw)
In rvu_rep_create(), the netdev is allocated via alloc_etherdev()
and assigned to rep->netdev. This rep structure is then stored
in the priv->reps array indexed by rep_id.
If either rvu_rep_devlink_port_register() or register_netdev() fails,
the function frees ndev using free_netdev(ndev) before jumping to
the 'exit:' label. However, in the 'exit:' section, the function
iterates over priv->reps[] and again frees rep->netdev, which points
to the same ndev.
This results in a potential double free of the same netdev pointer,
which can cause memory corruption or crashes.
To fix this, avoid calling free_netdev(ndev) before jumping to 'exit:'.
The cleanup logic at 'exit:' should handle the freeing safely.
Signed-off-by: cxxz16 <990492108@qq.com>
---
drivers/net/ethernet/marvell/octeontx2/nic/rep.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
index 04e08e06f30f..de9a50f2fc39 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
@@ -681,7 +681,6 @@ int rvu_rep_create(struct otx2_nic *priv, struct netlink_ext_ack *extack)
eth_hw_addr_random(ndev);
err = rvu_rep_devlink_port_register(rep);
if (err) {
- free_netdev(ndev);
goto exit;
}
@@ -691,7 +690,6 @@ int rvu_rep_create(struct otx2_nic *priv, struct netlink_ext_ack *extack)
NL_SET_ERR_MSG_MOD(extack,
"PFVF representor registration failed");
rvu_rep_devlink_port_unregister(rep);
- free_netdev(ndev);
goto exit;
}
--
2.34.1
next reply other threads:[~2025-04-13 6:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-13 6:16 cxxz16 [this message]
2025-04-15 6:03 ` Abdun Nihaal
2025-04-15 7:32 ` Markus Elfring
2025-04-15 13:44 ` Abdun Nihaal
2025-04-15 6:55 ` [Patch] " Markus Elfring
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=tencent_20ED8A5A99ECCFE616B18F17D8056B5AF707@qq.com \
--to=990492108@qq.com \
--cc=andrew+netdev@lunn.ch \
--cc=bbhushan2@marvell.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=hkelam@marvell.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.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®