m/n/c/n/dhcp4c: verify hardware address sanity
Complain early if an empty or all-zero hardware address is passed in, as
this is never valid.
Change-Id: I3abfcd618aaa8018e88267d414d7a34a859f3ce2
Reviewed-on: https://review.monogon.dev/c/monogon/+/3113
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/core/network/dhcp4c/dhcpc.go b/metropolis/node/core/network/dhcp4c/dhcpc.go
index 5159cc5..76347e8 100644
--- a/metropolis/node/core/network/dhcp4c/dhcpc.go
+++ b/metropolis/node/core/network/dhcp4c/dhcpc.go
@@ -235,6 +235,20 @@
// Increase maximum interval to reduce chatter when the server is down
renewBackoff.MaxInterval = 5 * time.Minute
+ // Check if the hardware address contains at least one non-zero value.
+ // This exists to catch undefined/non-supplied hardware address values,
+ // it does not check for L2 protocol-specific hardware address constraints.
+ hasValidHWAddr := false
+ for _, b := range iface.HardwareAddr {
+ if b != 0x00 {
+ hasValidHWAddr = true
+ break
+ }
+ }
+ if !hasValidHWAddr {
+ return nil, fmt.Errorf("iface HardwareAddr is invalid (only zeroes or invalid length): %x", iface.HardwareAddr)
+ }
+
return &Client{
state: stateDiscovering,
broadcastConn: broadcastConn,