Skip to content

Commit 5dee6d6

Browse files
AlexiousLukuba-moo
authored andcommitted
net: ipv4: fix a memleak in ip_setup_cork
When inetdev_valid_mtu fails, cork->opt should be freed if it is allocated in ip_setup_cork. Otherwise there could be a memleak. Fixes: 501a90c ("inet: protect against too small mtu values.") Signed-off-by: Zhipeng Lu <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e028243 commit 5dee6d6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/ipv4/ip_output.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,12 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
12871287
if (unlikely(!rt))
12881288
return -EFAULT;
12891289

1290+
cork->fragsize = ip_sk_use_pmtu(sk) ?
1291+
dst_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
1292+
1293+
if (!inetdev_valid_mtu(cork->fragsize))
1294+
return -ENETUNREACH;
1295+
12901296
/*
12911297
* setup for corking.
12921298
*/
@@ -1303,12 +1309,6 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
13031309
cork->addr = ipc->addr;
13041310
}
13051311

1306-
cork->fragsize = ip_sk_use_pmtu(sk) ?
1307-
dst_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
1308-
1309-
if (!inetdev_valid_mtu(cork->fragsize))
1310-
return -ENETUNREACH;
1311-
13121312
cork->gso_size = ipc->gso_size;
13131313

13141314
cork->dst = &rt->dst;

0 commit comments

Comments
 (0)