From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 14A453FF889 for ; Fri, 31 Jul 2026 10:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785493342; cv=none; b=GXhZNxTXEFTa85+nca7kcF/fsBEZTsKECSfQEnQESWeldQKd68MCwjuJ/HSpd2kRZsHL/nKfFYaeNvVf1g4SS3bC7cwSLUuGI7N2QTc7R3yzxZTytaWgxLB+8I6aYiA5BKROrbSNzoBoxBsok8E1XtG6PHkjglUGHw+XhUYVqzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785493342; c=relaxed/simple; bh=4VcKVUvyWU1HN+BHXSPwtW/RIhweQaUqjTDSxbgd9kw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OcdobOATuoq2opajBZDhBZS6i/OWbv+bg1cZF6nh2XblHZfcy14woTsN8h5D3Bx9f4i9moev3uuqA8b7kpB6rWgNjl/lpjHHnaRk8CFx5zc3KPwQEQg/j4Lci4Ponv679PKui/ATDhIRWzCXSlMXQlX2iOWssvI35O5GnUEM6B8= 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=XeMl+8G4; arc=none smtp.client-ip=209.85.210.176 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="XeMl+8G4" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-848479c9bd5so726175b3a.3 for ; Fri, 31 Jul 2026 03:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785493334; x=1786098134; 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:content-type; bh=zamWU58jYttudwlzY04AXQugAWUn6boGIsckkOCHePs=; b=XeMl+8G4DG5osSRdqkbfOUX0OZAoJqJAYs+qOsS0oD0vF8p7sNMiLUUySymECYM6OJ tsaUeK/FtLBxNuzrWTpUmVxKLaAOP8StaOUAFJjfGn0wka1oq5Ilqr61bV0EGugK5vV/ CEExu4Ss7+JBK+lqFZRPyhVXjDTdCBzxy/1Ij37t6JSgIwpXNoAfeyovrV855a0CpjUw m12N2R6vKOGCA0c2C6d623++0c7mgxjvyM+0fGSi1bJsxDBbC9ZVgEg4ZUWc8QiNjgZJ 6HQeJsATGQlT3Ph4fF44SY8TAjOvkFwCcJ/njTHxIZwhPZKPkrDm1cTLmC0zDSLOkJ/a /vug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785493334; x=1786098134; 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:content-type; bh=zamWU58jYttudwlzY04AXQugAWUn6boGIsckkOCHePs=; b=URPRho68APpvfExUnKq1Yq+8R+xwLtCsfbTunbXZJTyNv+HHox9As36pil3rs5Mb7a SQe4Tb+JxXLhJjEj7+XhdG96pG1LtroypCQAaALT83jazpt5bIKGViVFVxV/Q1OxfRKn Ctj9GFelfBMl6OBa+0t/GzXrbB0T77Qfu7JznynAasdjn5TTRmnCcywaIa17DQYF3crz a3veefqHuAfBb4SArJU91VWuEwkVa3dSR5bMLrgudJFitPVdVeIXXJmw5aHryFPQqYq5 Ph0bOPs+g8eC7c5Hd3/GtXt7yfOp3+glurFyU00jjxyHf77++TERApx1xTJFEUd+hnmV C22g== X-Forwarded-Encrypted: i=1; AHgh+RrE2AP0l/mykZXiPYjED8QGgmIrvsX270q+/6ag93kCFtaalGq5WPiekA3Bir5IBCSXsKhssFGo/S0G/zI=@vger.kernel.org X-Gm-Message-State: AOJu0Ywf3iP0oI6OM50gbRT0aiEdWYLdYRQC23hKUDNvTTJ4iiy/n88T A8zU2CKTxybAHJlw5wq9D+eOvF7bPAcYwPIAK7ot1LszWYK1VFO0YQW1 X-Gm-Gg: AR+sD10afKjy+rlH6plKxRmWIIsRjJe091BwFqpWKI5bRqe4iklS2zsNuB6hHEpDERm JCFa2JIjlDK4lIDelewoBkDuJShTjtFuVnOYBHK0Fm5hzwwuo+aBD81bhwJxspooSjnUxbiZUFi WwKq3QdTxTBJxUglZtltjd7lJ/Jj419DPKg+wQZGz7VmZjbOCQaMOcu60n4ZeI62PiS9Y0XSOKh Coq5u9UGMiUYXJ59g5cRq1eNhOaJ7m+iAyDWXK6tsi4PHZVVFyEC+4XeIlEsUaBIFlJhBsx4Tch olv/O5S5HgPLdzvW+DQhfAJPD67swrLyvRzB/rE1zsqazpoutHhDtszPwEZ74jsyg8Fos+eQX1Q tjl+v85Ag7FqzS/DQMyByxdgIYx3X28wTKh7tZqEuAmDxuI6kvlaC2v8vuQRwXRNnQjMHBsMT4p JxudvCojRU+aU8CWdK3D6BA+X7idYtVmGlZTB1c9OWlzox74rmnngk13tAt152ToUrRzZsrmHJv SyJzC2ow7EIzHVpjqG/Le4oZVk= X-Received: by 2002:a05:6a00:2d9d:b0:848:4fd9:9a8d with SMTP id d2e1a72fcca58-84ed6f1e5d3mr1251126b3a.59.1785493333569; Fri, 31 Jul 2026 03:22:13 -0700 (PDT) Received: from JUNVYYANG-MC1.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84edc2d45afsm265024b3a.41.2026.07.31.03.22.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 31 Jul 2026 03:22:13 -0700 (PDT) From: Jun Yang To: netdev@vger.kernel.org Cc: Jun Yang , stable@kernel.org, TencentOS Corvus AI , Jon Maloy , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Ying Xue , tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH net] tipc: read le->link under the node lock in tipc_node_link_down() Date: Fri, 31 Jul 2026 18:20:58 +0800 Message-ID: <20260731102145.33622-1-juny24602@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jun Yang tipc_node_link_down() caches the link pointer before taking n->lock: struct tipc_link *l = le->link; /* unlocked */ if (!l) return; tipc_node_write_lock(n); if (!tipc_link_is_establishing(l)) { /* deref l */ ... tipc_link_reset(l); /* write into l */ if (delete) { kfree(l); le->link = NULL; The delete=true caller frees that very object under n->lock, so the lock does not protect the cached pointer against it: - CPU A, delete=false: tipc_rcv() on TIPC_LINK_DOWN_EVT, or the link supervision timer via tipc_node_timeout(), reads l unlocked and then dereferences it under n->lock; - CPU B, delete=true: netlink TIPC_NL_BEARER_DISABLE -> bearer_disable() -> tipc_node_delete_links() -> tipc_node_link_down(n, bearer_id, true) -> kfree(l). The link is freed with plain kfree(), not kfree_rcu(), and for UDP bearers disable_media() only schedules the asynchronous cleanup_bearer() work, so its synchronize_net() runs after the links are already gone. An in-flight CPU A that has read l therefore dereferences freed memory once B frees it: a use-after-free read in tipc_link_is_establishing(), and a use-after-free write via tipc_link_reset() on the establishing branch. BUG: KASAN: slab-use-after-free in tipc_link_is_establishing+0x3f/0x50 Read of size 4 at addr ffff888111f90868 by task swapper/3/0 tipc_link_is_establishing+0x3f/0x50 tipc_node_link_down+0x1a0/0x450 tipc_node_timeout+0x63d/0xca0 Allocated by task 7903: tipc_link_create+0x17e/0xf20 tipc_node_check_dest+0x98b/0x1150 tipc_disc_rcv+0x9f3/0x10c0 tipc_udp_recv+0x42a/0x7e0 Freed by task 7903: tipc_node_link_down+0x301/0x450 tipc_node_delete_links+0xf5/0x240 bearer_disable+0xc0/0x240 __tipc_nl_bearer_disable+0x21f/0x380 Move the le->link read inside tipc_node_write_lock(), so it is serialised against the kfree() in the delete path. A racing teardown now either has not run yet, and we see a valid link, or has already run, and we see NULL. Fixes: 73f646cec354 ("tipc: delay ESTABLISH state event when link is established") Cc: stable@kernel.org Reported-by: TencentOS Corvus AI Signed-off-by: Jun Yang --- net/tipc/node.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/tipc/node.c b/net/tipc/node.c index 8e4ef2630ae4..918e59362d07 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c @@ -1063,16 +1063,23 @@ static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete) { struct tipc_link_entry *le = &n->links[bearer_id]; struct tipc_media_addr *maddr = NULL; - struct tipc_link *l = le->link; int old_bearer_id = bearer_id; struct sk_buff_head xmitq; - - if (!l) - return; + struct tipc_link *l; __skb_queue_head_init(&xmitq); + /* Read le->link under n->lock: the delete path below kfree()s it while + * holding the same lock, so an unlocked read here could be raced by a + * concurrent bearer teardown and leave us with a freed pointer. + */ tipc_node_write_lock(n); + l = le->link; + if (!l) { + tipc_node_write_unlock(n); + return; + } + if (!tipc_link_is_establishing(l)) { __tipc_node_link_down(n, &bearer_id, &xmitq, &maddr); } else { -- 2.55.0