Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Jun 2021 09:53:03 +0200 (CEST)
From:      Ronald Klop <ronald-lists@klop.ws>
To:        Kyle Evans <kevans@FreeBSD.org>
Cc:        dev-commits-src-all@FreeBSD.org, src-committers@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   Re: git: 2d741f33bd07 - main - kern: ether_gen_addr: randomize on default hostuuid, too
Message-ID:  <2123581522.4.1622620383310@localhost>
In-Reply-To: <202106020359.1523xbk3040971@gitrepo.freebsd.org>
References:  <202106020359.1523xbk3040971@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

Wouldn't it be user friendly to tell why the MAC is random? Something like this.

 if (strncmp(uuid, DEFAULT_HOSTUUID, sizeof(uuid)) == 0) {
      printf("No /etc/hostuuid found. Fall back to a random mac address.");
      goto rando;
 }

I know it would save me a lot of time if I would encounter this case.
Plus the message is only printed once on boot.

Regards,
Ronald.

 
Van: Kyle Evans <kevans@FreeBSD.org>
Datum: woensdag, 2 juni 2021 05:59
Aan: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Onderwerp: git: 2d741f33bd07 - main - kern: ether_gen_addr: randomize on default hostuuid, too
> 
> The branch main has been updated by kevans:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=2d741f33bd07bf94a59635db3c7b9e070a8a6e55
> 
> commit 2d741f33bd07bf94a59635db3c7b9e070a8a6e55
> Author:     Kyle Evans <kevans@FreeBSD.org>
> AuthorDate: 2021-04-16 01:11:35 +0000
> Commit:     Kyle Evans <kevans@FreeBSD.org>
> CommitDate: 2021-06-02 03:59:21 +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
> ---
>  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 303e31490eb1..9784f3bfc23b 100644
> --- a/sys/kern/kern_jail.c
> +++ b/sys/kern/kern_jail.c
> @@ -76,7 +76,6 @@ __FBSDID("$FreeBSD$");
>  
>  #include <security/mac/mac_framework.h>
>  
> -#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 01c2d2f7b3e8..7eb46df8281a 100644
> --- a/sys/net/if_ethersubr.c
> +++ b/sys/net/if_ethersubr.c
> @@ -1443,6 +1443,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));
> @@ -1450,9 +1455,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);
> @@ -1467,6 +1470,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 c9d4c65e4d9e..76ed377e3f06 100644
> --- a/sys/sys/jail.h
> +++ b/sys/sys/jail.h
> @@ -140,6 +140,7 @@ MALLOC_DECLARE(M_PRISON);
>  #include <sys/osd.h>
>  
>  #define    HOSTUUIDLEN 64
> +#define    DEFAULT_HOSTUUID    "00000000-0000-0000-0000-000000000000"
>  #define    OSRELEASELEN    32
>  
>  struct racct;
> _______________________________________________
> dev-commits-src-all@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
> To unsubscribe, send any mail to "dev-commits-src-all-unsubscribe@freebsd.org"
> 
> 
> 
From owner-dev-commits-src-all@freebsd.org  Wed Jun  2 08:05:04 2021
Return-Path: <owner-dev-commits-src-all@freebsd.org>
Delivered-To: dev-commits-src-all@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 75D7A63D66C;
 Wed,  2 Jun 2021 08:05:04 +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 4Fw1m01z7Fz4YLc;
 Wed,  2 Jun 2021 08:05:04 +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 212E8137A1;
 Wed,  2 Jun 2021 08:05:04 +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 152854Cq072931;
 Wed, 2 Jun 2021 08:05:04 GMT (envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
 by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 152854kD072930;
 Wed, 2 Jun 2021 08:05:04 GMT (envelope-from git)
Date: Wed, 2 Jun 2021 08:05:04 GMT
Message-Id: <202106020805.152854kD072930@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
 dev-commits-src-main@FreeBSD.org
From: Marcin Wojtas <mw@FreeBSD.org>
Subject: git: 9cf66a0458f4 - main - uart_dev_ns8250: Switch ACPI UART subtype
 for Marvell SoCs
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: mw
X-Git-Repository: src
X-Git-Refname: refs/heads/main
X-Git-Reftype: branch
X-Git-Commit: 9cf66a0458f4913d34cb3c5f6b653c78f70de8a8
Auto-Submitted: auto-generated
X-BeenThere: dev-commits-src-all@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Commit messages for all branches of the src repository
 <dev-commits-src-all.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-all>, 
 <mailto:dev-commits-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-all/>;
List-Post: <mailto:dev-commits-src-all@freebsd.org>
List-Help: <mailto:dev-commits-src-all-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all>, 
 <mailto:dev-commits-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 02 Jun 2021 08:05:04 -0000

The branch main has been updated by mw:

URL: https://cgit.FreeBSD.org/src/commit/?id=9cf66a0458f4913d34cb3c5f6b653c78f70de8a8

commit 9cf66a0458f4913d34cb3c5f6b653c78f70de8a8
Author:     Marcin Wojtas <mw@FreeBSD.org>
AuthorDate: 2021-05-20 21:37:02 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2021-06-02 07:55:19 +0000

    uart_dev_ns8250: Switch ACPI UART subtype for Marvell SoCs
    
    DBG2 ACPI table description [1] specifies three subtypes
    related to 16550 UART:
    0x0 - 16550 compatible
    0x1 - 16550 subset
    0x12 - 16550 compatible with parameters defined in Generic Address Structure (GAS)
    
    It turned out however, that the Windows OS treats 0x0 subtype as
    legacy x86 UART with 8-bit access. ARM SoCs can use types 0x1 (16550 with
    fixed mmio32 access) or 0x12 (16550 with fully respected GAS contents).
    
    Switch Marvell SoCs ACPI UART subtype to 0x1 - thanks to that the same firmware
    can run properly with UART output in FreeBSD, Windows 10, Linux and ESXI
    hypervisor. Tests showed the older firmware versions that use 0x0
    UART subtype in SPCR table continue to display output properly.
    
    [1] https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table
    
    Obtained from: Semihalf
    Sponsored by: ARM
    Differential revision: https://reviews.freebsd.org/D30386
    MFC after: 2 weeks
---
 sys/dev/uart/uart_dev_ns8250.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/uart/uart_dev_ns8250.c b/sys/dev/uart/uart_dev_ns8250.c
index 45b4d315c3d5..859fb352a194 100644
--- a/sys/dev/uart/uart_dev_ns8250.c
+++ b/sys/dev/uart/uart_dev_ns8250.c
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/uart/uart_ppstypes.h>
 #ifdef DEV_ACPI
 #include <dev/uart/uart_cpu_acpi.h>
+#include <contrib/dev/acpica/include/acpi.h>
 #endif
 
 #include <dev/ic/ns16550.h>
@@ -415,7 +416,7 @@ struct uart_class uart_ns8250_class = {
 static struct acpi_uart_compat_data acpi_compat_data[] = {
 	{"AMD0020",	&uart_ns8250_class, 0, 2, 0, 48000000, UART_F_BUSY_DETECT, "AMD / Synopsys Designware UART"},
 	{"AMDI0020", &uart_ns8250_class, 0, 2, 0, 48000000, UART_F_BUSY_DETECT, "AMD / Synopsys Designware UART"},
-	{"MRVL0001", &uart_ns8250_class, 0, 2, 0, 200000000, UART_F_BUSY_DETECT, "Marvell / Synopsys Designware UART"},
+	{"MRVL0001", &uart_ns8250_class, ACPI_DBG2_16550_SUBSET, 2, 0, 200000000, UART_F_BUSY_DETECT, "Marvell / Synopsys Designware UART"},
 	{"SCX0006",  &uart_ns8250_class, 0, 2, 0, 62500000, UART_F_BUSY_DETECT, "SynQuacer / Synopsys Designware UART"},
 	{"HISI0031", &uart_ns8250_class, 0, 2, 0, 200000000, UART_F_BUSY_DETECT, "HiSilicon / Synopsys Designware UART"},
 	{"PNP0500", &uart_ns8250_class, 0, 0, 0, 0, 0, "Standard PC COM port"},



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2123581522.4.1622620383310>