From mboxrd@z Thu Jan 1 00:00:00 1970 From: gfree.wind@vip.163.com Subject: [PATCH net] net: Fix one possible memleak in ip_setup_cork Date: Mon, 16 Apr 2018 10:16:45 +0800 Message-ID: <1523845005-6353-2-git-send-email-gfree.wind@vip.163.com> References: <1523845005-6353-1-git-send-email-gfree.wind@vip.163.com> Cc: Gao Feng To: davem@davemloft.net, kuznet@ms2.inr.ac.ru, netdev@vger.kernel.org Return-path: Received: from m181-177.vip.163.com ([123.58.177.181]:48484 "EHLO m181-177.vip.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752662AbeDPCXQ (ORCPT ); Sun, 15 Apr 2018 22:23:16 -0400 In-Reply-To: <1523845005-6353-1-git-send-email-gfree.wind@vip.163.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Gao Feng It would allocate memory in this function when the cork->opt is NULL. But the memory isn't freed if failed in the latter rt check, and return error directly. It causes the memleak if its caller is ip_make_skb which also doesn't free the cork->opt when meet a error. Now move the rt check ahead to avoid the memleak. Signed-off-by: Gao Feng --- net/ipv4/ip_output.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 4c11b81..83c73ba 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1109,6 +1109,10 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, struct ip_options_rcu *opt; struct rtable *rt; + rt = *rtp; + if (unlikely(!rt)) + return -EFAULT; + /* * setup for corking. */ @@ -1124,9 +1128,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->flags |= IPCORK_OPT; cork->addr = ipc->addr; } - rt = *rtp; - if (unlikely(!rt)) - return -EFAULT; + /* * We steal reference to this route, caller should not release it */ -- 1.9.1