Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Fix one possible memleak in ip_setup_cork

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 <gfree.wind@vip.163.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Gao Feng and committed by
David S. Miller
9783ccd0 5171b37d

+5 -3
+5 -3
net/ipv4/ip_output.c
··· 1109 1109 struct ip_options_rcu *opt; 1110 1110 struct rtable *rt; 1111 1111 1112 + rt = *rtp; 1113 + if (unlikely(!rt)) 1114 + return -EFAULT; 1115 + 1112 1116 /* 1113 1117 * setup for corking. 1114 1118 */ ··· 1128 1124 cork->flags |= IPCORK_OPT; 1129 1125 cork->addr = ipc->addr; 1130 1126 } 1131 - rt = *rtp; 1132 - if (unlikely(!rt)) 1133 - return -EFAULT; 1127 + 1134 1128 /* 1135 1129 * We steal reference to this route, caller should not release it 1136 1130 */