From owner-dev-commits-src-branches@freebsd.org Fri Aug 20 21:36:23 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4FE55667F82; Fri, 20 Aug 2021 21:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Grw1g1fR9z3HWC; Fri, 20 Aug 2021 21:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1EE9A2026E; Fri, 20 Aug 2021 21:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17KLaNvp082375; Fri, 20 Aug 2021 21:36:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17KLaN6l082374; Fri, 20 Aug 2021 21:36:23 GMT (envelope-from git) Date: Fri, 20 Aug 2021 21:36:23 GMT Message-Id: <202108202136.17KLaN6l082374@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 0a7dbddfb0ca - stable/12 - kern: ether_gen_addr: randomize on default hostuuid, too MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 0a7dbddfb0ca789acca9858c980e58ab8f1bc6de Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Aug 2021 21:36:23 -0000 The branch stable/12 has been updated by kbowling (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=0a7dbddfb0ca789acca9858c980e58ab8f1bc6de commit 0a7dbddfb0ca789acca9858c980e58ab8f1bc6de Author: Kyle Evans AuthorDate: 2021-04-16 01:11:35 +0000 Commit: Kevin Bowling CommitDate: 2021-08-20 21:35:49 +0000 kern: ether_gen_addr: randomize on default hostuuid, too Currently, this will still hash the default (all zero) hostuuid and potentially arrive at a MAC address that has a high chance of collision if another interface of the same name appears in the same broadcast domain on another host without a hostuuid, e.g., some virtual machine setups. Instead of using the default hostuuid, just treat it as a failure and generate a random LA unicast MAC address. Reviewed by: bz, gbe, imp, kbowling, kp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D29788 (cherry picked from commit 2d741f33bd07bf94a59635db3c7b9e070a8a6e55) --- share/man/man9/ether_gen_addr.9 | 5 +++-- sys/kern/kern_jail.c | 1 - sys/net/if_ethersubr.c | 17 ++++++++++++++--- sys/sys/jail.h | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/share/man/man9/ether_gen_addr.9 b/share/man/man9/ether_gen_addr.9 index 1b98a841736d..f69cb199e2c3 100644 --- a/share/man/man9/ether_gen_addr.9 +++ b/share/man/man9/ether_gen_addr.9 @@ -61,8 +61,9 @@ or on machines that do not use .Xr loader 8 . .Pp .Nm -can fail to derive a MAC address due to memory allocation failure. -In this case, a locally-administered unicast MAC address will be randomly +can fail to derive a MAC address due to memory allocation failure, or because +the hostid has not been populated. +In these cases, a locally-administered unicast MAC address will be randomly generated and returned via the .Ar hwaddr parameter. diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 46b43fa7bbc2..e95a0c60bd1e 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -76,7 +76,6 @@ __FBSDID("$FreeBSD$"); #include -#define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" #define PRISON0_HOSTUUID_MODULE "hostuuid" MALLOC_DEFINE(M_PRISON, "prison", "Prison structures"); diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 5e255f862221..ddc92535be60 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1396,6 +1396,11 @@ ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) char jailname[MAXHOSTNAMELEN]; getcredhostuuid(curthread->td_ucred, uuid, sizeof(uuid)); + if (strncmp(uuid, DEFAULT_HOSTUUID, sizeof(uuid)) == 0) { + /* Fall back to a random mac address. */ + goto rando; + } + /* If each (vnet) jail would also have a unique hostuuid this would not * be necessary. */ getjailname(curthread->td_ucred, jailname, sizeof(jailname)); @@ -1403,9 +1408,7 @@ ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) jailname); if (sz < 0) { /* Fall back to a random mac address. */ - arc4rand(hwaddr, sizeof(*hwaddr), 0); - hwaddr->octet[0] = 0x02; - return; + goto rando; } SHA1Init(&ctx); @@ -1420,6 +1423,14 @@ ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) hwaddr->octet[i] = addr >> ((ETHER_ADDR_LEN - i - 1) * 8) & 0xFF; } + + return; +rando: + arc4rand(hwaddr, sizeof(*hwaddr), 0); + /* Unicast */ + hwaddr->octet[0] &= 0xFE; + /* Locally administered. */ + hwaddr->octet[0] |= 0x02; } DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY); diff --git a/sys/sys/jail.h b/sys/sys/jail.h index 590fb4488262..66ffa60e67ef 100644 --- a/sys/sys/jail.h +++ b/sys/sys/jail.h @@ -138,6 +138,7 @@ MALLOC_DECLARE(M_PRISON); #include #define HOSTUUIDLEN 64 +#define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" #define OSRELEASELEN 32 struct racct;