Commit 6b8b9e3b authored by Hyunwoo Kim's avatar Hyunwoo Kim Committed by Pu Lehui
Browse files

net: gtp: Fix Use-After-Free in gtp_dellink

stable inclusion
from stable-v5.10.216
commit 0caff3e6390f840666b8dc1ecebf985c2ef3f1dd
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9O0MU
CVE: CVE-2024-27396

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0caff3e6390f



--------------------------------

[ Upstream commit f2a904107ee2b647bb7794a1a82b67740d7c8a64 ]

Since call_rcu, which is called in the hlist_for_each_entry_rcu traversal
of gtp_dellink, is not part of the RCU read critical section, it
is possible that the RCU grace period will pass during the traversal and
the key will be free.

To prevent this, it should be changed to hlist_for_each_entry_safe.

Fixes: 94dc550a ("gtp: fix an use-after-free in ipv4_pdp_find()")
Signed-off-by: default avatarHyunwoo Kim <v4bel@theori.io>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarPu Lehui <pulehui@huawei.com>
parent 04dd32cb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -700,11 +700,12 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev,
static void gtp_dellink(struct net_device *dev, struct list_head *head)
{
	struct gtp_dev *gtp = netdev_priv(dev);
	struct hlist_node *next;
	struct pdp_ctx *pctx;
	int i;

	for (i = 0; i < gtp->hash_size; i++)
		hlist_for_each_entry_rcu(pctx, &gtp->tid_hash[i], hlist_tid)
		hlist_for_each_entry_safe(pctx, next, &gtp->tid_hash[i], hlist_tid)
			pdp_context_delete(pctx);

	list_del_rcu(&gtp->list);