tcp/dccp: make our listener code more robust
Subsystems (3)
v2 cover tcp/dccp: make our listener code more robust
This patch series addresses request sockets leaks and listener dismantle phase. This survives a stress test with listeners being added/removed quite randomly.
Eric Dumazet (3):
Revert "inet: fix double request socket freeing" tcp/dccp: add inet_csk_reqsk_queue_drop_and_put() helper tcp/dccp: fix race at listener dismantle phase
include/net/inet_connection_sock.h | 10 ++--- include/net/request_sock.h | 19 --------- net/dccp/ipv4.c | 4 +- net/dccp/ipv6.c | 2 +- net/ipv4/inet_connection_sock.c | 81 +++++++++++++++++++++++++++----------- net/ipv4/tcp_ipv4.c | 6 +-- net/ipv6/tcp_ipv6.c | 2 +- 7 files changed, 67 insertions(+), 57 deletions(-)
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 1/3 Revert "inet: fix double request socket freeing"
This reverts commit c69736696cf3742b37d850289dc0d7ead177bb14.
At the time of above commit, tcp_req_err() and dccp_req_err() were dead code, as SYN_RECV request sockets were not yet in ehash table.
Real bug was fixed later in a different commit.
We need to revert to not leak a refcount on request socket.
inet_csk_reqsk_queue_drop_and_put() will be added in following commit to make clean inet_csk_reqsk_queue_drop() does not release the reference owned by caller.
--- net/dccp/ipv4.c | 2 +- net/ipv4/tcp_ipv4.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
net/dccp/ipv4.c +1 -1
@@ -208,7 +208,6 @@ void dccp_req_err(struct sock *sk, u64 seq)if (!between48 (seq,dccp_rsk (req)->dreq_iss,dccp_rsk (req)->dreq_gss)) {NET_INC_STATS_BH (net,LINUX_MIB_OUTOFWINDOWICMPS ); -reqsk_put (req); }else {/* * Still in RESPOND, just remove it silently.
@@ -218,6 +217,7 @@ void dccp_req_err(struct sock *sk, u64 seq)*/ inet_csk_reqsk_queue_drop (req->rsk_listener, req); } +reqsk_put (req); }EXPORT_SYMBOL (dccp_req_err);
net/ipv4/tcp_ipv4.c +2 -2
@@ -324,7 +324,6 @@ void tcp_req_err(struct sock *sk, u32 seq)if (seq !=tcp_rsk (req)->snt_isn) {NET_INC_STATS_BH (net,LINUX_MIB_OUTOFWINDOWICMPS ); -reqsk_put (req); }else {/* * Still in SYN_RECV, just remove it silently.
@@ -332,9 +331,10 @@ void tcp_req_err(struct sock *sk, u32 seq)* created socket, and POSIX does not want network * errors returned from accept(). */ -NET_INC_STATS_BH (net,LINUX_MIB_LISTENDROPS );inet_csk_reqsk_queue_drop (req->rsk_listener, req); +NET_INC_STATS_BH (net,LINUX_MIB_LISTENDROPS ); } +reqsk_put (req); }EXPORT_SYMBOL (tcp_req_err);
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 2/3 tcp/dccp: add inet_csk_reqsk_queue_drop_and_put() helper
In reply to Eric DumazetLet's reduce the confusion about inet_csk_reqsk_queue_drop() :
In many cases we also need to release reference on request socket, so add a helper to do this, reducing code size and complexity.
--- include/net/inet_connection_sock.h | 1 + net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 2 +- net/ipv4/inet_connection_sock.c | 10 ++++++++-- net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-)
include/net/inet_connection_sock.h +1 -0
@@ -299,6 +299,7 @@ static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk) }void inet_csk_reqsk_queue_drop (struct sock *sk,struct request_sock *req); +void inet_csk_reqsk_queue_drop_and_put (struct sock *sk,struct request_sock *req);void inet_csk_destroy_sock (struct sock *sk);void inet_csk_prepare_forced_close (struct sock *sk);
net/dccp/ipv4.c +1 -1
@@ -828,7 +828,7 @@ lookup:if (likely (sk->sk_state ==DCCP_LISTEN )) { nsk =dccp_check_req (sk, skb, req); }else { -inet_csk_reqsk_queue_drop (sk, req); +inet_csk_reqsk_queue_drop_and_put (sk, req); goto lookup; }if (!nsk) {
net/dccp/ipv6.c +1 -1
@@ -686,7 +686,7 @@ lookup:if (likely (sk->sk_state ==DCCP_LISTEN )) { nsk =dccp_check_req (sk, skb, req); }else { -inet_csk_reqsk_queue_drop (sk, req); +inet_csk_reqsk_queue_drop_and_put (sk, req); goto lookup; }if (!nsk) {
net/ipv4/inet_connection_sock.c +8 -2
@@ -546,6 +546,13 @@ void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req) }EXPORT_SYMBOL (inet_csk_reqsk_queue_drop); +void inet_csk_reqsk_queue_drop_and_put (struct sock *sk,struct request_sock *req) +{ +inet_csk_reqsk_queue_drop (sk, req); +reqsk_put (req); +} +EXPORT_SYMBOL (inet_csk_reqsk_queue_drop_and_put); +static void reqsk_timer_handler (unsigned long data) {struct request_sock *req = (struct request_sock *)data;
@@ -608,8 +615,7 @@ static void reqsk_timer_handler(unsigned long data)return ; } drop: -inet_csk_reqsk_queue_drop (sk_listener, req); -reqsk_put (req); +inet_csk_reqsk_queue_drop_and_put (sk_listener, req); } static void reqsk_queue_hash_req(struct request_sock *req,
net/ipv4/tcp_ipv4.c +1 -1
@@ -1591,7 +1591,7 @@ process:if (likely (sk->sk_state ==TCP_LISTEN )) { nsk =tcp_check_req (sk, skb, req, false); }else { -inet_csk_reqsk_queue_drop (sk, req); +inet_csk_reqsk_queue_drop_and_put (sk, req); goto lookup; }if (!nsk) {
net/ipv6/tcp_ipv6.c +1 -1
@@ -1386,7 +1386,7 @@ process:if (likely (sk->sk_state ==TCP_LISTEN )) { nsk =tcp_check_req (sk, skb, req, false); }else { -inet_csk_reqsk_queue_drop (sk, req); +inet_csk_reqsk_queue_drop_and_put (sk, req); goto lookup; }if (!nsk) {
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH v2 3/3 tcp/dccp: fix race at listener dismantle phase
In reply to Eric DumazetUnder stress, a close() on a listener can trigger the WARN_ON(sk->sk_ack_backlog) in inet_csk_listen_stop()
We need to test if listener is still active before queueing a child in inet_csk_reqsk_queue_add()
Create a common inet_child_forget() helper, and use it from inet_csk_reqsk_queue_add() and inet_csk_listen_stop()
--- include/net/inet_connection_sock.h | 9 ++--- include/net/request_sock.h | 19 ---------- net/ipv4/inet_connection_sock.c | 71 ++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 48 deletions(-)
include/net/inet_connection_sock.h +2 -7
@@ -268,13 +268,8 @@ struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,struct sock *newsk, const struct request_sock *req); -static inline void inet_csk_reqsk_queue_add (struct sock *sk, -struct request_sock *req, -struct sock *child) -{ -reqsk_queue_add (&inet_csk (sk)->icsk_accept_queue, req, sk, child); -} - +void inet_csk_reqsk_queue_add (struct sock *sk,struct request_sock *req, +struct sock *child);void inet_csk_reqsk_queue_hash_add (struct sock *sk,struct request_sock *req,unsigned long timeout);
include/net/request_sock.h +0 -19
@@ -186,25 +186,6 @@ static inline bool reqsk_queue_empty(const struct request_sock_queue *queue)return queue->rskq_accept_head ==NULL ; } -static inline void reqsk_queue_add (struct request_sock_queue *queue, -struct request_sock *req, -struct sock *parent, -struct sock *child) -{ -spin_lock (&queue->rskq_lock); - req->sk = child; -sk_acceptq_added (parent); - -if (queue->rskq_accept_head ==NULL ) - queue->rskq_accept_head = req; -else - queue->rskq_accept_tail->dl_next = req; - - queue->rskq_accept_tail = req; - req->dl_next =NULL ; -spin_unlock (&queue->rskq_lock); -} -static inline struct request_sock *reqsk_queue_remove (struct request_sock_queue *queue,struct sock *parent) {
net/ipv4/inet_connection_sock.c +49 -22
93 lines not on this page · raw message
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Wed, 14 Oct 2015 11:16:25 -0700
Quoted 3 lines
This patch series addresses request sockets leaks and listener dismantle phase. This survives a stress test with listeners being added/removed quite randomly.
Series applied, thanks Eric.