From: Tuo Li <islituo@gmail.com>
To: leon@kernel.org, jgg@ziepe.ca
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
Tuo Li <islituo@gmail.com>
Subject: [PATCH] IB/mlx5: Fix a possible null-pointer dereference in set_roce_addr()
Date: Tue, 9 Dec 2025 15:23:05 +0800 [thread overview]
Message-ID: <20251209072305.3955121-1-islituo@gmail.com> (raw)
The pointer gid is checked at the beginning of set_roce_addr(). However,
if it is NULL, the function continues execution and may dereference gid
when calling mlx5_core_roce_gid_set():
return mlx5_core_roce_gid_set(..., gid->raw, ...)
This can lead to a null-pointer dereference. To prevent this, add an else
branch that return -EINVAL when gid is NULL, and remove the redundant gid
check in the IB_GID_TYPE_ROCE_UDP_ENCAP case.
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/infiniband/hw/mlx5/main.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 40284bbb45d6..d68a58d249d4 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -645,6 +645,8 @@ int set_roce_addr(struct mlx5_ib_dev *dev, u32 port_num,
ret = rdma_read_gid_l2_fields(attr, &vlan_id, &mac[0]);
if (ret)
return ret;
+ } else {
+ return -EINVAL;
}
switch (gid_type) {
@@ -653,7 +655,7 @@ int set_roce_addr(struct mlx5_ib_dev *dev, u32 port_num,
break;
case IB_GID_TYPE_ROCE_UDP_ENCAP:
roce_version = MLX5_ROCE_VERSION_2;
- if (gid && ipv6_addr_v4mapped((void *)gid))
+ if (ipv6_addr_v4mapped((void *)gid))
roce_l3_type = MLX5_ROCE_L3_TYPE_IPV4;
else
roce_l3_type = MLX5_ROCE_L3_TYPE_IPV6;
--
2.43.0
next reply other threads:[~2025-12-09 7:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 7:23 Tuo Li [this message]
2025-12-15 9:42 ` [PATCH] IB/mlx5: Fix a possible null-pointer dereference in set_roce_addr() Michael Gur
2025-12-15 10:07 ` Tuo Li
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=20251209072305.3955121-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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