public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] batman-adv: Don't accept TT entries for out-of-spec VIDs
       [not found] <20240621143915.49137-1-sw@simonwunderlich.de>
@ 2024-06-21 14:39 ` Simon Wunderlich
  2024-06-22  1:20   ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Wunderlich @ 2024-06-21 14:39 UTC (permalink / raw)
  To: davem, kuba
  Cc: netdev, b.a.t.m.a.n, Sven Eckelmann, stable, Linus Lüssing,
	Simon Wunderlich

From: Sven Eckelmann <sven@narfation.org>

The internal handling of VLAN IDs in batman-adv is only specified for
following encodings:

* VLAN is used
  - bit 15 is 1
  - bit 11 - bit 0 is the VLAN ID (0-4095)
  - remaining bits are 0
* No VLAN is used
  - bit 15 is 0
  - remaining bits are 0

batman-adv was only preparing new translation table entries (based on its
soft interface information) using this encoding format. But the receive
path was never checking if entries in the roam or TT TVLVs were also
following this encoding.

It was therefore possible to create more than the expected maximum of 4096
+ 1 entries in the originator VLAN list. Simply by setting the "remaining
bits" to "random" values in corresponding TVLV.

Cc: stable@vger.kernel.org
Fixes: 7ea7b4a14275 ("batman-adv: make the TT CRC logic VLAN specific")
Reported-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/originator.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index ac74f6ead62d..8f6dd2c6ee41 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/etherdevice.h>
 #include <linux/gfp.h>
+#include <linux/if_vlan.h>
 #include <linux/jiffies.h>
 #include <linux/kref.h>
 #include <linux/list.h>
@@ -131,6 +132,29 @@ batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
 	return vlan;
 }
 
+/**
+ * batadv_vlan_id_valid() - check if vlan id is in valid batman-adv encoding
+ * @vid: the VLAN identifier
+ *
+ * Return: true when either no vlan is set or if VLAN is in correct range,
+ *  false otherwise
+ */
+static bool batadv_vlan_id_valid(unsigned short vid)
+{
+	unsigned short non_vlan = vid & ~(BATADV_VLAN_HAS_TAG | VLAN_VID_MASK);
+
+	if (vid == 0)
+		return true;
+
+	if (!(vid & BATADV_VLAN_HAS_TAG))
+		return false;
+
+	if (non_vlan)
+		return false;
+
+	return true;
+}
+
 /**
  * batadv_orig_node_vlan_new() - search and possibly create an orig_node_vlan
  *  object
@@ -149,6 +173,9 @@ batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
 {
 	struct batadv_orig_node_vlan *vlan;
 
+	if (!batadv_vlan_id_valid(vid))
+		return NULL;
+
 	spin_lock_bh(&orig_node->vlan_list_lock);
 
 	/* first look if an object for this vid already exists */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] batman-adv: Don't accept TT entries for out-of-spec VIDs
  2024-06-21 14:39 ` [PATCH 1/2] batman-adv: Don't accept TT entries for out-of-spec VIDs Simon Wunderlich
@ 2024-06-22  1:20   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-06-22  1:20 UTC (permalink / raw)
  To: Simon Wunderlich
  Cc: davem, kuba, netdev, b.a.t.m.a.n, sven, stable, linus.luessing

Hello:

This series was applied to netdev/net.git (main)
by Simon Wunderlich <sw@simonwunderlich.de>:

On Fri, 21 Jun 2024 16:39:14 +0200 you wrote:
> From: Sven Eckelmann <sven@narfation.org>
> 
> The internal handling of VLAN IDs in batman-adv is only specified for
> following encodings:
> 
> * VLAN is used
>   - bit 15 is 1
>   - bit 11 - bit 0 is the VLAN ID (0-4095)
>   - remaining bits are 0
> * No VLAN is used
>   - bit 15 is 0
>   - remaining bits are 0
> 
> [...]

Here is the summary with links:
  - [1/2] batman-adv: Don't accept TT entries for out-of-spec VIDs
    https://git.kernel.org/netdev/net/c/537a350d1432
  - [2/2] Revert "batman-adv: prefer kfree_rcu() over call_rcu() with free-only callbacks"
    https://git.kernel.org/netdev/net/c/6bfff3582416

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-22  1:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20240621143915.49137-1-sw@simonwunderlich.de>
2024-06-21 14:39 ` [PATCH 1/2] batman-adv: Don't accept TT entries for out-of-spec VIDs Simon Wunderlich
2024-06-22  1:20   ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox