Repository navigation
fix(net): validate TAP MTU and make VIRTIO_NET_F_MTU optional - #553
Merged
Merged
Conversation
Coverage Report for CI Build 43395750689Coverage increased (+0.2%) to 44.348%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
Net::new() unconditionally offered VIRTIO_NET_F_MTU with
TapNetSpec::mtu as config.mtu. When mtu was set below 68, the device
advertised VIRTIO_NET_F_MTU with an invalid config.mtu, violating
VirtIO 1.4 Sec 5.1.4.1 ("The device MUST set mtu to between 68 and
65535 inclusive, if it offers VIRTIO_NET_F_MTU"). Linux tolerates it
by not accepting VIRTIO_NET_F_MTU if config.mtu is below 68.
Make TapNetSpec::mtu optional on the command line, defaulting to 0.
When it is 0, set config.mtu to 0 and omit NetFeature::MTU from the
device features. Otherwise validate mtu >= 68 before opening the TAP
device and return Error::InvalidMtu if it is smaller.
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Net::new()unconditionally advertisedVIRTIO_NET_F_MTUwithTapNetSpec::mtuasconfig.mtu. Whenmtuwas configured below68, the device exposedVIRTIO_NET_F_MTUwith an out-of-rangeconfig.mtu, violating VirtIO 1.4 Sec 5.1.4.1 ("The device MUST setmtuto between 68 and 65535 inclusive, if it offersVIRTIO_NET_F_MTU"). Linux tolerates it:virtnet_validate()does not acceptVIRTIO_NET_F_MTUifconfig.mtuis below 68.Changes
TapNetSpec::mtuau16and make it optional on the command line (0by default).mtuis0, setconfig.mtu = 0and do not advertiseNetFeature::MTU.mtu >= 68(MIN_MTU) before opening the TAP device and returnvirtio::Error::InvalidMtu { mtu }on invalid values; advertiseNetFeature::MTUwhen valid.alioth/src/virtio/dev/net/tap_test.rs(running without root or/dev/net/tun) and a CLI net parsing test withoutmtuinalioth-cli/src/boot/boot_test.rs.