From 216dcef0df73be65b8df15124fe87c388e390440 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Imre=20Vad=C3=A1sz?= Date: Mon, 11 Sep 2017 00:21:24 +0200 Subject: [PATCH] if_vtnet - Fix potential vtnet_set_hwaddr call before virtqueues are set up. * When VIRTIO_NET_F_MAC isn't negotiated (i.e. the host doesn't give us a macaddress), we generate a random mac address. The vtnet_set_hwaddr() call to set this mac address, would have tried to use the control virtqueue too early, where it isn't yet allocated. * To fix this case, do the vtnet_set_hwaddr() call for this a bit later, after the virtqueues have been set up. (We are already disabling promiscuous mode there, so we know the controlq is working there) --- sys/dev/virtual/virtio/net/if_vtnet.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/dev/virtual/virtio/net/if_vtnet.c b/sys/dev/virtual/virtio/net/if_vtnet.c index 1e942aad29..8abd92db7c 100644 --- a/sys/dev/virtual/virtio/net/if_vtnet.c +++ b/sys/dev/virtual/virtio/net/if_vtnet.c @@ -322,6 +322,12 @@ vtnet_attach(device_t dev) goto fail; } + if ((sc->vtnet_flags & VTNET_FLAG_MAC) == 0) { + lwkt_serialize_enter(&sc->vtnet_slz); + vtnet_set_hwaddr(sc); + lwkt_serialize_exit(&sc->vtnet_slz); + } + /* * Device defaults to promiscuous mode for backwards * compatibility. Turn it off if possible. @@ -700,7 +706,6 @@ vtnet_get_hwaddr(struct vtnet_softc *sc) */ sc->vtnet_hwaddr[0] = 0xB2; karc4rand(&sc->vtnet_hwaddr[1], ETHER_ADDR_LEN - 1); - vtnet_set_hwaddr(sc); return; } -- 2.41.0