Skip to contentSkip to conversation

net: ipv6: fix use after free of struct seg6_pernet_data

PATCH Applied MichelleJin 2 participants 2 messages Oct 2, 2021 – Oct 4, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ipv6: fix use after free of struct seg6_pernet_data

sdata->tun_src should be freed before sdata is freed because sdata->tun_src is allocated after sdata allocation. So, kfree(sdata) and kfree(rcu_dereference_raw(sdata->tun_src)) are changed code order.

Fixes f04ed7d277e8 ("net: ipv6: check return value of rhashtable_init")

---

commit f04ed7d277e8
("net: ipv6: check return value of rhashtable_init") is not yet merged into net branch,
so this patch is committed to net-next.

 net/ipv6/seg6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/seg6.c +1 -1
index 65744f2d38da..5daa1c3ed83b 100644
@@ -375,8 +375,8 @@ static int __net_init seg6_net_init(struct net *net)
 
 #ifdef CONFIG_IPV6_SEG6_HMAC
 	if (seg6_hmac_net_init(net)) {
-		kfree(sdata);
 		kfree(rcu_dereference_raw(sdata->tun_src));
+		kfree(sdata);
 		return -ENOMEM;
 	};
 #endif
Signature · 1 line
2.25.1
#1 lore raw
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Sat, 2 Oct 2021 22:33:32 +0000 you wrote:

sdata->tun_src should be freed before sdata is freed because sdata->tun_src is allocated after sdata allocation. So, kfree(sdata) and kfree(rcu_dereference_raw(sdata->tun_src)) are changed code order.

Fixes f04ed7d277e8 ("net: ipv6: check return value of rhashtable_init")

[...]

Here is the summary with links:
- [net-next] net: ipv6: fix use after free of struct seg6_pernet_data

    https://git.kernel.org/netdev/net-next/c/23b08260481c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html