diff mbox series

[22/31] rdma/siw: let siw_listen_address() call siw_cep_set_inuse() early

Message ID 33abff2233b36a51e468d691cb4327d0294d2734.1620343860.git.metze@samba.org (mailing list archive)
State Changes Requested
Headers show
Series rdma/siw: fix a lot of deadlocks and use after free bugs | expand

Commit Message

Stefan Metzmacher May 6, 2021, 11:36 p.m. UTC
We should protect the whole section after siw_cep_alloc().

Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Cc: Bernard Metzler <bmt@zurich.ibm.com>
Cc: linux-rdma@vger.kernel.org
---
 drivers/infiniband/sw/siw/siw_cm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Bernard Metzler May 11, 2021, 12:42 p.m. UTC | #1
-----"Stefan Metzmacher" <metze@samba.org> wrote: -----

>To: "Bernard Metzler" <bmt@zurich.ibm.com>
>From: "Stefan Metzmacher" <metze@samba.org>
>Date: 05/07/2021 01:39AM
>Cc: linux-rdma@vger.kernel.org, "Stefan Metzmacher" <metze@samba.org>
>Subject: [EXTERNAL] [PATCH 22/31] rdma/siw: let siw_listen_address()
>call siw_cep_set_inuse() early
>
>We should protect the whole section after siw_cep_alloc().
>
>Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
>Signed-off-by: Stefan Metzmacher <metze@samba.org>
>Cc: Bernard Metzler <bmt@zurich.ibm.com>
>Cc: linux-rdma@vger.kernel.org
>---
> drivers/infiniband/sw/siw/siw_cm.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/infiniband/sw/siw/siw_cm.c
>b/drivers/infiniband/sw/siw/siw_cm.c
>index fe6f7bb4d615..09ae7f7ca82a 100644
>--- a/drivers/infiniband/sw/siw/siw_cm.c
>+++ b/drivers/infiniband/sw/siw/siw_cm.c
>@@ -1920,6 +1920,8 @@ int siw_create_listen(struct iw_cm_id *id, int
>backlog)
> 	if (!cep)
> 		return -ENOMEM;
> 
>+	siw_cep_set_inuse(cep);
>+
> 	rv = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
> 	if (rv < 0) {
> 		siw_dbg(id->device, "sock_create error: %d\n", rv);
>@@ -2014,13 +2016,12 @@ int siw_create_listen(struct iw_cm_id *id,
>int backlog)
> 
> 	siw_dbg(id->device, "Listen at laddr %pISp\n", &id->local_addr);
> 
>+	siw_cep_set_free(cep);
> 	return 0;
> 
> error:
> 	siw_dbg(id->device, "failed: %d\n", rv);
> 
>-	siw_cep_set_inuse(cep);
>-
> 	if (cep->cm_id) {
> 		cep->cm_id->rem_ref(cep->cm_id);
> 		cep->cm_id = NULL;
>-- 
>2.25.1
>
>
Agreed, makes it easier to read.

Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
index fe6f7bb4d615..09ae7f7ca82a 100644
--- a/drivers/infiniband/sw/siw/siw_cm.c
+++ b/drivers/infiniband/sw/siw/siw_cm.c
@@ -1920,6 +1920,8 @@  int siw_create_listen(struct iw_cm_id *id, int backlog)
 	if (!cep)
 		return -ENOMEM;
 
+	siw_cep_set_inuse(cep);
+
 	rv = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
 	if (rv < 0) {
 		siw_dbg(id->device, "sock_create error: %d\n", rv);
@@ -2014,13 +2016,12 @@  int siw_create_listen(struct iw_cm_id *id, int backlog)
 
 	siw_dbg(id->device, "Listen at laddr %pISp\n", &id->local_addr);
 
+	siw_cep_set_free(cep);
 	return 0;
 
 error:
 	siw_dbg(id->device, "failed: %d\n", rv);
 
-	siw_cep_set_inuse(cep);
-
 	if (cep->cm_id) {
 		cep->cm_id->rem_ref(cep->cm_id);
 		cep->cm_id = NULL;