From: Kery Qi <qikeyu2017@gmail.com>
To: tariqt@nvidia.com
Cc: linux-kernel@vger.kernel.org, Kery Qi <qikeyu2017@gmail.com>
Subject: [PATCH] mlx4: Fix out of bounds access in __mlx4_register_mac()
Date: Thu, 8 Jan 2026 00:21:26 +0800 [thread overview]
Message-ID: <20260107162126.1564-1-qikeyu2017@gmail.com> (raw)
__mlx4_register_mac() searches for a free MAC table slot using
`free = -1`. If the requested MAC is not found and there is no
free entry (all refs[] are non-zero), the scan may finish with
`free` still -1, yet the code later uses it as an array index
(entries/refs/is_dup), causing an out-of-bounds access.
Fix this by checking `free < 0` after the scan (and mf-bond slot
selection) and returning an error before touching the arrays.
This matches the same bug pattern fixed by CVE-2010-5332 in
mlx4_register_mac()/mlx4_register_vlan().
Signed-off-by: Kery Qi <qikeyu2017@gmail.com>
---
drivers/net/ethernet/mellanox/mlx4/port.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
index e3d0b13c1610..ff1cce138357 100644
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -267,6 +267,11 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
if (need_mf_bond && can_mf_bond)
free = free_for_dup;
+ if (free < 0) {
+ err = -ENOMEM;
+ goto out;
+ }
+
mlx4_dbg(dev, "Free MAC index is %d\n", free);
if (table->total == table->max) {
--
2.34.1
reply other threads:[~2026-01-07 16:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260107162126.1564-1-qikeyu2017@gmail.com \
--to=qikeyu2017@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tariqt@nvidia.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