[PATCH] RDMA/cxgb4: Added NULL check for lookup_atid

Mikhail Lobanov posted 1 patch 2 months, 2 weeks ago
drivers/infiniband/hw/cxgb4/cm.c | 11 +++++++++++
1 file changed, 11 insertions(+)
[PATCH] RDMA/cxgb4: Added NULL check for lookup_atid
Posted by Mikhail Lobanov 2 months, 2 weeks ago
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
Re: [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid
Posted by Leon Romanovsky 2 months, 2 weeks ago
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>
Re: [PATCH] RDMA/cxgb4: Added NULL check for lookup_atid
Posted by Leon Romanovsky 2 months, 2 weeks ago
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