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=1793215641; b=oC+JZwAIuNItrt6SQ0G9mO1RAvcNMqCXMAvCpHhoapZPMDcKQVkTRM7YguH1TrffIPfq 47XRjpuvVpAYen9crcCcH0jhsDJjhUNIWWkgPu9luqk/ytxxkv0jke4/5HKpaNBQZfzYv UWjfaK3+ojveXh3Dx0FWzO46a+A2SV/6tA74Ro6jvSN+eeoMX5ApzJKE3z4YRbtTEE4op 08m5E5ciovxkRQr9qkKDqKJI9xtsmTbk8LgUA0XpBlZorSHUm+TfWOlJEd0UkiQtos959 ffi7lTROabpooLJR0BHyMOruKXfFitWS1ikK5Pkk7pz9NkAYn6YzLS/70DTFx/hYmSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793215641; 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=hHs7OCDB7aod2T5756Ymnh0IxKkb3hMNFrHtsHgmPxg=; b=U1+SGG3ONmwUJp6x/nNZL7dbB7Jvu8K0HHKMBe2uLUZY6Yi0BF6zHMzbruPLi1yttsd+ lchRLDHm1mSAqRV5lsenVTbRbgaY3ovFA8II3DGxqCn4BUo48KYDmnnGjUdDO8aT8MLKQ vb658XcQbrYjqQh8FYzlxZ+llIaFKLpgUzuMbWmAsX8Z96G2JLmcpNAi8ta5YDESrjbQN NMn2SzoGx9LgbWLbZLgC1OZ3hajp1KOsLjCZ/8ZSdMLQ0B6W1ugmRXTpCgIooT2rEBva7 sLH2Dff9gk61xsBXG6vmGg1q9OXSCGvwGiTg6ZtXzo+BDnxmCIyPspzL6+6DsrEDA9w== 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=1n8gI1ix; 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 CACAE606A31E; Wed, 28 Oct 2026 19:27:20 +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=1n8gI1ix Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF1111F01825; Wed, 28 Oct 2026 19:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793215640; bh=hHs7OCDB7aod2T5756Ymnh0IxKkb3hMNFrHtsHgmPxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1n8gI1ixglE/Hfx/lOVzpnQLQUZgM2/52tDhNE2B1Zt9aMNOuCNezMVEVgF+36hNb iFGupa6JxG3X9fjN0VyFLufGGI3wnm3jKqWiP76I4PM68AnuSiMi7HjjMx0pAO7vyE l79H5jvywNEEztqLUe9gGDp9NorZPZ/HeERvFctM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+eca845fb8c18dd6b44c1@syzkaller.appspotmail.com, Eric Dumazet , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 1282/1887] net: udp_tunnel: fix memory leak in udp_tunnel_nic_unregister() Date: Wed, 28 Oct 2026 17:56:18 +0100 Message-ID: <20261028170528.601215549@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 080695e6f005e2396f1207fd69d24c442cb230c6 ] syzbot reported a memory leak [1] in the UDP tunnel NIC offload code. When device registration fails (e.g. in register_netdevice()), netdev core unwinds by sending a single NETDEV_UNREGISTER notification. If work was queued during NETDEV_REGISTER (utn->work_pending is set), udp_tunnel_nic_unregister() returns early: if (utn->work_pending) return; Because failed registrations do not enter netdev_wait_allrefs_any(), no subsequent NETDEV_UNREGISTER rebroadcast will ever occur. As a result, the struct udp_tunnel_nic allocated in udp_tunnel_nic_alloc() is leaked permanently. Fix this by removing the early return. Instead, synchronously cancel any pending work with cancel_delayed_work_sync() before freeing @utn. To be able to call cancel_delayed_work_sync() while holding RTNL (the work also needs RTNL), switch udp_tunnel_nic_device_sync_work() to rtnl_trylock(). If RTNL is contended, requeue the work with a 1 jiffy delay (via queue_delayed_work()) to prevent high CPU contention while waiting for RTNL lock. The utn->work_pending bookkeeping is no longer needed and is removed, as the workqueue core already tracks the pending/running state of the work. [1] BUG: memory leak unreferenced object 0xffff888127d5f840 (size 96): comm "syz-executor", pid 5806, jiffies 4294942188 backtrace (crc 99fdb6c8): __kmalloc_noprof+0x3bf/0x550 udp_tunnel_nic_alloc net/ipv4/udp_tunnel_nic.c:756 [inline] udp_tunnel_nic_register net/ipv4/udp_tunnel_nic.c:833 [inline] udp_tunnel_nic_netdevice_event+0x804/0xab0 net/ipv4/udp_tunnel_nic.c:931 notifier_call_chain+0x59/0x160 kernel/notifier.c:85 call_netdevice_notifiers_info+0x7d/0xb0 net/core/dev.c:2250 register_netdevice+0xc10/0xeb0 net/core/dev.c:11478 Fixes: cc4e3835eff4 ("udp_tunnel: add central NIC RX port offload infrastructure") Reported-by: syzbot+eca845fb8c18dd6b44c1@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/6a632b15.dde6c935.cf6c8.0011.GAE@google.com/T/#u Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20260724091137.1792543-1-edumazet@google.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/ipv4/udp_tunnel_nic.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/net/ipv4/udp_tunnel_nic.c b/net/ipv4/udp_tunnel_nic.c index e6d6c4f716379..98f73221a6bff 100644 --- a/net/ipv4/udp_tunnel_nic.c +++ b/net/ipv4/udp_tunnel_nic.c @@ -31,19 +31,17 @@ struct udp_tunnel_nic_table_entry { * @dev: netdev pointer * @need_sync: at least one port start changed * @need_replay: space was freed, we need a replay of all ports - * @work_pending: @work is currently scheduled * @n_tables: number of tables under @entries * @missed: bitmap of tables which overflown * @entries: table of tables of ports currently offloaded */ struct udp_tunnel_nic { - struct work_struct work; + struct delayed_work work; struct net_device *dev; u8 need_sync:1; u8 need_replay:1; - u8 work_pending:1; unsigned int n_tables; unsigned long missed; @@ -301,7 +299,7 @@ udp_tunnel_nic_device_sync(struct net_device *dev, struct udp_tunnel_nic *utn) const struct udp_tunnel_nic_info *info = dev->udp_tunnel_nic_info; bool may_sleep; - if (!utn->need_sync || utn->work_pending) + if (!utn->need_sync) return; /* Drivers which sleep in the callback need to update from @@ -310,10 +308,8 @@ udp_tunnel_nic_device_sync(struct net_device *dev, struct udp_tunnel_nic *utn) may_sleep = info->flags & UDP_TUNNEL_NIC_INFO_MAY_SLEEP; if (!may_sleep) __udp_tunnel_nic_device_sync(dev, utn); - if (may_sleep || utn->need_replay) { - queue_work(udp_tunnel_nic_workqueue, &utn->work); - utn->work_pending = 1; - } + if (may_sleep || utn->need_replay) + queue_delayed_work(udp_tunnel_nic_workqueue, &utn->work, 0); } static bool @@ -705,10 +701,16 @@ udp_tunnel_nic_replay(struct net_device *dev, struct udp_tunnel_nic *utn) static void udp_tunnel_nic_device_sync_work(struct work_struct *work) { struct udp_tunnel_nic *utn = - container_of(work, struct udp_tunnel_nic, work); + container_of(work, struct udp_tunnel_nic, work.work); - rtnl_lock(); - utn->work_pending = 0; + /* We cannot block on RTNL here, otherwise we would deadlock with + * udp_tunnel_nic_unregister() calling cancel_delayed_work_sync() + * while holding RTNL. Requeue with 1 jiffy delay if RTNL is contended. + */ + if (!rtnl_trylock()) { + queue_delayed_work(udp_tunnel_nic_workqueue, &utn->work, 1); + return; + } __udp_tunnel_nic_device_sync(utn->dev, utn); if (utn->need_replay) @@ -727,7 +729,7 @@ udp_tunnel_nic_alloc(const struct udp_tunnel_nic_info *info, if (!utn) return NULL; utn->n_tables = n_tables; - INIT_WORK(&utn->work, udp_tunnel_nic_device_sync_work); + INIT_DELAYED_WORK(&utn->work, udp_tunnel_nic_device_sync_work); utn->entries = kmalloc_array(n_tables, sizeof(void *), GFP_KERNEL); if (!utn->entries) @@ -868,11 +870,11 @@ udp_tunnel_nic_unregister(struct net_device *dev, struct udp_tunnel_nic *utn) */ udp_tunnel_nic_flush(dev, utn); - /* Wait for the work to be done using the state, netdev core will - * retry unregister until we give up our reference on this device. + /* Make sure no work is running or queued before freeing @utn. + * The work handler uses rtnl_trylock(), so it will not deadlock + * against the RTNL we are holding here. */ - if (utn->work_pending) - return; + cancel_delayed_work_sync(&utn->work); udp_tunnel_nic_free(utn); release_dev: -- 2.53.0