From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793208226; b=A9FjTVPkrYTzRxvWetsaM4nIITwBsBSItvnHkqm+BjGObgxTzN6csVX/e0y59P6+xQ8l CIoRo1pJbnNtsz0iK6WVQ7uP8axt8VT0o7lybcebOVxASwYTFBS+FyrGiq/j2W0q2kpfW PX63sU5vf6aG1PvfAC2yhTnQ+3BTDCVwN1vvNbDxiMPc+KiFOewu/nvdCEsb111AC+T2X c0Zb4x2rU+E88rV9TCRBMc9CCYHo8O00F9fWryZSezcq40tXXq/ybzPbbaORmTRbFpSCI BBSZYUujRUtDDjLqo4t4KlgUjz7JaUTuZKB8W9a+4vAPxccv76RXvkti7Lj8SxHJqmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793208226; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=leU5fl7cZr8zaH+Z1XdN/LUDUkLOWmnAu0OWFOLOr8I=; b=ZAQJ+M903fw58h61z9wTwc26buRkNriASlxrWZqd2L37lgVFK0bPEQ/ekXss1GOSvDJt qiFm92Z/R2El2iMRqKp7mNXG+AWMlqcWnHpX9IzyTUCxjSKkhhWBwiHENEkis7gX+BMua VE3WY+zj2kmlR95Eb6glKRoZY71tpkwyDBvyUu/RsRvUE1JndRfm7jP7CO6C7jnLNCIrU ENMiOiFnnsT99dYMTnVRHZ/RK6xMiFViFcZx4mPaHD1E076OECj0yzTa2/tDBJuj4kb9W 07+BAmPYIn/hrRbvMXv6NZwah8k1EwsWNuT63JZ08OWj57jUNSRN8Ncfeo/cna9/y1Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WoxdhxIw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 588F8606A324; Wed, 28 Oct 2026 17:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WoxdhxIw Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6E111F01829; Wed, 28 Oct 2026 17:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793208226; bh=leU5fl7cZr8zaH+Z1XdN/LUDUkLOWmnAu0OWFOLOr8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WoxdhxIwssqxUXAa2ibanUKOQMGuk676MSIEnISXdwvOkhjIXqJo6L4IOCPlE/Dmp pWoFQxr5ePhsf6u/TLYd3SARMFFwgr52VXQ3p2soDWA/VgCLqzvW+/DZYcE3ZZ4p+I 8bckk+CgmQr9wHM3FgHtDPMagcL4tqz768hExeYg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qing Ming , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 043/516] gtp: serialize PDP context updates Date: Wed, 28 Oct 2026 17:53:15 +0100 Message-ID: <20261028170004.553152098@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170003.522232767@linuxfoundation.org> References: <20261028170003.522232767@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ 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 624220f8ec132..89f46e50d817b 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; @@ -709,9 +714,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); @@ -1096,6 +1103,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); @@ -1103,6 +1111,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(); @@ -1157,6 +1166,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); @@ -1177,6 +1188,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