Skip to content

Commit

Permalink
net: Fix one possible memleak in ip_setup_cork
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
gfreewind authored and davem330 committed Apr 16, 2018
1 parent 5171b37 commit 9783ccd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
*/
Expand Down

0 comments on commit 9783ccd

Please sign in to comment.