Skip to contentSkip to conversation

net: tipc: fix possible refcount leak in tipc_sk_create()

PATCH In review Hangyu Hua 2 participants 3 messages Jun 29, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 net: tipc: fix possible refcount leak in tipc_sk_create()

sk need to be free when tipc_sk_insert fails. While tipc_sk_insert is hard to fail, it's better to fix this.

Fixes 07f6c4bc048a ("tipc: convert tipc reference table to use generic rhashtable")
---
 net/tipc/socket.c | 1 +
 1 file changed, 1 insertion(+)
net/tipc/socket.c +1 -0
index 17f8c523e33b..43509c7e90fc 100644
@@ -502,6 +502,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
 	sock_init_data(sock, sk);
 	tipc_set_sk_state(sk, TIPC_OPEN);
 	if (tipc_sk_insert(tsk)) {
+		sk_free(sk);
 		pr_warn("Socket create failed; port number exhausted\n");
 		return -EINVAL;
 	}
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines

sk need to be free when tipc_sk_insert fails. While tipc_sk_insert is hard to fail, it's better to fix this.

Incorrect English grammar. You should use a simple comment in changelog, for example: "Free sk in case tipc_sk_insert() fails."

Quoted 21 lines
Fixes 07f6c4bc048a ("tipc: convert tipc reference table to use generic rhashtable")
---
 net/tipc/socket.c | 1 +
 1 file changed, 1 insertion(+)
net/tipc/socket.c +1 -1
index 17f8c523e33b..43509c7e90fc 100644
@@ -502,6 +502,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
 	sock_init_data(sock, sk);
 	tipc_set_sk_state(sk, TIPC_OPEN);
 	if (tipc_sk_insert(tsk)) {
+		sk_free(sk);
 		pr_warn("Socket create failed; port number exhausted\n");
 		return -EINVAL;
 	}
--

2.25.1

author
#2 lore raw
Quoted 3 lines · Tung Quang Nguyen
Quoted 2 lines

sk need to be free when tipc_sk_insert fails. While tipc_sk_insert is hard to fail, it's better to fix this.

Incorrect English grammar. You should use a simple comment in changelog, for example: "Free sk in case tipc_sk_insert() fails."

Thanks a lot. I will fix this then send a v2.

Hangyu.

Quoted 22 lines
Quoted 21 lines
Fixes 07f6c4bc048a ("tipc: convert tipc reference table to use generic rhashtable")
---
  net/tipc/socket.c | 1 +
  1 file changed, 1 insertion(+)
net/tipc/socket.c +1 -1
index 17f8c523e33b..43509c7e90fc 100644
@@ -502,6 +502,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
  	sock_init_data(sock, sk);
  	tipc_set_sk_state(sk, TIPC_OPEN);
  	if (tipc_sk_insert(tsk)) {
+		sk_free(sk);
  		pr_warn("Socket create failed; port number exhausted\n");
  		return -EINVAL;
  	}
--

2.25.1