Skip to content

Commit

Permalink
inet: reqsk_alloc() needs to take care of dead listeners
Browse files Browse the repository at this point in the history
We'll soon no longer take a refcount on listeners,
so reqsk_alloc() can not assume a listener refcount is not
zero. We need to use atomic_inc_not_zero()

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and davem330 committed Apr 5, 2016
1 parent 2d33191 commit 3a5d1c0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions include/net/request_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,23 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener,
struct request_sock *req;

req = kmem_cache_alloc(ops->slab, GFP_ATOMIC | __GFP_NOWARN);

if (req) {
req->rsk_ops = ops;
if (attach_listener) {
sock_hold(sk_listener);
req->rsk_listener = sk_listener;
} else {
req->rsk_listener = NULL;
if (!req)
return NULL;
req->rsk_listener = NULL;
if (attach_listener) {
if (unlikely(!atomic_inc_not_zero(&sk_listener->sk_refcnt))) {
kmem_cache_free(ops->slab, req);
return NULL;
}
req_to_sk(req)->sk_prot = sk_listener->sk_prot;
sk_node_init(&req_to_sk(req)->sk_node);
sk_tx_queue_clear(req_to_sk(req));
req->saved_syn = NULL;
/* Following is temporary. It is coupled with debugging
* helpers in reqsk_put() & reqsk_free()
*/
atomic_set(&req->rsk_refcnt, 0);
req->rsk_listener = sk_listener;
}
req->rsk_ops = ops;
req_to_sk(req)->sk_prot = sk_listener->sk_prot;
sk_node_init(&req_to_sk(req)->sk_node);
sk_tx_queue_clear(req_to_sk(req));
req->saved_syn = NULL;
atomic_set(&req->rsk_refcnt, 0);

return req;
}

Expand Down

0 comments on commit 3a5d1c0

Please sign in to comment.