2023-02-01 17:21:33

by Nikita Zhandarovich

[permalink] [raw]
Subject: [PATCH] RDMA/cxgb4: add null-ptr-check after ip_dev_find()

ip_dev_find() may return NULL and assign it to pdev which is
dereferenced later.
Fix this by checking the return value of ip_dev_find() for NULL
similar to the way it is done with other instances of said function.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 1cab775c3e75 ("RDMA/cxgb4: Fix LE hash collision bug for passive open connection")
Signed-off-by: Nikita Zhandarovich <[email protected]>
---
drivers/infiniband/hw/cxgb4/cm.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index c16017f6e8db..07d0bafb7ac5 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -4151,6 +4151,10 @@ static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)

if (neigh->dev->flags & IFF_LOOPBACK) {
pdev = ip_dev_find(&init_net, iph->daddr);
+ if (!pdev) {
+ pr_err("%s - failed to find device!\n", __func__);
+ goto free_dst;
+ }
e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
pdev, 0);
pi = (struct port_info *)netdev_priv(pdev);
--
2.25.1



2023-02-02 08:18:20

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH] RDMA/cxgb4: add null-ptr-check after ip_dev_find()


On Wed, 01 Feb 2023 09:21:03 -0800, Nikita Zhandarovich wrote:
> ip_dev_find() may return NULL and assign it to pdev which is
> dereferenced later.
> Fix this by checking the return value of ip_dev_find() for NULL
> similar to the way it is done with other instances of said function.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> [...]

Applied, thanks!

[1/1] RDMA/cxgb4: add null-ptr-check after ip_dev_find()
https://git.kernel.org/rdma/rdma/c/ef42520240aacf

Best regards,
--
Leon Romanovsky <[email protected]>