Skip to content

netvsp: fix untrusted guest input errors#3183

Open
erfrimod wants to merge 4 commits intomicrosoft:mainfrom
erfrimod:erfrimod/netvsp-arithmetic-safety
Open

netvsp: fix untrusted guest input errors#3183
erfrimod wants to merge 4 commits intomicrosoft:mainfrom
erfrimod:erfrimod/netvsp-arithmetic-safety

Conversation

@erfrimod
Copy link
Copy Markdown
Contributor

@erfrimod erfrimod commented Apr 2, 2026

Fuzz testing found several places where netvsp and vmbus channel could panic on edge-case inputs: untrusted guest data, malformed save state, function calls with out-of-range channel indices. Adding defensive validation to turn those panics into Errors.

  • Added checks for invalid GuestBuffer allocations
  • RxBufferRanges added checks prevent underflow and division by zero from failing restart_queues
  • Correcting logic in max_subchannels
  • OID RSS set parameters checks for divide by zero indirection table size

Copilot AI review requested due to automatic review settings April 2, 2026 22:56
@erfrimod erfrimod requested a review from a team as a code owner April 2, 2026 22:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the netvsp VMBus NIC implementation against malformed/untrusted guest inputs (including fuzz-discovered edge cases) by replacing panic paths with explicit validation and structured errors, plus adding regression tests.

Changes:

  • Add defensive validation for RX buffer partitioning (RxBufferRanges) to prevent divide-by-zero/underflow and propagate typed errors.
  • Replace GuestBuffers::new panic/unwrap paths with GuestBuffersError and plumb that error into the worker error surface.
  • Fix max_subchannels() to correctly exclude the primary channel and add a test for rejecting RSS params with indirection_table_size == 0.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
vm/devices/net/netvsp/src/test.rs Adds regression tests covering RSS invalid input and RX buffer configuration validation.
vm/devices/net/netvsp/src/lib.rs Adds RX buffer config validation + error wiring, fixes max_subchannels logic, and rejects RSS indirection table size of 0.
vm/devices/net/netvsp/src/buffers.rs Introduces GuestBuffersError and converts prior assert/unwrap failure modes into recoverable errors with tests.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 2, 2026 23:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

mtu,
});
}
if gpadl.first().is_none() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the gpadl empty check come before the other checks, since we have no need to do any math here? Which condition is more likely to hit, or there's not one?

#[error("GPADL has no ranges")]
EmptyGpadl,
#[error("guest memory error")]
Memory(#[source] GuestMemoryError),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really a lock error, not generic memory?

if !active_queues.is_empty() {
active_queues.len() as u16
} else {
tracelimit::warn_ratelimited!("Invalid RSS indirection table");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need any more information with this breadcrumb?

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.

3 participants