All of lore.kernel.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address
@ 2016-04-01 17:22 Sven Eckelmann
  2016-04-01 17:22 ` [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket Sven Eckelmann
  2016-04-04 15:47 ` [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Simon Wunderlich
  0 siblings, 2 replies; 4+ messages in thread
From: Sven Eckelmann @ 2016-04-01 17:22 UTC (permalink / raw)
  To: b.a.t.m.a.n

The ipv6_to_mac function currently only checks if the EUI64 markers are
present but not if the mac address is valid for a host. This has to be done
to avoid invalid data in the alfred data storage.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 alfred.h       |  2 ++
 batadv_query.c |  4 ++++
 util.c         | 15 +++++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/alfred.h b/alfred.h
index 7e5db16..8ed1ef0 100644
--- a/alfred.h
+++ b/alfred.h
@@ -26,6 +26,7 @@
 #include <net/ethernet.h>
 #include <netinet/in.h>
 #include <netinet/udp.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <time.h>
 #include <sys/select.h>
@@ -196,3 +197,4 @@ int time_diff(struct timespec *tv1, struct timespec *tv2,
 	      struct timespec *tvdiff);
 void time_random_seed(void);
 uint16_t get_random_id(void);
+bool is_valid_ether_addr(uint8_t *addr);
diff --git a/batadv_query.c b/batadv_query.c
index 2604503..6dc2cf4 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -19,6 +19,7 @@
  *
  */
 
+#include "alfred.h"
 #include "batadv_query.h"
 #include <errno.h>
 #include <net/ethernet.h>
@@ -85,6 +86,9 @@ int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac)
 	mac->ether_addr_octet[4] = addr->s6_addr[14];
 	mac->ether_addr_octet[5] = addr->s6_addr[15];
 
+	if (!is_valid_ether_addr(mac->ether_addr_octet))
+		return -EINVAL;
+
 	return 0;
 }
 
diff --git a/util.c b/util.c
index db6ec96..c7e11cc 100644
--- a/util.c
+++ b/util.c
@@ -19,6 +19,8 @@
  *
  */
 
+#include <netinet/ether.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -60,3 +62,16 @@ uint16_t get_random_id(void)
 {
 	return random();
 }
+
+bool is_valid_ether_addr(uint8_t addr[ETH_ALEN])
+{
+	/* multicast address */
+	if (addr[0] & 0x01)
+		return false;
+
+	/* 00:00:00:00:00:00 */
+	if ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) == 0)
+		return false;
+
+	return true;
+}
-- 
2.8.0.rc3


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

* [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket
  2016-04-01 17:22 [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Sven Eckelmann
@ 2016-04-01 17:22 ` Sven Eckelmann
  2016-04-04 15:48   ` Simon Wunderlich
  2016-04-04 15:47 ` [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Simon Wunderlich
  1 sibling, 1 reply; 4+ messages in thread
From: Sven Eckelmann @ 2016-04-01 17:22 UTC (permalink / raw)
  To: b.a.t.m.a.n

Not only 00:00:00:00:00:00 but also multicast addresses are invalid as data
source for alfred. These have to be checked too before accepting the mac
address received from the client over the unix socket.

Fixes: 58e109973bbe ("alfred: Allow setting the source mac via unix sock")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 unix_sock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/unix_sock.c b/unix_sock.c
index a0ccc13..ee6dd8f 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -97,7 +97,6 @@ static int unix_sock_add_data(struct globals *globals,
 			      struct alfred_push_data_v0 *push,
 			      int client_sock)
 {
-	static const char zero[ETH_ALEN] = { 0 };
 	struct alfred_data *data;
 	struct dataset *dataset;
 	int len, data_len, ret = -1;
@@ -124,7 +123,7 @@ static int unix_sock_add_data(struct globals *globals,
 	/* clients should set the source mac to 00:00:00:00:00:00
 	 * to make the server set the source for them
 	 */
-	if (memcmp(zero, data->source, sizeof(data->source)) == 0)
+	if (!is_valid_ether_addr(data->source))
 		memcpy(data->source, &interface->hwaddr,
 		       sizeof(interface->hwaddr));
 
-- 
2.8.0.rc3


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

* Re: [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address
  2016-04-01 17:22 [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Sven Eckelmann
  2016-04-01 17:22 ` [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket Sven Eckelmann
@ 2016-04-04 15:47 ` Simon Wunderlich
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Wunderlich @ 2016-04-04 15:47 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

On Friday 01 April 2016 19:22:35 Sven Eckelmann wrote:
> The ipv6_to_mac function currently only checks if the EUI64 markers are
> present but not if the mac address is valid for a host. This has to be done
> to avoid invalid data in the alfred data storage.
> 
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
>  alfred.h       |  2 ++
>  batadv_query.c |  4 ++++
>  util.c         | 15 +++++++++++++++
>  3 files changed, 21 insertions(+)

Applied in revision 46b8926.

Thanks!
     Simon

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket
  2016-04-01 17:22 ` [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket Sven Eckelmann
@ 2016-04-04 15:48   ` Simon Wunderlich
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Wunderlich @ 2016-04-04 15:48 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 447 bytes --]

On Friday 01 April 2016 19:22:36 Sven Eckelmann wrote:
> Not only 00:00:00:00:00:00 but also multicast addresses are invalid as data
> source for alfred. These have to be checked too before accepting the mac
> address received from the client over the unix socket.
> 
> Fixes: 58e109973bbe ("alfred: Allow setting the source mac via unix sock")
> Signed-off-by: Sven Eckelmann <sven@narfation.org>

Applied in revision 25b4ae6.

Thanks!
     Simon

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2016-04-04 15:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-01 17:22 [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Sven Eckelmann
2016-04-01 17:22 ` [B.A.T.M.A.N.] [PATCH 2/2] alfred: Only accept valid mac addresses via unix socket Sven Eckelmann
2016-04-04 15:48   ` Simon Wunderlich
2016-04-04 15:47 ` [B.A.T.M.A.N.] [PATCH 1/2] alfred: Check for invalid mac in EUI64 address Simon Wunderlich

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.