if_vtnet: Disable F_MTU feature if MTU is invalid

Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27931
This commit is contained in:
Bryan Venteicher 2021-01-19 04:55:25 +00:00
parent bd8809df20
commit c3187190c7
2 changed files with 15 additions and 0 deletions

View File

@ -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;

View File

@ -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