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=1796387989; b=jjpIclTe9mDtDABcUoGIUpVesJh+AtHMBCZo1zmvLp7ESBbbkC73/ymueMTFuf7NU4kJ LF6CD0CETAigqJ/wBKWHAdhFntPgqoNT8M7ndvjjQB3Iie5Sv5OfCk+FFs2iMZLxQ1DN9 Ar3UdYBaixuWUMk2DT8Q78SA2M3U6vfZJ/TOP67ifE5Vg7viCKlpkR0io/RGl07/sPIHr nt2WoeaNz02NHU3RFpOU6MHjKk6NwZLZhMsWr9hNSGnEhBZji1GahCBX/zhSm9pZVpbyn KbQqrMLS/iCa1iVsJ7nmciYmr47xtc+EntADjFSz1liPMfpRNcMKNoI1/YEvhWP3rOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387989; 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=V7FFnZHcEMMnvMgLcg86AxcmMtTaw7AvKZ0XYU1rajs=; b=kth7QL+9srE0YVWgvX6sR8C6MZCFklSpia2KnbvYpKWlIS9dx49Q42LKAeZJ3PCPdaN0 D6qyes9p/ZNNs7UhSId8/6a/B4eSaRJZMpHGVRhD9iK1+ovTBPFC0od1RR7lH18nN4WPL DM+0uEe0SPVecIlzRLiG3Q0M6AuC6kDyTZmfqjXt9aD9uYFh4E+p5Qzz4P1j9ITTyJ7ZT L5depgZ3ocDuae3TefPo8QS0HYg0fNmtu8FZTPAt7SWDtcgsurZ3Y/r46vZV7NxnVf5x7 5VHUPi/wrs5hQ1IVtoPgV5dlQWDLIEhDzuDHxwDeafCp+KN5V52NYKqX9xRt1Dzl1RA== 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=bcFeBsU6; 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 CB5B8606A322; Fri, 4 Dec 2026 12:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bcFeBsU6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4A611F000C2; Fri, 4 Dec 2026 12:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387989; bh=V7FFnZHcEMMnvMgLcg86AxcmMtTaw7AvKZ0XYU1rajs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bcFeBsU65r840RycSqY51g21z3y3aIQL/0fD+uVRjVCK5YckSc2HCQ8JsHqj6NijN 7uItVLxNXmbVy4SgQrRe796QnDsbIVRb6dH7J7xOc6t5Y7WCGo9lcZGt3UlpPpkzFq Qsy+yl90IR2QZq8NPSQfLQamZLsKciBT1Waz7z4k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Paolo Abeni , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 0440/1059] gtp: hold RCU in gtp_genl_send_echo_req() Date: Fri, 4 Dec 2026 18:59:31 +0900 Message-ID: <20261204100655.711206759@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni [ Upstream commit a204e9c001dfafe83cac01b16508b1cf5c953355 ] Such function is invoked in process context, performs an RCU device lookup and dereference the found device with no additional protection. ============================= WARNING: suspicious RCU usage 7.3.0-virtme #7 Not tainted ----------------------------- net/core/dev.c:1047 RCU-list traversed in non-reader section!! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 locks held by python3/233: 2, last CPU#5: #0: ffffffffbab93268 (cb_lock){++++}-{4:4}, at: genl_rcv+0x19/0x40 #1: ffffffffbab93320 (genl_mutex){+.+.}-{4:4}, at: genl_rcv_msg+0x12c/0x160 stack backtrace: CPU: 5 UID: 0 PID: 233 Comm: python3 Not tainted 7.3.0#7 PREEMPT(full) Hardware name: Bochs, BIOS Bochs 01/01/2011 Call Trace: dump_stack_lvl+0x6f/0xb0 lockdep_rcu_suspicious.cold+0x37/0x8e dev_get_by_index_rcu+0x135/0x180 gtp_find_dev+0xe7/0x360 [gtp] gtp_genl_send_echo_req+0x298/0xb30 [gtp] genl_family_rcv_msg_doit+0x20f/0x310 genl_family_rcv_msg+0x3a8/0x640 genl_rcv_msg+0xbb/0x160 netlink_rcv_skb+0x154/0x3a0 genl_rcv+0x28/0x40 netlink_unicast+0x54b/0x860 netlink_sendmsg+0x7fb/0xf60 __sys_sendto+0x3d6/0x450 __x64_sys_sendto+0xe4/0x1f0 do_syscall_64+0xff/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7ffa43b0256e Code: 4d 89 d8 e8 d4 bd 00 00 4c 8b 5d f8 41 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 11 c9 c3 0f 1f 80 00 00 00 00 48 8b 45 10 0f 05 c3 83 e2 39 83 fa 08 75 e7 e8 03 ff ff ff 0f 1f 00 f3 0f 1e fa RSP: 002b:00007ffd3b8828d0 EFLAGS: 00000202 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00007ffd3b8829e0 RCX: 00007ffa43b0256e RDX: 0000000000000034 RSI: 00007ffa3519d0d0 RDI: 0000000000000006 RBP: 00007ffd3b8828e0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 00007ffa351cc0c0 R13: 00007ffd3b8829e0 R14: 00007ffa354ca130 R15: 00007ffa4433d498 Add the missing RCU guards and keep it for the whole function body, while the RCU-protected device is used. Found by code inspection, validated explicitly testing the relevant code path. Fixes: d33bd757d362 ("gtp: Implement GTP echo request") Signed-off-by: Paolo Abeni Link: https://patch.msgid.link/ed27d133fe73afd377d3fa4e553c34e7987b6dd9.1792744478.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski [ sashal: Kept the local udp_tunnel_xmit_skb() call without local_bh_* and the extra argument, and added only the unlock: tail after it. ] Signed-off-by: Sasha Levin --- drivers/net/gtp.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 0303f24815a1b..94f4be527e539 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -1760,9 +1760,9 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) struct gtp_dev *gtp; struct flowi4 fl4; struct rtable *rt; + int len, ret = 0; struct sock *sk; __be16 port; - int len; if (!info->attrs[GTPA_VERSION] || !info->attrs[GTPA_LINK] || @@ -1774,14 +1774,21 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) dst_ip = nla_get_be32(info->attrs[GTPA_PEER_ADDRESS]); src_ip = nla_get_be32(info->attrs[GTPA_MS_ADDRESS]); + rcu_read_lock(); gtp = gtp_find_dev(sock_net(skb->sk), info->attrs); - if (!gtp) - return -ENODEV; + if (!gtp) { + ret = -ENODEV; + goto unlock; + } - if (!gtp->sk_created) - return -EOPNOTSUPP; - if (!(gtp->dev->flags & IFF_UP)) - return -ENETDOWN; + if (!gtp->sk_created) { + ret = -EOPNOTSUPP; + goto unlock; + } + if (!(gtp->dev->flags & IFF_UP)) { + ret = -ENETDOWN; + goto unlock; + } if (version == GTP_V0) { struct gtp0_header *gtp0_h; @@ -1790,8 +1797,10 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) sizeof(struct iphdr) + sizeof(struct udphdr); skb_to_send = netdev_alloc_skb_ip_align(gtp->dev, len); - if (!skb_to_send) - return -ENOMEM; + if (!skb_to_send) { + ret = -ENOMEM; + goto unlock; + } sk = gtp->sk0; port = htons(GTP0_PORT); @@ -1807,8 +1816,10 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) sizeof(struct iphdr) + sizeof(struct udphdr); skb_to_send = netdev_alloc_skb_ip_align(gtp->dev, len); - if (!skb_to_send) - return -ENOMEM; + if (!skb_to_send) { + ret = -ENOMEM; + goto unlock; + } sk = gtp->sk1u; port = htons(GTP1U_PORT); @@ -1818,7 +1829,8 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) memset(gtp1u_h, 0, sizeof(struct gtp1_header_long)); gtp1u_build_echo_msg(gtp1u_h, GTP_ECHO_REQ); } else { - return -ENODEV; + ret = -ENODEV; + goto unlock; } rt = ip4_route_output_gtp(&fl4, sk, dst_ip, src_ip); @@ -1826,7 +1838,8 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) netdev_dbg(gtp->dev, "no route for echo request to %pI4\n", &dst_ip); kfree_skb(skb_to_send); - return -ENODEV; + ret = -ENODEV; + goto unlock; } udp_tunnel_xmit_skb(rt, sk, skb_to_send, @@ -1838,7 +1851,10 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) !net_eq(sock_net(sk), dev_net(gtp->dev)), false); - return 0; + +unlock: + rcu_read_unlock(); + return ret; } static const struct nla_policy gtp_genl_policy[GTPA_MAX + 1] = { -- 2.53.0