Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A4853AFAEC for ; Tue, 1 Sep 2026 02:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788228592; cv=none; b=BJwk3526I//SLXLv/WOVK0k4pB+0LjobudD0nPeBkzgy/3Q+z4Z7Y3tYEzVQhYYYbODFINU6ZiJd7YhNjrFeTvkgA99Q6bahedj90cYn9vqe1BD5SzRSF1UOWobq8GGSt9UxWK7A3lX4a+e35iaz5SD6TuIFzwxvAA1F3TMB7Aw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788228592; c=relaxed/simple; bh=qfRZ4xQyeg9tQBBAh1lXTygI1+E1Ss6rPNMwvGw/YL0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ehxtasrs2mQp3V3XslfQO01HKieNda5tLu6aDV1SmCxfWNMHdvCpPucqHZRKmMmsBt5oxG6BIvVc5bUxR1ieUuYcU/IZYI4un5NxI0XjzBfeF/vRL0SGBVGIg0qHEO5R7NiuWRcHHxYFV211ioX3cJOGw6/VoUfuOkL7rCe1q8c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=du56M2xz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="du56M2xz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8D2B1F00A3F; Tue, 1 Sep 2026 02:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788228583; bh=Q69hUx5iHnrGVOLWYvMxBLgaYmdeoWhZEAiDVUlsLkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=du56M2xzj/LRIwBTRtOd5sOkxczF5SLUV6ZP25UFFLi/pJfy82tm9LwJmnMaJAL/G 1Oj5T9Tf6GyKG4ZeXgAXi8J64vrDAZI+IVUWtM4tB79qj6YTv51FpM6OpMjCToQi6K sizbgN/K3IJo6yFd95TjXK9fDN3se+0f4nFQPnL5B+VYrb25csnNmZRlMpT7yXqgG/ VrfjpHcuucl8M7AHVLsZLdDB85hrN1DkxN6RCFERsqRCEtPf/R0zEiUWDb+H9shvVe dl6DkomKZwVMsXQpmejJ2WvPBtFkx524GdZ/K22MXi7bd0zx5Y97IeSnq2k3M2UVUF DSKcO7hUPfvIQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Qing Ming , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10.y] gtp: serialize PDP context updates Date: Mon, 31 Aug 2026 22:09:40 -0400 Message-ID: <20260901020940.2314903-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026083100-bats-talisman-6475@gregkh> References: <2026083100-bats-talisman-6475@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Qing Ming [ Upstream commit 498386b6d402737db1e2eeed4c385acbf0ef9e34 ] PDP contexts can be deleted through GTP_CMD_DELPDP or while the GTP network device is being unregistered. The latter is serialized by RTNL, but the generic-netlink delete path only holds RCU. Running both paths concurrently can therefore make both paths delete the same PDP context. The issue was found through static analysis and reproduced on a KASAN-enabled kernel by a simple two-thread program racing GTP_CMD_DELPDP against RTM_DELLINK: Oops: general protection fault, probably for non-canonical address KASAN: maybe wild-memory-access in range [0xdead000000000120-0xdead000000000127] RIP: gtp_genl_del_pdp+0x1c1/0x420 [gtp] RBP: dead000000000122 The second deletion dereferenced the poisoned hlist pprev pointer. Serialize gtp_pdp_add(), gtp_genl_del_pdp(), and gtp_dellink() with a shared mutex. Keep the mutex held until the final use of a PDP context in the NEWPDP path, and keep the RCU read-side section around the complete PDP context use in the DELPDP path. Fixes: 459aa660eb1d ("gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)") Cc: stable@vger.kernel.org Signed-off-by: Qing Ming Link: https://patch.msgid.link/20260818150000.7670-1-a0yami@mailbox.org Signed-off-by: Jakub Kicinski [ adapted the locking changes to the older IPv4-only PDP context API and omitted the absent IPv6 lookup hunk. ] Signed-off-by: Sasha Levin --- drivers/net/gtp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 155ae9b1e4d9a..39b119a7170bf 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include @@ -82,6 +83,7 @@ struct gtp_net { }; static u32 gtp_h_initval; +static DEFINE_MUTEX(gtp_pdp_lock); static void pdp_context_delete(struct pdp_ctx *pctx); @@ -109,7 +111,8 @@ static struct pdp_ctx *gtp0_pdp_find(struct gtp_dev *gtp, u64 tid) head = >p->tid_hash[gtp0_hashfn(tid) % gtp->hash_size]; - hlist_for_each_entry_rcu(pdp, head, hlist_tid) { + hlist_for_each_entry_rcu(pdp, head, hlist_tid, + lockdep_is_held(>p_pdp_lock)) { if (pdp->gtp_version == GTP_V0 && pdp->u.v0.tid == tid) return pdp; @@ -125,7 +128,8 @@ static struct pdp_ctx *gtp1_pdp_find(struct gtp_dev *gtp, u32 tid) head = >p->tid_hash[gtp1u_hashfn(tid) % gtp->hash_size]; - hlist_for_each_entry_rcu(pdp, head, hlist_tid) { + hlist_for_each_entry_rcu(pdp, head, hlist_tid, + lockdep_is_held(>p_pdp_lock)) { if (pdp->gtp_version == GTP_V1 && pdp->u.v1.i_tei == tid) return pdp; @@ -141,7 +145,8 @@ static struct pdp_ctx *ipv4_pdp_find(struct gtp_dev *gtp, __be32 ms_addr) head = >p->addr_hash[ipv4_hashfn(ms_addr) % gtp->hash_size]; - hlist_for_each_entry_rcu(pdp, head, hlist_addr) { + hlist_for_each_entry_rcu(pdp, head, hlist_addr, + lockdep_is_held(>p_pdp_lock)) { if (pdp->af == AF_INET && pdp->ms_addr_ip4.s_addr == ms_addr) return pdp; @@ -707,9 +712,11 @@ static void gtp_dellink(struct net_device *dev, struct list_head *head) struct pdp_ctx *pctx; int i; + mutex_lock(>p_pdp_lock); for (i = 0; i < gtp->hash_size; i++) hlist_for_each_entry_safe(pctx, next, >p->tid_hash[i], hlist_tid) pdp_context_delete(pctx); + mutex_unlock(>p_pdp_lock); list_del(>p->list); unregister_netdevice_queue(dev, head); @@ -1094,6 +1101,7 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info) goto out_unlock; } + mutex_lock(>p_pdp_lock); pctx = gtp_pdp_add(gtp, sk, info); if (IS_ERR(pctx)) { err = PTR_ERR(pctx); @@ -1101,6 +1109,7 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info) gtp_tunnel_notify(pctx, GTP_CMD_NEWPDP, GFP_KERNEL); err = 0; } + mutex_unlock(>p_pdp_lock); out_unlock: rtnl_unlock(); @@ -1155,6 +1164,8 @@ static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info) if (!info->attrs[GTPA_VERSION]) return -EINVAL; + mutex_lock(>p_pdp_lock); + rcu_read_lock(); pctx = gtp_find_pdp(sock_net(skb->sk), info->attrs); @@ -1175,6 +1186,7 @@ static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info) out_unlock: rcu_read_unlock(); + mutex_unlock(>p_pdp_lock); return err; } -- 2.53.0