Received: from diktynna.open-mesh.org (diktynna.open-mesh.org [136.243.236.17]) (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 66AA9606A332 for ; Mon, 2 Nov 2026 21:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=narfation.org header.i=@narfation.org header.a=rsa-sha256 header.s=20121 header.b=GEyF4ePr Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 0B75C81A7E for ; Mon, 02 Nov 2026 22:28:27 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1793654907; b=Kr+EN60B2E8ZruAXHM+yKXkFNAEjm9adyhH30OvrL2hXo+vCrv98tqtIV9EbL1wZefE6f V9dc8ptZMewMdN0JHEuCxItWQzgoWMBylTy8qiEppQGxX1otFmYGB6PtI2ZuV7o5jGAUHkW BxBod7vlIkGiedRQUb6WUDxd7UrqSnI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1793654907; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=Fr/X0cSlEgTqY6EvVQHRXlX0f6l0ozmq4shgxoLBnBY=; b=lXtQWZrG1ZGgm86Dkk0vRcIuU/OAA6ujRcabMyu1kbCJJ0CNk+AYRi8UjVFDuhbU/C4+u tLIXCnrg38qV1eKlISEpzrSq7xouOhI/dmWWA1v39CsJ8RublbgNV0hEtKa/sxuLiOlhoKr zaDZRKKIaumMppEG3JpcVT4but0vdH8= ARC-Authentication-Results: i=2; open-mesh.org; dkim=pass header.d=narfation.org; arc=pass; dmarc=pass header.from=narfation.org policy.dmarc=none Authentication-Results: open-mesh.org; dkim=pass header.d=narfation.org; arc=pass; dmarc=pass (Used From Domain Record) header.from=narfation.org policy.dmarc=none Received: from dvalin.narfation.org (dvalin.narfation.org [213.160.73.56]) by diktynna.open-mesh.org (Postfix) with UTF8SMTPS id B543882E1A for ; Mon, 02 Nov 2026 22:27:09 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; d=open-mesh.org; s=20121; cv=none; t=1793654829; b=ExZQ0vhQ+5p+H663VJlIh6CG7gpjHIR1ruph8N9G4WE3aZfai7ToB1Gj0O9FCeDVCoWiCO 8vm1tcMGI71YFGeQiFbLoaj0U9b9qen4MqUsQSBL0RpAEVX8Fhdj+Odwo64yZbdJoCDfLL sPDnBGNA92pC4p+TFc/rVG+fcL54vP8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1793654829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Fr/X0cSlEgTqY6EvVQHRXlX0f6l0ozmq4shgxoLBnBY=; b=zgCSv2rDRivO4SxDjWUGJVkm60xGEUTlmTh0o6An2le92LlgvjWweJx31ga/fca6AO9Llv xpuLHdUcnjaLEWCOGLQGGRcDYxs1tMm4x46aYmg+rFYuzUXf/Czx+WT2vvWCsNZtJn61Dr o2HS/ZIORfA4lj+yQU+nGeXbHHxrrjw= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=GEyF4ePr; spf=pass (diktynna.open-mesh.org: domain of sven@narfation.org designates 213.160.73.56 as permitted sender) smtp.mailfrom=sven@narfation.org; dmarc=pass (policy=none) header.from=narfation.org Received: by dvalin.narfation.org (Postfix) id 72D081FDF5; Mon, 02 Nov 2026 21:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1793654829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fr/X0cSlEgTqY6EvVQHRXlX0f6l0ozmq4shgxoLBnBY=; b=GEyF4ePrq7zyWvktsqu2r3gp3+844CHwq02GwkzK2SecHhXYcnRaoherKuFzGI7f1XzEFn 0Ot9Kaa+KDNsbiZaWLneX7sO7TFuGe+mNsc7nyna0lON5JxjS+cZuVv85wdE7BhEMM2i/I VSmxIEplZ5TVZk82xQgoaPt2UiqbSi0= From: Sven Eckelmann Date: Mon, 02 Nov 2026 22:26:58 +0100 Subject: [PATCH batadv v4 2/5] batman-adv: limit number of parallel learned originators X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261102-resource-limit-v4-2-7ff9da793db4@narfation.org> References: <20261102-resource-limit-v4-0-7ff9da793db4@narfation.org> In-Reply-To: <20261102-resource-limit-v4-0-7ff9da793db4@narfation.org> To: b.a.t.m.a.n@lists.open-mesh.org Cc: Sven Eckelmann X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6873; i=sven@narfation.org; h=from:subject:message-id; bh=GiMEWd2XzvGFjl0s8HfymbA6EfqFyNCOz+pCvpJBbEg=; b=owGbwMvMwCXmy1+ufVnk62nG02pJDFkvGVRaDMP57H78feymJVLwQmZuRuL87POB3J+C10tuT Yn5O8Gzo5SFQYyLQVZMkWXPlfzzm9nfyn+e9vEozBxWJpAhDFycAjCR7C0Mf+Un23LdCtMtSmX8 v03KtJk36c/5SyLPMzwuuv82n19xPYSRYcp7cW92pZkbWo7MD9l4cp2Jf6IhU8heo3r94JehO0N cmAE= X-Developer-Key: i=sven@narfation.org; a=openpgp; fpr=522D7163831C73A635D12FE5EC371482956781AF Message-ID-Hash: VATEAFYF73KTEBBJQHAI6YJBVCFFD3P5 X-Message-ID-Hash: VATEAFYF73KTEBBJQHAI6YJBVCFFD3P5 X-MailFrom: sven@narfation.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; header-match-b.a.t.m.a.n.lists.open-mesh.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 A malicious actor behind one hardif may spam the kernel with OGMs using a random source MAC address, each of which will create an originator node entry, a dynamic allocation in the kernel. This will at some point exhaust the available memory. Mitigate this by maintaining a per meshif count of those automatically generated entries in orig_learned, and a limit in orig_max_learned. If the limit is hit, new entries are not learned anymore. For backwards compatibility, the default setting of 0 disables the limit. Signed-off-by: Sven Eckelmann --- include/uapi/linux/batman_adv.h | 6 ++++++ net/batman-adv/bat_iv_ogm.c | 15 +++++++++++++-- net/batman-adv/bat_v_ogm.c | 15 +++++++++++++-- net/batman-adv/mesh-interface.c | 3 +++ net/batman-adv/netlink.c | 10 ++++++++++ net/batman-adv/originator.c | 3 +++ net/batman-adv/types.h | 6 ++++++ 7 files changed, 54 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index debd2ae1..e5c1d1d4 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -487,6 +487,12 @@ enum batadv_nl_attrs { */ BATADV_ATTR_NEIGH_MAX_LEARNED, + /** + * @BATADV_ATTR_ORIG_MAX_LEARNED: defines the maximum number of originators + * which can be learned in parallel. 0 disables the limit. + */ + BATADV_ATTR_ORIG_MAX_LEARNED, + /* add attributes above here, update the policy in netlink.c */ /** diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 7b47c253..7e7370dc 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -142,15 +142,26 @@ static struct batadv_orig_node * __must_check batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr) { struct batadv_orig_node *orig_node; + u32 orig_max_learned; + int orig_learned; int hash_added; orig_node = batadv_orig_hash_find(bat_priv, addr); if (orig_node) return orig_node; - orig_node = batadv_orig_node_new(bat_priv, addr); - if (!orig_node) + orig_max_learned = READ_ONCE(bat_priv->orig_max_learned); + orig_learned = atomic_inc_return(&bat_priv->orig_learned); + if (orig_max_learned && orig_learned > orig_max_learned) { + atomic_dec(&bat_priv->orig_learned); return NULL; + } + + orig_node = batadv_orig_node_new(bat_priv, addr); + if (!orig_node) { + atomic_dec(&bat_priv->orig_learned); + return NULL; + } spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock); diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c index 108bb144..de9dff6f 100644 --- a/net/batman-adv/bat_v_ogm.c +++ b/net/batman-adv/bat_v_ogm.c @@ -57,15 +57,26 @@ struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv, const u8 *addr) { struct batadv_orig_node *orig_node; + u32 orig_max_learned; + int orig_learned; int hash_added; orig_node = batadv_orig_hash_find(bat_priv, addr); if (orig_node) return orig_node; - orig_node = batadv_orig_node_new(bat_priv, addr); - if (!orig_node) + orig_max_learned = READ_ONCE(bat_priv->orig_max_learned); + orig_learned = atomic_inc_return(&bat_priv->orig_learned); + if (orig_max_learned && orig_learned > orig_max_learned) { + atomic_dec(&bat_priv->orig_learned); return NULL; + } + + orig_node = batadv_orig_node_new(bat_priv, addr); + if (!orig_node) { + atomic_dec(&bat_priv->orig_learned); + return NULL; + } kref_get(&orig_node->refcount); hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c index a6956720..581ec303 100644 --- a/net/batman-adv/mesh-interface.c +++ b/net/batman-adv/mesh-interface.c @@ -876,6 +876,9 @@ static int batadv_meshif_init_late(struct net_device *dev) atomic_set(&bat_priv->neigh_learned, 0); WRITE_ONCE(bat_priv->neigh_max_learned, 0); + atomic_set(&bat_priv->orig_learned, 0); + WRITE_ONCE(bat_priv->orig_max_learned, 0); + WRITE_ONCE(bat_priv->tt.local_changes, 0); bat_priv->tt.last_changeset = NULL; bat_priv->tt.last_changeset_len = 0; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 21719d30..37b6b925 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -155,6 +155,7 @@ static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_ELP_INTERVAL] = { .type = NLA_U32 }, [BATADV_ATTR_THROUGHPUT_OVERRIDE] = { .type = NLA_U32 }, [BATADV_ATTR_NEIGH_MAX_LEARNED] = { .type = NLA_U32 }, + [BATADV_ATTR_ORIG_MAX_LEARNED] = { .type = NLA_U32 }, }; /** @@ -360,6 +361,10 @@ static int batadv_netlink_mesh_fill(struct sk_buff *msg, READ_ONCE(bat_priv->neigh_max_learned))) goto nla_put_failure; + if (nla_put_u32(msg, BATADV_ATTR_ORIG_MAX_LEARNED, + READ_ONCE(bat_priv->orig_max_learned))) + goto nla_put_failure; + batadv_hardif_put(primary_if); genlmsg_end(msg, hdr); @@ -610,6 +615,11 @@ static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info) nla_get_u32(info->attrs[BATADV_ATTR_NEIGH_MAX_LEARNED])); } + if (info->attrs[BATADV_ATTR_ORIG_MAX_LEARNED]) { + WRITE_ONCE(bat_priv->orig_max_learned, + nla_get_u32(info->attrs[BATADV_ATTR_ORIG_MAX_LEARNED])); + } + batadv_netlink_notify_mesh(bat_priv); return 0; diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index cfe5b3ef..d0aa8936 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -887,9 +887,11 @@ void batadv_orig_node_release(struct kref *ref) struct batadv_neigh_node *neigh_node; struct batadv_orig_node *orig_node; struct batadv_orig_node_vlan *vlan; + struct batadv_priv *bat_priv; struct hlist_node *node_tmp; orig_node = container_of(ref, struct batadv_orig_node, refcount); + bat_priv = orig_node->bat_priv; spin_lock_bh(&orig_node->neigh_list_lock); @@ -921,6 +923,7 @@ void batadv_orig_node_release(struct kref *ref) batadv_mcast_purge_orig(orig_node); + atomic_dec(&bat_priv->orig_learned); call_rcu(&orig_node->rcu, batadv_orig_node_free_rcu); } diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index b938f761..2b7916b5 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -1736,6 +1736,12 @@ struct batadv_priv { /** @neigh_learned: current number of learned neighbors */ atomic_t neigh_learned; + /** @orig_max_learned: Maximum number of originators */ + u32 orig_max_learned; + + /** @orig_learned: current number of learned originators */ + atomic_t orig_learned; + #ifdef CONFIG_BATMAN_ADV_BLA /** @bla: bridge loop avoidance data */ struct batadv_priv_bla bla; -- 2.47.3