git: 9front

Download patch

ref: 2a3268c1e3442909ef047ce0c44b2211620283d0
parent: c6f05d0f9d1cec898bce36caa693413759c6d4de
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Aug 4 10:43:01 EDT 2025

vmx: whine when we have an invalid mac address

it's annoying if we accept the address for the interface and then guests refuse
to handle it, so let's reject it early.

--- a/sys/src/cmd/vmx/virtio.c
+++ b/sys/src/cmd/vmx/virtio.c
@@ -688,9 +688,22 @@
 	mkvioqueue(d, 1024, viowakeup);
 	mkvioqueue(d, 1024, viowakeup);
 	mkvioqueue(d, 32, vionetcmd);
-	if(ea == nil || parseether(d->net.mac, ea)){
+	if(ea == nil){
 		genrandom(d->net.mac, 6);
 		d->net.mac[0] = d->net.mac[0] & ~1 | 2;
+	}else{
+		if(parseether(d->net.mac, ea) != 0){
+			fprint(2, "unparsable mac addr: %s\n", ea);
+			return -1;
+		}
+		if((d->net.mac[0] & 1) != 0){
+			werrstr("invalid mac addr: must be unicast", d->net.mac[0]);
+			return -1;
+		}
+		if((d->net.mac[0] & 2) == 0){
+			fprint(2, "invalid mac addr: must not be local", d->net.mac[0]);
+			return -1;
+		}
 	}
 	d->net.flags = flags;
 	d->devfeat = 1<<5|1<<16|1<<17|1<<18|1<<20;
--