* [PATCH] [v2] net: ipv4: fix a memleak in ip_setup_cork
@ 2024-01-29 9:10 Zhipeng Lu
2024-01-29 13:22 ` Eric Dumazet
2024-02-01 0:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Zhipeng Lu @ 2024-01-29 9:10 UTC (permalink / raw)
To: alexious
Cc: David S. Miller, David Ahern, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
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: 501a90c94510 ("inet: protect against too small mtu values.")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
Changelog:
v2: fix memleak by placing the malloc as the last error-handling.
---
net/ipv4/ip_output.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index b06f678b03a1..41537d18eecf 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1287,6 +1287,12 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
if (unlikely(!rt))
return -EFAULT;
+ cork->fragsize = ip_sk_use_pmtu(sk) ?
+ dst_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
+
+ if (!inetdev_valid_mtu(cork->fragsize))
+ return -ENETUNREACH;
+
/*
* setup for corking.
*/
@@ -1303,12 +1309,6 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork,
cork->addr = ipc->addr;
}
- cork->fragsize = ip_sk_use_pmtu(sk) ?
- dst_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu);
-
- if (!inetdev_valid_mtu(cork->fragsize))
- return -ENETUNREACH;
-
cork->gso_size = ipc->gso_size;
cork->dst = &rt->dst;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] [v2] net: ipv4: fix a memleak in ip_setup_cork
2024-01-29 9:10 [PATCH] [v2] net: ipv4: fix a memleak in ip_setup_cork Zhipeng Lu
@ 2024-01-29 13:22 ` Eric Dumazet
2024-02-01 0:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2024-01-29 13:22 UTC (permalink / raw)
To: Zhipeng Lu
Cc: David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On Mon, Jan 29, 2024 at 10:23 AM Zhipeng Lu <alexious@zju.edu.cn> wrote:
>
> 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: 501a90c94510 ("inet: protect against too small mtu values.")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
Okay, although the changelog is a bit confusing, since we do not free
cork->opt anymore in V2...
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [v2] net: ipv4: fix a memleak in ip_setup_cork
2024-01-29 9:10 [PATCH] [v2] net: ipv4: fix a memleak in ip_setup_cork Zhipeng Lu
2024-01-29 13:22 ` Eric Dumazet
@ 2024-02-01 0:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-02-01 0:00 UTC (permalink / raw)
To: Zhipeng Lu; +Cc: davem, dsahern, edumazet, kuba, pabeni, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 29 Jan 2024 17:10:17 +0800 you wrote:
> 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: 501a90c94510 ("inet: protect against too small mtu values.")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> ---
> Changelog:
>
> [...]
Here is the summary with links:
- [v2] net: ipv4: fix a memleak in ip_setup_cork
https://git.kernel.org/netdev/net/c/5dee6d692345
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-01 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 9:10 [PATCH] [v2] net: ipv4: fix a memleak in ip_setup_cork Zhipeng Lu
2024-01-29 13:22 ` Eric Dumazet
2024-02-01 0:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).