]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dccp: fix a memleak that dccp_ipv6 doesn't put reqsk properly
authorXin Long <lucien.xin@gmail.com>
Wed, 26 Jul 2017 06:19:09 +0000 (14:19 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Jul 2017 07:01:05 +0000 (00:01 -0700)
In dccp_v6_conn_request, after reqsk gets alloced and hashed into
ehash table, reqsk's refcnt is set 3. one is for req->rsk_timer,
one is for hlist, and the other one is for current using.

The problem is when dccp_v6_conn_request returns and finishes using
reqsk, it doesn't put reqsk. This will cause reqsk refcnt leaks and
reqsk obj never gets freed.

Jianlin found this issue when running dccp_memleak.c in a loop, the
system memory would run out.

dccp_memleak.c:
  int s1 = socket(PF_INET6, 6, IPPROTO_IP);
  bind(s1, &sa1, 0x20);
  listen(s1, 0x9);
  int s2 = socket(PF_INET6, 6, IPPROTO_IP);
  connect(s2, &sa1, 0x20);
  close(s1);
  close(s2);

This patch is to put the reqsk before dccp_v6_conn_request returns,
just as what tcp_conn_request does.

Reported-by: Jianlin Shi <jishi@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dccp/ipv6.c

index c376af5bfdfb34774d82de6858ec0e4b6e3380bb..1b58eac8aad326b6db09a4cee82fdcc178c2afad 100644 (file)
@@ -380,6 +380,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
                goto drop_and_free;
 
        inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
+       reqsk_put(req);
        return 0;
 
 drop_and_free: