Skip to content

Commit 8940351

Browse files
ecsvroxanan1996
authored andcommitted
batman-adv: Don't accept TT entries for out-of-spec VIDs
BugLink: https://bugs.launchpad.net/bugs/2073765 commit 537a350d14321c8cca5efbf0a33a404fec3a9f9e upstream. 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: 7ea7b4a ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Portia Stephens <portia.stephens@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent c9a3e48 commit 8940351

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

net/batman-adv/originator.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/errno.h>
1212
#include <linux/etherdevice.h>
1313
#include <linux/gfp.h>
14+
#include <linux/if_vlan.h>
1415
#include <linux/jiffies.h>
1516
#include <linux/kernel.h>
1617
#include <linux/kref.h>
@@ -131,6 +132,29 @@ batadv_orig_node_vlan_get(struct batadv_orig_node *orig_node,
131132
return vlan;
132133
}
133134

135+
/**
136+
* batadv_vlan_id_valid() - check if vlan id is in valid batman-adv encoding
137+
* @vid: the VLAN identifier
138+
*
139+
* Return: true when either no vlan is set or if VLAN is in correct range,
140+
* false otherwise
141+
*/
142+
static bool batadv_vlan_id_valid(unsigned short vid)
143+
{
144+
unsigned short non_vlan = vid & ~(BATADV_VLAN_HAS_TAG | VLAN_VID_MASK);
145+
146+
if (vid == 0)
147+
return true;
148+
149+
if (!(vid & BATADV_VLAN_HAS_TAG))
150+
return false;
151+
152+
if (non_vlan)
153+
return false;
154+
155+
return true;
156+
}
157+
134158
/**
135159
* batadv_orig_node_vlan_new() - search and possibly create an orig_node_vlan
136160
* object
@@ -149,6 +173,9 @@ batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
149173
{
150174
struct batadv_orig_node_vlan *vlan;
151175

176+
if (!batadv_vlan_id_valid(vid))
177+
return NULL;
178+
152179
spin_lock_bh(&orig_node->vlan_list_lock);
153180

154181
/* first look if an object for this vid already exists */

0 commit comments

Comments
 (0)