b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>, Andre Kasper <Andre.Kasper@gmx.de>
Subject: [B.A.T.M.A.N.] [PATCH] batctl: Validate translated mac addresses
Date: Fri, 13 Apr 2018 20:16:18 +0200	[thread overview]
Message-ID: <20180413181618.24144-1-sven@narfation.org> (raw)

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


             reply	other threads:[~2018-04-13 18:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 18:16 Sven Eckelmann [this message]
2018-04-14  2:34 ` [B.A.T.M.A.N.] [PATCH] batctl: Validate translated mac addresses 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180413181618.24144-1-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=Andre.Kasper@gmx.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).