rds-tcp: sock_graft() leak
Subsystems (4)
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(-)
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
@@ -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
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()fromrds_tcp_accept_one()
1. it sets up anew_sock->skthat is wasteful, because this ->skis 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->skAvoid these problems by calling
sock_create_lite().Signed-off-by Sowmini Varadhan <[email protected]>---
PATCH 2/2 net/sock: add WARN_ON(parent->sk) in sock_graft()
In reply to Sowmini Varadhansock_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
@@ -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
David Miller
maintainerFrom: 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
- makerds_tcp_accept_one()callsock_create_lite()
- add aWARN_ON()tosock_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.