Skip to contentSkip to conversation

rds-tcp: sock_graft() leak

PATCH In review Sowmini Varadhan 3 participants 5 messages Jul 6, 2017 – Jul 8, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover rds-tcp: sock_graft() leak

Following up on the discussion at
https://www.spinics.net/lists/netdev/msg442859.html
- make rds_tcp_accept_one() call sock_create_lite()
- add a WARN_ON() to sock_graft()

Tested by running an infinite while() loop that does (module-load; rds-stress; module-unload) and monitors TCP slabinfo while the test is running.

Sowmini Varadhan (2):
rds: tcp: use sock_create_lite() to create the accept socket net/sock: add WARN_ON(parent->sk) in sock_graft()

 include/net/sock.h   |    1 +
 net/rds/tcp_listen.c |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)
#1 lore raw

PATCH 1/2 rds: tcp: use sock_create_lite() to create the accept socket

There are two problems with calling sock_create_kern() from rds_tcp_accept_one()
1. it sets up a new_sock->sk that is wasteful, because this ->sk is going to get replaced by inet_accept() in the subsequent ->accept()
2. The new_sock->sk is a leaked reference in sock_graft() which expects to find a null parent->sk

Avoid these problems by calling sock_create_lite().

---
 net/rds/tcp_listen.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/rds/tcp_listen.c +1 -1
index c6dc8ca..c061d6e 100644
@@ -136,7 +136,7 @@ int rds_tcp_accept_one(struct socket *sock)
 	if (!sock) /* module unload or netns delete in progress */
 		return -ENETUNREACH;
 
-	ret = sock_create_kern(sock_net(sock->sk), sock->sk->sk_family,
+	ret = sock_create_lite(sock->sk->sk_family,
 			       sock->sk->sk_type, sock->sk->sk_protocol,
 			       &new_sock);
 	if (ret)
Signature · 1 line
1.7.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH net 1/2] rds: tcp: use sock_create_lite() to create the accept socket

Quoted 11 lines · Sowmini Varadhan

There are two problems with calling sock_create_kern() from rds_tcp_accept_one()
1. it sets up a new_sock->sk that is wasteful, because this ->sk

    is going to get replaced by inet_accept() in the subsequent ->accept()
2. The new_sock->sk is a leaked reference in sock_graft() which
    expects to find a null parent->sk

Avoid these problems by calling sock_create_lite().

---

#3 lore raw

PATCH 2/2 net/sock: add WARN_ON(parent->sk) in sock_graft()

In reply to Sowmini Varadhan

sock_graft() unilaterally sets up parent->sk based on the assumption that the existing parent->sk is null. If this condition is not true, then the existing parent->sk would be leaked, so add a WARN_ON() to alert callers who may fall in this category.

---
 include/net/sock.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/net/sock.h +1 -0
index 48e4d5c..8c85791 100644
@@ -1697,6 +1697,7 @@ static inline void sock_orphan(struct sock *sk)
 
 static inline void sock_graft(struct sock *sk, struct socket *parent)
 {
+	WARN_ON(parent->sk);
 	write_lock_bh(&sk->sk_callback_lock);
 	sk->sk_wq = parent->wq;
 	parent->sk = sk;
Signature · 1 line
1.7.1
maintainer
#4 lore raw
In reply to Sowmini Varadhan

From: Sowmini Varadhan <[email protected]>
Date: Thu, 6 Jul 2017 08:15:05 -0700

Quoted 8 lines

Following up on the discussion at
https://www.spinics.net/lists/netdev/msg442859.html
- make rds_tcp_accept_one() call sock_create_lite()
- add a WARN_ON() to sock_graft()

Tested by running an infinite while() loop that does (module-load; rds-stress; module-unload) and monitors TCP slabinfo while the test is running.

This looks great, thanks for following up on this.

Series applied and queued up for -stable.