All of lore.kernel.org
 help / color / mirror / Atom feed
* [kernel-hardening] Patch for random mac address
@ 2017-05-24 20:44 HacKurx
  2017-05-24 22:40 ` Casey Schaufler
  2017-05-25  7:31 ` intrigeri
  0 siblings, 2 replies; 18+ messages in thread
From: HacKurx @ 2017-05-24 20:44 UTC (permalink / raw)
  To: kernel-hardening, keescook

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

Hi all,

Firstly, I am sad that no major company has taken the trouble to
finance PaX / Grsecurity so they can continue their development in a
way that is accessible to all. This is regrettable because their work
is your main source of inspiration ...

In what brings me here. Brad had released an interesting hack for privacy:
https://www.grsecurity.net/~spender/random_mac.diff

I updated this patch and added a menu option. Can you examine it for
include it upstream?
Because this would be useful for distributions like Tails, Subgraph
OS, Kali Linux and other ...

Thanks. Best regards,

HacKurx (Loic)

[-- Attachment #2: random-mac_linux-4.12-rc2.diff --]
[-- Type: text/plain, Size: 2039 bytes --]

diff --git a/net/core/dev.c b/net/core/dev.c
index fca407b..3eeb42b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6669,6 +6669,26 @@ int dev_change_flags(struct net_device *dev, unsigned int flags)
 
 	changes = (old_flags ^ dev->flags) | (old_gflags ^ dev->gflags);
 	__dev_notify_flags(dev, old_flags, changes);
+
+#ifdef CONFIG_RANDOM_MAC_ADDRESS
+	if ((changes & IFF_UP) && !(old_flags & IFF_UP)) {
+		/* randomize MAC whenever interface is brought up */
+		struct sockaddr sa;
+		unsigned int mac4;
+		unsigned short mac2;
+
+		mac4 = prandom_u32();
+		mac2 = prandom_u32();
+		memcpy(sa.sa_data, &mac4, sizeof(mac4));
+		memcpy((char *)sa.sa_data + sizeof(mac4), &mac2, sizeof(mac2));
+		if (!is_valid_ether_addr(sa.sa_data))
+			sa.sa_data[5] = 1;
+		sa.sa_data[0] &= 0xFC;
+		sa.sa_family = dev->type;
+		dev_set_mac_address(dev, &sa);
+	}
+#endif
+
 	return ret;
 }
 EXPORT_SYMBOL(dev_change_flags);
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index b94b1d2..b020d15 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -262,6 +262,10 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 
 	case SIOCSIFHWADDR:
 		return dev_set_mac_address(dev, &ifr->ifr_hwaddr);
+#ifdef CONFIG_RANDOM_MAC_ADDRESS
+		/* ignore userland MAC changes */
+		return 0;
+#endif
 
 	case SIOCSIFHWBROADCAST:
 		if (ifr->ifr_hwaddr.sa_family != dev->type)
diff --git a/security/Kconfig b/security/Kconfig
index 93027fd..6b7b6fc 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -67,6 +67,14 @@ config SECURITY_NETWORK_XFRM
 	  IPSec.
 	  If you are unsure how to answer this question, answer N.
 
+config RANDOM_MAC_ADDRESS
+	bool "Use random MAC adresses"
+	default n
+	help
+	  Say Y here for randomize the MAC addresses of network interfaces.
+	  This option is recommended for people who want to increase their privacy.
+	  If you are unsure how to answer this question, answer N.
+
 config SECURITY_PATH
 	bool "Security hooks for pathname based access control"
 	depends on SECURITY

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

end of thread, other threads:[~2017-06-10  7:00 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24 20:44 [kernel-hardening] Patch for random mac address HacKurx
2017-05-24 22:40 ` Casey Schaufler
2017-05-24 23:05   ` Lukas Odzioba
2017-05-25  7:31 ` intrigeri
2017-05-25 15:07   ` Rik van Riel
2017-05-25 15:47     ` intrigeri
2017-05-25 15:59       ` Rik van Riel
2017-05-25 17:28         ` Kees Cook
2017-05-25 21:28           ` Anisse Astier
2017-05-26  8:23             ` Daniel Micay
2017-05-26  7:55           ` HacKurx
2017-05-26 12:34             ` Anisse Astier
2017-05-26 14:41               ` HacKurx
2017-06-09 12:00               ` HacKurx
2017-06-09 13:01                 ` Anisse Astier
2017-05-25 15:48   ` Theodore Ts'o
2017-06-09 13:11     ` Matt Brown
2017-06-10  7:00       ` HacKurx

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.