Skip to contentSkip to conversation

infiniband: cma: fix the dev refcnt leak

PATCH In review Wang Yufen 2 participants 2 messages Nov 22, 2022 InfiniBand

lore
Share & tools
lore

Wang Yufen

author
#0 lore raw

PATCH 1/1 infiniband: cma: fix the dev refcnt leak

Syzbot report the following issue:
infiniband syj1: RDMA CMA: cma_listen_on_dev, error -98
unregister_netdevice: waiting for vlan0 to become free. Usage count = 2

The causes are as follows:

rdma_listen()
rdma_bind_addr()

    cma_acquire_dev_by_src_ip()
      cma_attach_to_dev()
        _cma_attach_to_dev()
          cma_dev_get()

cma_check_port()
<--The return value is -98, goto err

err:
<-- The error handling here is missing the operation of cma_release_dev.

To fix, add cma_release_dev to error handing.

Fixes e51060f08a61 ("IB: IP address based RDMA connection manager")
Reported-by [email protected]
---
 drivers/infiniband/core/cma.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/cma.c +3 -0
index 26d1772..3a50a8e 100644
@@ -4049,6 +4049,9 @@ int rdma_listen(struct rdma_cm_id *id, int backlog)
 	return 0;
 err:
 	id_priv->backlog = 0;
+	if (id_priv->cma_dev)
+		cma_release_dev(id_priv);
+
 	/*
 	 * All the failure paths that lead here will not allow the req_handler's
 	 * to have run.
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 33 lines · Wang Yufen

Syzbot report the following issue:
infiniband syj1: RDMA CMA: cma_listen_on_dev, error -98
unregister_netdevice: waiting for vlan0 to become free. Usage count = 2

The causes are as follows:

rdma_listen()
rdma_bind_addr()

    cma_acquire_dev_by_src_ip()
      cma_attach_to_dev()
        _cma_attach_to_dev()
          cma_dev_get()

cma_check_port()
<--The return value is -98, goto err

err:
<-- The error handling here is missing the operation of cma_release_dev.

To fix, add cma_release_dev to error handing.

Fixes e51060f08a61 ("IB: IP address based RDMA connection manager")
Reported-by [email protected]
---
 drivers/infiniband/core/cma.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/cma.c +0 -0
index 26d1772..3a50a8e 100644

drivers/infiniband/core/cma.c int rdma_listen(struct rdma_cm_id *id, int backlog) · line 4054

Quoted 6 lines
drivers/infiniband/core/cma.c +3 -0
@@ -4049,6 +4049,9 @@ int rdma_listen(struct rdma_cm_id *id, int backlog)
 	return 0;
 err:
 	id_priv->backlog = 0;
+	if (id_priv->cma_dev)
+		cma_release_dev(id_priv);
+

I'm not sure about this, the dev is released during _destroy_id()

Is something leaking an entire CM id or is there something wrong with _destroy_id() ?

Jason