Skip to content

fix(net): validate TAP MTU and make VIRTIO_NET_F_MTU optional - #553

Merged
Lencerf merged 1 commit into
google:mainfrom
Lencerf:fix/net-mtu
Nov 13, 2026
Merged

Lencerf merged 1 commit into
google:mainfrom
Lencerf:fix/net-mtu

Conversation

@Lencerf

@Lencerf Lencerf commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Net::new() unconditionally advertised VIRTIO_NET_F_MTU with TapNetSpec::mtu as config.mtu. When mtu was configured below 68, the device exposed VIRTIO_NET_F_MTU with an out-of-range 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: virtnet_validate() does not accept VIRTIO_NET_F_MTU if config.mtu is below 68.

Changes

  • Keep TapNetSpec::mtu a u16 and make it optional on the command line (0 by default).
  • When mtu is 0, set config.mtu = 0 and do not advertise NetFeature::MTU.
  • Otherwise validate mtu >= 68 (MIN_MTU) before opening the TAP device and return virtio::Error::InvalidMtu { mtu } on invalid values; advertise NetFeature::MTU when valid.
  • Add unit tests in alioth/src/virtio/dev/net/tap_test.rs (running without root or /dev/net/tun) and a CLI net parsing test without mtu in alioth-cli/src/boot/boot_test.rs.

@coveralls

coveralls commented Nov 13, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 43395750689

Coverage increased (+0.2%) to 44.348%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 7 uncovered changes across 1 file (28 of 35 lines covered, 80.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
alioth/src/virtio/dev/net/tap.rs 35 28 80.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 16578
Covered Lines: 7140
Line Coverage: 43.07%
Relevant Branches: 1788
Covered Branches: 1005
Branch Coverage: 56.21%
Branches in Coverage %: Yes
Coverage Strength: 900.24 hits per line

💛 - 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>
@Lencerf
Lencerf added this pull request to the merge queue Nov 13, 2026
Merged via the queue into google:main with commit aa739c3 Nov 13, 2026
20 checks passed
@Lencerf
Lencerf deleted the fix/net-mtu branch November 13, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants