Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jan 2021 05:08:28 GMT
From:      Bryan Venteicher <bryanv@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: c3187190c71f - main - if_vtnet: Disable F_MTU feature if MTU is invalid
Message-ID:  <202101190508.10J58SOK086077@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by bryanv:

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

commit c3187190c71f6850a8d8a058d78a671a45e2871c
Author:     Bryan Venteicher <bryanv@FreeBSD.org>
AuthorDate: 2021-01-19 04:55:25 +0000
Commit:     Bryan Venteicher <bryanv@FreeBSD.org>
CommitDate: 2021-01-19 04:55:25 +0000

    if_vtnet: Disable F_MTU feature if MTU is invalid
    
    Reviewed by: grehan (mentor)
    Differential Revision: https://reviews.freebsd.org/D27931
---
 sys/dev/virtio/network/if_vtnet.c    | 14 ++++++++++++++
 sys/dev/virtio/network/if_vtnetvar.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index a9dc3fad96a5..e3a42413d5cd 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -657,6 +657,20 @@ vtnet_negotiate_features(struct vtnet_softc *sc)
 
 	negotiated_features = virtio_negotiate_features(dev, features);
 
+	if (virtio_with_feature(dev, VIRTIO_NET_F_MTU)) {
+		uint16_t mtu;
+
+		mtu = virtio_read_dev_config_2(dev,
+		    offsetof(struct virtio_net_config, mtu));
+		if (mtu < VTNET_MIN_MTU /* || mtu > VTNET_MAX_MTU */) {
+			device_printf(dev, "Invalid MTU value: %d. "
+			    "MTU feature disabled.\n", mtu);
+			features &= ~VIRTIO_NET_F_MTU;
+			negotiated_features =
+			    virtio_negotiate_features(dev, features);
+		}
+	}
+
 	if (virtio_with_feature(dev, VIRTIO_NET_F_MQ)) {
 		uint16_t npairs;
 
diff --git a/sys/dev/virtio/network/if_vtnetvar.h b/sys/dev/virtio/network/if_vtnetvar.h
index 96cd68abba82..7781e1c9b398 100644
--- a/sys/dev/virtio/network/if_vtnetvar.h
+++ b/sys/dev/virtio/network/if_vtnetvar.h
@@ -340,6 +340,7 @@ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE);
 #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \
     VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN)
 
+#define VTNET_MIN_MTU		68
 #define VTNET_MAX_MTU		65536
 #define VTNET_MAX_RX_SIZE	65550
 



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