From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DDB735E1B9 for ; Tue, 16 Jun 2026 12:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781612603; cv=none; b=e/tImyuuRwDjaJup+lLDl+yLGwRa0DFBOd4LHmMa3sYTYSCl8ASiDvZpYo7S5ClzJgWtc/5rHY1AME5+6OqPoyDQDJjNrbkdREzO+54LVJMSHfbwWyKNlLsRweMvjeUFDkOJDswWwHqeoXTxslAHDHb79nxvuoY6Xi78E0brAas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781612603; c=relaxed/simple; bh=yVeUvNux++Yj4q5eneVR9Cq6halnoFWGaX88rxVeWhQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fs/LPwpIVlp/+rDOZmLWZPzF6/Y5YOqJPwXadaVOx3dQKgri15Q2uan7JtBypX6Z6fGY2+Q3CClY0kKK7KSb+xHQrXvjw/7yfHQ22HWg9ZkeeU5WBmqYeN2HOrOtXLT38RkcBpGLlTlfuaN8k13urmf03V9XfYwnAxgOIUlQRY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mFuU5ZeX; arc=none smtp.client-ip=74.125.82.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mFuU5ZeX" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-30bbb1bc064so690189eec.1 for ; Tue, 16 Jun 2026 05:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781612601; x=1782217401; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=g3qEhg0IM5Q+9NZam+NDsCeaeWf8gVayCaGPWh17VjI=; b=mFuU5ZeXUkgeZYjOK++WMeKJC1/Q1nGEdiLtla/121BfEZ+o7b1enKdKDydQyF+IM8 EbXSWi1oOoBFmQFD+O4IRUPjsZjQJfmeZcafXAirwvOxVXsrIWRlpB5jkT5bClm+VFJI /ZS7tmvmnW0VohieLq8+k2+OC97cb7jfKeYTYMkH5ivujBHzdhErJqCWa4uQvCeH2it3 mxfnXoW25TkC9Aeie9DNsK2IPEROLku6dii0k1focEBshbK0GKQ2jc/f+XYvVMJOgKlt VxAEblv0Wt0jvbzSH8f4TIokHiZcremh5DfAJkawgi0AExnEx2NGLBvunlhXiJ16+L5a iMuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781612601; x=1782217401; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=g3qEhg0IM5Q+9NZam+NDsCeaeWf8gVayCaGPWh17VjI=; b=cKzbUeFPTU80GWxLk3pmEpAvpB1X1ccSrCpS6iuP/h2C0RCmGQFtGFY0ocKCLwpTM6 p/sAjhsdQJGSWjUtHGSuv6GbUHxvCVp7L82zB8YIFRn5/gmrPBGTBoLj7KCSyGDaF27p 7DqX+PaXJzWwUrHcWf0PezrlP77eE2upVUQD0rhwkkj/caHQGl2mgxyAlfSnNvuH6a1J Dy2BidwvTy8ZlDCmIJQTo3iMZKdZx2l+tVgW70p3gj/7MC6er45S1PwOHNbnMV7e40Mu NwbO/6mB3UyUoDxh6IsKg6Hj/EaXh16j3DKfuJoFTs2W+x4fckun64thms72AG5Xo4V1 oUqA== X-Forwarded-Encrypted: i=1; AFNElJ9rP6SsIq2s2hkfkOr6ceT7uqB2J3qJSv7itkUjdlT9pqZNv/+9i546NkWzvIQNwOJ/CzABoDwIxtFlMSc=@vger.kernel.org X-Gm-Message-State: AOJu0YxJR5GKhPX56MM5ahTIC0mlntEhSjYZvqECUCAr6C0yQ+AKRjx3 jR0bqmF5i948h2kdDHFfREMz6iKslsn2Pxe2omFxJkO7P5+UzWluQl1r X-Gm-Gg: Acq92OFOFV+hcwnJGD9NKzRq2mx5UoUpnQ0OwHkobxDSwl/oOWxQjZCV6akwbekQYi/ qg5jKsQOCjb3rTawARKRm177QSkZjSUEaA/ypy5860uZyO1jssqQgwRgqPA9IGmijmD+PJbqBtV TTNs7ybYOsOUb7zkRickqGk9SGV4XqB5m6mSRT1p+coOYkHi7kY37eALTrFIkdl4IIbocw6+M8+ NcmibvtR3fY2OQwNE8PwgEjwCkcvkw42PTDUJPG1u8yDDsQBxxtJpCit/4T/0taa5HAFDpwdIQq 72UvR0u7X2SC6eEtpKOJWoe8CMTbOiHJxHhIlpz99Hx1C/jt/DbQXuTmWlh2i8aXjBxMxVXgFlg NVdKjlLlWt/JOXNr5NBhel9kNc250Eo8VQf3XKcMOjl/cVSSAMWbbkFqtIL/rEVbfQrVPJcP6Xx sJx3Vkgao+Oo0Z67ILca8QrjWdEWcHKuhdimmp3Y7NXMLhsbsGSgOsrVQWp6KIO+Ui3wTJ X-Received: by 2002:a05:693c:37c2:b0:304:fa0d:85ba with SMTP id 5a478bee46e88-30ba59856damr2198824eec.12.1781612598945; Tue, 16 Jun 2026 05:23:18 -0700 (PDT) Received: from fx.tailc0aff1.ts.net ([206.206.192.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3081ea43b80sm18001224eec.21.2026.06.16.05.23.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 05:23:18 -0700 (PDT) From: Weiming Shi To: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: jmaloy@redhat.com, ying.xue@windriver.com, tung.quang.nguyen@est.tech, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, davem@davemloft.net, xmei5@asu.edu, Weiming Shi Subject: [PATCH net v2] tipc: fix use-after-free of the discoverer in tipc_disc_rcv() Date: Tue, 16 Jun 2026 05:22:47 -0700 Message-ID: <20260616122246.3136462-2-bestswngs@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit bearer_disable() frees b->disc with tipc_disc_delete()'s plain kfree(), but tipc_disc_rcv() still dereferences b->disc in RX softirq under rcu_read_lock() (tipc_udp_recv -> tipc_rcv -> tipc_disc_rcv). L2 bearers are safe thanks to the synchronize_net() in tipc_disable_l2_media(), but the UDP bearer defers that call to the cleanup_bearer() workqueue, so the discoverer is freed with no grace period: BUG: KASAN: slab-use-after-free in tipc_disc_rcv (net/tipc/discover.c:149) Read of size 8 at addr ffff88802348b728 by task poc_tipc/184 tipc_disc_rcv (net/tipc/discover.c:149) tipc_rcv (net/tipc/node.c:2126) tipc_udp_recv (net/tipc/udp_media.c:391) udp_rcv (net/ipv4/udp.c:2643) ip_local_deliver_finish (net/ipv4/ip_input.c:241) Freed by task 181: kfree (mm/slub.c:6565) bearer_disable (net/tipc/bearer.c:418) tipc_nl_bearer_disable (net/tipc/bearer.c:1001) The bearer is freed with kfree_rcu(); free the discoverer the same way. Add an rcu_head to struct tipc_discoverer and free it and its skb from an RCU callback. Because the RCU callback (tipc_disc_free_rcu) lives in module text, a call_rcu() that is still pending when the tipc module is unloaded would invoke a freed function. Add an rcu_barrier() to tipc_exit() after the bearer subsystem has been torn down, so all pending discoverer callbacks have run before the module text goes away. Reachable from an unprivileged user namespace: the TIPCv2 genl family is netnsok and its bearer commands have no GENL_ADMIN_PERM. Needs CONFIG_TIPC and CONFIG_TIPC_MEDIA_UDP. Fixes: 25b0b9c4e835 ("tipc: handle collisions of 32-bit node address hash values") Reported-by: Xiang Mei Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Weiming Shi --- v2: - split the over-80-column container_of() line (Tung Quang Nguyen) - add rcu_barrier() to tipc_exit() so a pending call_rcu() cannot fire into freed module text after rmmod (Eric Dumazet) net/tipc/core.c | 3 +++ net/tipc/discover.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/net/tipc/core.c b/net/tipc/core.c index 434e70eabe08..747328e58d30 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -218,6 +218,9 @@ static void __exit tipc_exit(void) unregister_pernet_device(&tipc_net_ops); tipc_unregister_sysctl(); + /* Wait for tipc_disc_free_rcu() callbacks queued from module text. */ + rcu_barrier(); + pr_info("Deactivated\n"); } diff --git a/net/tipc/discover.c b/net/tipc/discover.c index 3e54d2df5683..696b7a8ed54d 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c @@ -58,6 +58,7 @@ * @skb: request message to be (repeatedly) sent * @timer: timer governing period between requests * @timer_intv: current interval between requests (in ms) + * @rcu: RCU head for deferred freeing */ struct tipc_discoverer { u32 bearer_id; @@ -69,6 +70,7 @@ struct tipc_discoverer { struct sk_buff *skb; struct timer_list timer; unsigned long timer_intv; + struct rcu_head rcu; }; /** @@ -382,6 +384,15 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b, return 0; } +static void tipc_disc_free_rcu(struct rcu_head *rp) +{ + struct tipc_discoverer *d = + container_of(rp, struct tipc_discoverer, rcu); + + kfree_skb(d->skb); + kfree(d); +} + /** * tipc_disc_delete - destroy object sending periodic link setup requests * @d: ptr to link dest structure @@ -389,8 +400,7 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b, void tipc_disc_delete(struct tipc_discoverer *d) { timer_shutdown_sync(&d->timer); - kfree_skb(d->skb); - kfree(d); + call_rcu(&d->rcu, tipc_disc_free_rcu); } /** -- 2.43.0