Article View: linux.kernel.netdev
Article #21186[PATCH net-next 08/15] batman-adv: tt: don't queue local events for unhashed entries
From: Simon Wunderlich
Date: Mon, 23 Nov 2026 17:18
Date: Mon, 23 Nov 2026 17:18
254 lines
18517 bytes
18517 bytes
From: Sven Eckelmann <sven@narfation.org>
batadv_tt_local_add() looks up the local entry via RCU only.
batadv_tt_local_purge_pending_clients() or batadv_tt_local_remove() can
unhash it before the entry is modified and an event is queued for it:
CPU0 CPU1
/* DEL#1 queued, PENDING set */
batadv_tt_local_hash_find()
batadv_tt_local_commit_changes()
..._purge_pending_clients()
hlist_del_rcu(&...->hash_entry);
/* DEL#1 announced */
batadv_tt_local_refresh()
flags &= ~..._PENDING;
/* ADD queued for unhashed entry */
The queued event will then be announced for a client which is not part
anymore of the table (+ its CRC). A full table request in this and similar
scenarios is required to fix the inconsistency.
Only the hash bucket list_lock can ensure that an entry is still part of
the local table. batadv_tt_local_refresh() therefore checks with
hlist_unhashed() under this lock whether the entry is still hashed. An
entry which is no longer hashed is not refreshed and batadv_tt_local_add()
creates a new entry instead. batadv_tt_local_insert() adds this entry to
the hash and queues its initial ADD under the same list_lock. Otherwise
batadv_tt_local_commit_changes() could count the entry in the CRC of a ttvn
before its ADD was queued or batadv_tt_local_remove() could unhash it
before the ADD was queued.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930094558.3723766-2-sw%40simonwunderlich.de?part=7
Closes: https://sashiko.dev/#/bug/linux-557fd001-5041-4b0a-a2ea-cdf22526ee84
Closes: https://sashiko.dev/#/bug/linux-c7f17a4b-620f-4307-a058-be6523cc6fa2
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/translation-table.c | 156 ++++++++++++++++++++++++-----
1 file changed, 129 insertions(+), 27 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 7968931d5d3c..2828e362640a 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -966,7 +966,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
}
/**
- * batadv_tt_local_refresh() - refresh a local TT entry of an active client
+ * batadv_tt_local_refresh_locked() - refresh a hashed local TT entry
* @bat_priv: the bat priv with all the mesh interface information
* @tt_local: the local TT entry to refresh
* @iif_is_wifi: whether the client is connected via a wifi interface
@@ -980,19 +980,23 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
* updated. An ADD event is queued when @announce is set, the pending removal
* was cancelled or a flag announced to the other nodes was modified.
*
- * All checks and modifications of the flags and the queueing of the ADD event
- * happen in a single flags_lock section. The announced flags are therefore the
- * ones which were just stored in the entry.
+ * The caller must hold the hash bucket list_lock of the entry and must have
+ * checked that the entry is still part of the local table.
*/
static void
-batadv_tt_local_refresh(struct batadv_priv *bat_priv,
- struct batadv_tt_local_entry *tt_local,
- bool iif_is_wifi, u32 mark, bool announce,
- bool *roamed_back)
+batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local,
+ bool iif_is_wifi, u32 mark, bool announce,
+ bool *roamed_back)
{
struct batadv_tt_common_entry *common = &tt_local->common;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
u8 remote_flags;
u32 match_mark;
+ u32 i;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ lockdep_assert_held(&hash->list_locks[i]);
scoped_guard(spinlock_bh, &common->flags_lock) {
if (common->flags & BATADV_TT_CLIENT_PENDING) {
@@ -1053,6 +1057,109 @@ batadv_tt_local_refresh(struct batadv_priv *bat_priv,
}
}
+/**
+ * batadv_tt_local_refresh() - refresh a local TT entry of an active client
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_local: the local TT entry to refresh
+ * @iif_is_wifi: whether the client is connected via a wifi interface
+ * @mark: the value contained in the skb->mark field of the received packet (if
+ * any)
+ * @roamed_back: set to true when the client returned to its original location
+ *
+ * See batadv_tt_local_refresh_locked() for the actual refresh.
+ *
+ * Return: 0 if the entry was refreshed, -ENOENT if the entry is no longer part
+ * of the local table.
+ */
+static int
+batadv_tt_local_refresh(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local,
+ bool iif_is_wifi, u32 mark, bool *roamed_back)
+{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct batadv_tt_common_entry *common = &tt_local->common;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ u32 i;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ list_lock = &hash->list_locks[i];
+
+ WRITE_ONCE(tt_local->last_seen, jiffies);
+
+ spin_lock_bh(list_lock);
+
+ /* the entry was removed from the local table after it was looked up */
+ if (hlist_unhashed(&common->hash_entry)) {
+ spin_unlock_bh(list_lock);
+ return -ENOENT;
+ }
+
+ batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi, mark,
+ false, roamed_back);
+
+ spin_unlock_bh(list_lock);
+
+ return 0;
+}
+
+/**
+ * batadv_tt_local_insert() - add a new local TT entry to the local table
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_local: the new local TT entry (not yet hashed)
+ * @iif_is_wifi: whether the client is connected via a wifi interface
+ * @mark: the value contained in the skb->mark field of the received packet (if
+ * any)
+ * @roamed_back: set to true when the client returned to its original location
+ *
+ * The entry is inserted into the local hash and its initial ADD event is
+ * queued under the same hash bucket list_lock. A concurrent
+ * batadv_tt_local_commit_changes() can therefore not count the entry in the
+ * CRC of a ttvn before its ADD was queued and a concurrent
+ * batadv_tt_local_remove() can not unhash it before the ADD was queued.
+ *
+ * Return: true if the entry was added, false if the client already has an
+ * entry in the local table.
+ */
+static bool batadv_tt_local_insert(struct batadv_priv *bat_priv,
+ struct batadv_tt_local_entry *tt_local,
+ bool iif_is_wifi, u32 mark,
+ bool *roamed_back)
+{
+ spinlock_t *list_lock; /* protects write access to the hash lists */
+ struct batadv_tt_common_entry *common = &tt_local->common;
+ struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ struct hlist_head *head;
+ struct hlist_node *node;
+ u32 i;
+
+ i = batadv_choose_tt(&common->key, hash->size);
+ head = &hash->table[i];
+ list_lock = &hash->list_locks[i];
+
+ spin_lock_bh(list_lock);
+
+ hlist_for_each(node, head) {
+ if (!batadv_compare_tt(node, &common->key))
+ continue;
+
+ spin_unlock_bh(list_lock);
+ return false;
+ }
+
+ /* reference for the hash */
+ kref_get(&common->refcount);
+ hlist_add_head_rcu(&common->hash_entry, head);
+ atomic_inc(&hash->generation);
+
+ /* announce the added client to the mesh */
+ batadv_tt_local_refresh_locked(bat_priv, tt_local, iif_is_wifi, mark,
+ true, roamed_back);
+
+ spin_unlock_bh(list_lock);
+
+ return true;
+}
+
/**
* batadv_tt_local_add() - add a new client to the local table or update an
* existing client
@@ -1073,10 +1180,9 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
struct batadv_tt_global_entry *tt_global = NULL;
struct batadv_tt_local_entry *tt_local;
bool roamed_back = false;
- bool added = false;
bool iif_is_wifi;
bool ret = false;
- int hash_added;
+ int err;
iif_is_wifi = batadv_tt_iif_is_wifi(dev_net(mesh_iface), ifindex);
@@ -1086,30 +1192,26 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
if (tt_local) {
- WRITE_ONCE(tt_local->last_seen, jiffies);
- } else {
+ err = batadv_tt_local_refresh(bat_priv, tt_local, iif_is_wifi,
+ mark, &roamed_back);
+ if (err == -ENOENT) {
+ /* stale entry which has to be replaced by a new one */
+ batadv_tt_local_entry_put(tt_local);
+ tt_local = NULL;
+ }
+ }
+
+ if (!tt_local) {
tt_local = batadv_tt_local_create(mesh_iface, addr, vid, iif_is_wifi);
if (!tt_local)
goto out;
- kref_get(&tt_local->common.refcount);
- hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
- batadv_choose_tt, &tt_local->common.key,
- &tt_local->common.hash_entry);
-
- if (unlikely(hash_added != 0)) {
- /* remove the reference for the hash */
- batadv_tt_local_entry_put(tt_local);
+ if (unlikely(!batadv_tt_local_insert(bat_priv, tt_local,
+ iif_is_wifi, mark,
+ &roamed_back)))
goto out;
- }
-
- added = true;
}
- /* announce the (re-)added client or its modified flags to the mesh */
- batadv_tt_local_refresh(bat_priv, tt_local, iif_is_wifi, mark, added,
- &roamed_back);
-
batadv_tt_local_add_roam(bat_priv, tt_global, roamed_back);
ret = true;
--
2.47.3
Technical Details
Message-ID:
<20261123171827.3294525-9-sw@simonwunderlich.de>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369604-linux-kernel-netdev=dewy.ruReferences:
<20261123171827.3294525-1-sw@simonwunderlich.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369604-linux-kernel-netdev=dewy.ru From: sw@simonwunderlich.de (Simon Wunderlich) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next 08/15] batman-adv: tt: don't queue local events for unhashed entries Date: Mon, 23 Nov 2026 18:18:20 +0100 Organization: Usenet Network Message-ID: <20261123171827.3294525-9-sw@simonwunderlich.de> References: <20261123171827.3294525-1-sw@simonwunderlich.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3939586"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:vSzyQ9S03tHcUi56uB8j+T+MZtY= sha256:LUjgFaMdgHe9SJvHS57LUSQLuw7dmpte5voV+SE/Orc= sha1:Hn6RSpp05+LZ77uXBNF6DAlCq3I= sha256:LJLOb99u0gIkyjpMxhV7i1DY1n/h2opxgOrOEt2KrA8= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id F299B125DC0; Mon, 23 Nov 2026 20:25:44 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=simonwunderlich.de X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 88F5fxIh1gZh; Mon, 23 Nov 2026 20:25:41 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369604-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=simonwunderlich.de X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id C2D3E125DC2; Mon, 23 Nov 2026 20:25:35 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 671273858E; Mon, 23 Nov 2026 17:18:46 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795454323; b=E8LMjB2XjWF51RAVWjzaaqmS7yFJOvvxm99nuKswh+fRFC8I8Xhumga8EmtaeXGbaxqk zX1zFWCEzwk/aZX9gjI57KjBdGCJS9OfLOvwqCvtSmu9rXG3NodVf0kusGuB97U8RSbVC BHg/SvxrlDR2Ms54xC2G126xwk63OxfcA4QvlZKFAN+ICjspA0uw4qvS16YuZ5hI39wN6 N7j36GO4dnLEEeQbwPpRS1GRmJJs4tFKx+UAP4pmKGEp5yiGZviljBhZdQY07PWA5TqHB CtkhQEBjcswgAn9+SUK99hX15YOtvfXrR+6fM95PpLxdxPyXO3dEZUHnRgjom7IHeSw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795454323; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To: Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=HTSxq5AdXzXnAkXTGC23vo77Fv+9+l048NGGD4ATRx0=; b=wFge9+jH/Pr15+lcF9onDLrAgzQfoKsmMYAZEB5Z6Rk15F8BdDwp6Bof/9/zfOs1tgi3 B6pQtup2hNy6DoXTbavDeOeY/nBqw7+0/k2VU8bAVntifeow5kWyjYUgtYfXoIO9upUBp MAor2EHDQVM7qyGv7+q/SHsNt6KsthN5pnH6amDKhqsYEhwabGOg1qasPc9bCHMMBzUUX 5h4dWeGWoiet+510Er6xlMPdqkltZnX78g7vC+3eu/rFxnlxneIcHJchV7jMnMaT+zkoP +NiZ4+w96IfIzHtDi5tOedSDly9KIAEkrgOs8ruRONAl3wb75z+I/35wdx76FyZ+wxw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=PjPs9Fhl; dmarc=pass header.from=simonwunderlich.de; spf=pass smtp.mailfrom=simonwunderlich.de; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23682606A69C; Mon, 23 Nov 2026 17:18:43 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=PjPs9Fhl X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=23.88.38.48 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795454322; b=pFhie6yK++Z7izV0V6d2yCe/vw4BnTp5/JBmbtm696FEJ3PSywB0TTKCsj+tXfCjLYmV K1GC6Hzd8htz9SsA8Pc2yDP6DEJQLWs1Ke/nfyPvHhRFua3RXsGMaRDE3PLeg2lodF0xN /ieOxyboc+5dYE+FOAjCD3O4QfCnqEuBZQc0YnpseHiTCGBjbQghoOCtU4rlJDob/SPAa 5HqoSnygmDoLGzpE98bN8XrfRJHKz8xeoRj+zfAB2a3d2RcFR3LQG1wBtUtuYmPJlZpXh AN1ZMQUpu6XZIa43rlmzyemiRvgp5TQXVslnVvd/hhUhWzgCV9t5dgWQvtRqpOZxgsw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795454322; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=HTSxq5AdXzXnAkXTGC23vo77Fv+9+l048NGGD4ATRx0=; b=hlXX8YEp8pQmNkBFx2xV8DssfzVOMioAInfwSSjbnFIqvDuzRKhJMmM0tDJVqnPIqYAj 3Ad+w/ndr+RweO5JxTev+A4sG+lekfxjwroNTmTf0NKghbirfj8DzqPvfQd5SsxttYvVJ WZC5Ny4UVl4hn2lr1TAAWLB7+Dv9OxfUYT0hcX0jGivBHUYprTht12XBm+J2CsHa3cOjP i+cAX2lgGKsGfqRF0INKv/s4Zta0MHnE2hHSKqjkKxPxu1Z2qcIpFvcNFju9DIzIolDhV 4gBvtaDAujq+3GI8qcFJ6sXh8ywfl/hRpDaQUYLm4f2wAW2fTLZHT0a1yQO42aNUVQg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=simonwunderlich.de; spf=pass smtp.mailfrom=simonwunderlich.de; dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=PjPs9Fhl; arc=none smtp.remote-ip=23.88.38.48 X-Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id C084D606A680 for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 17:18:41 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C084D606A680 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de X-Received: from kero.packetmixer.de (p200300C59714c2E05a704819b6BA2db4.dip0.t-ipconnect.de [IPv6:2003:c5:9714:c2e0:5a70:4819:b6ba:2db4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with UTF8SMTPSA id A0E14FA3E1; Mon, 23 Nov 2026 18:18:39 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de; s=09092022; t=1795454319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTSxq5AdXzXnAkXTGC23vo77Fv+9+l048NGGD4ATRx0=; b=PjPs9FhlDvXPCiBzJ7gaAKLYxthPHgTeEg+8SL7fKk624ew3+ukufVL6YHj3UtjYvgMguv e1fdaK5nyosLEcPspAwzuvPuJSFHZQupkvYDDrUhgJTYoG3lna/7jGTCxoNSgf4EPOEVLT ZNt6NeZv0OvK5Tl9NaLbWaGb0aTnHT7tusec3K45MX29vL+QYDOL5gLUl31dPU/B4Zh0s0 1AZXSF0sZ6pBEb/4jPfZp5SL8Ld3RUV77Wcvl1AJHo1u+TaxjtU9wEuTFhoqvPgT6iURD5 8RaG2AnuKHV9pevoM2lHOwSgGAe7HakgGrRsBb/LMRUkFOzlfEtpoGFANecLIg== X-Cc: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, b.a.t.m.a.n@lists.open-mesh.org, Sven Eckelmann <sven@narfation.org>, Sashiko <sashiko-bot@kernel.org>, Simon Wunderlich <sw@simonwunderlich.de> X-Mailer: git-send-email 2.47.3 X-In-Reply-To: <20261123171827.3294525-1-sw@simonwunderlich.de> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list