All of lore.kernel.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batctl: Validate translated mac addresses
@ 2018-04-13 18:16 Sven Eckelmann
  2018-04-14  2:34 ` Antonio Quartulli
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sven Eckelmann @ 2018-04-13 18:16 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann, Andre Kasper

The IP translation layer is using the neighbor table of the kernel to get
the unicast link layer (mac) address for IP(v4|v6) addresses. The kernel
can not only return unicast mac addresses to such an RTM_GETNEIGH request
but also zero mac address. Such an address must be considered invalid
because the global translation table may not only contain a unique client
mac address entry for it. The translation from client mac to originator
will therefore most likely return an unexpected originator.

Dropping these kind of (bogus) results avoids confusions while using things
like batctl's ping or traceroute.

Reported-by: Andre Kasper <Andre.Kasper@gmx.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Cc: Andre Kasper <Andre.Kasper@gmx.de>

See https://www.open-mesh.org/issues/353
---
 functions.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/functions.c b/functions.c
index cd92b60..3c340a2 100644
--- a/functions.c
+++ b/functions.c
@@ -571,6 +571,19 @@ static struct nla_policy neigh_policy[NDA_MAX+1] = {
 	[NDA_PROBES]    = { .type = NLA_U32 },
 };
 
+static bool ether_addr_valid(const uint8_t *addr)
+{
+	/* no multicast address */
+	if (addr[0] & 0x01)
+		return false;
+
+	/* no zero address */
+	if ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0)
+		return false;
+
+	return true;
+}
+
 static int resolve_mac_from_parse(struct nl_msg *msg, void *arg)
 {
 	struct nlattr *tb[NDA_MAX + 1];
@@ -616,6 +629,9 @@ static int resolve_mac_from_parse(struct nl_msg *msg, void *arg)
 	mac = nla_data(tb[NDA_LLADDR]);
 	l3addr = nla_data(tb[NDA_DST]);
 
+	if (!ether_addr_valid(mac))
+		goto err;
+
 	if (memcmp(nl_arg->l3addr, l3addr, l3_len) == 0) {
 		memcpy(nl_arg->mac_result, mac, ETH_ALEN);
 		nl_arg->found = 1;
-- 
2.17.0


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

end of thread, other threads:[~2018-04-17  8:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-13 18:16 [B.A.T.M.A.N.] [PATCH] batctl: Validate translated mac addresses Sven Eckelmann
2018-04-14  2:34 ` Antonio Quartulli
2018-04-14  7:10   ` Sven Eckelmann
2018-04-14  8:11     ` Antonio Quartulli
2018-04-14  9:20       ` Sven Eckelmann
2018-04-14  9:35         ` Antonio Quartulli
2018-04-14  9:36 ` Antonio Quartulli
2018-04-17  8:35 ` Sven Eckelmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.