* [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid
@ 2024-09-12 14:58 Mikhail Lobanov
2024-09-16 8:51 ` Leon Romanovsky
2024-09-16 17:27 ` Leon Romanovsky
0 siblings, 2 replies; 3+ messages in thread
From: Mikhail Lobanov @ 2024-09-12 14:58 UTC (permalink / raw)
To: Potnuri Bharat Teja
Cc: Mikhail Lobanov, Jason Gunthorpe, Leon Romanovsky, Roland Dreier,
Steve Wise, linux-rdma, linux-kernel, lvc-project
The lookup_atid() function can return NULL if the ATID is
invalid or does not exist in the identifier table, which
could lead to dereferencing a null pointer without a
check in the `act_establish()` and `act_open_rpl()` functions.
Add a NULL check to prevent null pointer dereferencing.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: cfdda9d76436 ("RDMA/cxgb4: Add driver for Chelsio T4 RNIC")
Signed-off-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
---
drivers/infiniband/hw/cxgb4/cm.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 040ba2224f9f..311cc5bd160c 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1223,6 +1223,11 @@ static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
ep = lookup_atid(t, atid);
+ if (!ep) {
+ pr_err("Failed to lookup atid %u\n", atid);
+ return -EINVAL;
+ }
+
pr_debug("ep %p tid %u snd_isn %u rcv_isn %u\n", ep, tid,
be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
@@ -2279,6 +2284,12 @@ static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
int ret = 0;
ep = lookup_atid(t, atid);
+
+ if (!ep) {
+ pr_err("Failed to lookup atid %u\n", atid);
+ return -EINVAL;
+ }
+
la = (struct sockaddr_in *)&ep->com.local_addr;
ra = (struct sockaddr_in *)&ep->com.remote_addr;
la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid
2024-09-12 14:58 [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid Mikhail Lobanov
@ 2024-09-16 8:51 ` Leon Romanovsky
2024-09-16 17:27 ` Leon Romanovsky
1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2024-09-16 8:51 UTC (permalink / raw)
To: Mikhail Lobanov
Cc: Potnuri Bharat Teja, Jason Gunthorpe, Roland Dreier, Steve Wise,
linux-rdma, linux-kernel, lvc-project
On Thu, Sep 12, 2024 at 10:58:39AM -0400, Mikhail Lobanov wrote:
> The lookup_atid() function can return NULL if the ATID is
> invalid or does not exist in the identifier table, which
> could lead to dereferencing a null pointer without a
> check in the `act_establish()` and `act_open_rpl()` functions.
> Add a NULL check to prevent null pointer dereferencing.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: cfdda9d76436 ("RDMA/cxgb4: Add driver for Chelsio T4 RNIC")
> Signed-off-by: Mikhail Lobanov <m.lobanov@rosalinux.ru>
> ---
> drivers/infiniband/hw/cxgb4/cm.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
I would say that this is not possible flow, but the check is harmless.
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid
2024-09-12 14:58 [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid Mikhail Lobanov
2024-09-16 8:51 ` Leon Romanovsky
@ 2024-09-16 17:27 ` Leon Romanovsky
1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2024-09-16 17:27 UTC (permalink / raw)
To: Potnuri Bharat Teja, Mikhail Lobanov
Cc: Jason Gunthorpe, Roland Dreier, Steve Wise, linux-rdma,
linux-kernel, lvc-project
On Thu, 12 Sep 2024 10:58:39 -0400, Mikhail Lobanov wrote:
> The lookup_atid() function can return NULL if the ATID is
> invalid or does not exist in the identifier table, which
> could lead to dereferencing a null pointer without a
> check in the `act_establish()` and `act_open_rpl()` functions.
> Add a NULL check to prevent null pointer dereferencing.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> [...]
Applied, thanks!
[1/1] RDMA/cxgb4: Added NULL check for lookup_atid
https://git.kernel.org/rdma/rdma/c/e766e6a92410ca
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-16 17:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-12 14:58 [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid Mikhail Lobanov
2024-09-16 8:51 ` Leon Romanovsky
2024-09-16 17:27 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox