-
Notifications
You must be signed in to change notification settings - Fork 186
virtio_net: handle unexpected tx completion without panicking #2778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1305,7 +1305,29 @@ impl Worker { | |||||||||||||||||
|
|
||||||||||||||||||
| fn complete_tx_packet(&mut self, id: TxId) -> Result<(), WorkerError> { | ||||||||||||||||||
| let state = &mut self.active_state; | ||||||||||||||||||
| let tx_packet = state.pending_tx_packets[id.0 as usize].take().unwrap(); | ||||||||||||||||||
| let idx = id.0 as usize; | ||||||||||||||||||
| let pending_len = state.pending_tx_packets.len(); | ||||||||||||||||||
|
|
||||||||||||||||||
| let Some(slot) = state.pending_tx_packets.get_mut(idx) else { | ||||||||||||||||||
| tracelimit::error_ratelimited!( | ||||||||||||||||||
| tx_id = id.0, | ||||||||||||||||||
| tx_index = idx, | ||||||||||||||||||
| pending_tx_packets_len = pending_len, | ||||||||||||||||||
| "unexpected tx completion for out-of-range packet" | ||||||||||||||||||
| ); | ||||||||||||||||||
| return Ok(()); | ||||||||||||||||||
|
||||||||||||||||||
| return Ok(()); | |
| return Err(anyhow::anyhow!( | |
| "unexpected tx completion for out-of-range packet: tx_id={}, tx_index={}, pending_tx_packets_len={}", | |
| id.0, | |
| idx, | |
| pending_len | |
| ) | |
| .into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id.0 as usizecan silently truncate ifid.0is wider thanusize(or if this ever builds/runs in a 32-bit environment). Since this function is explicitly handling unexpected IDs, it would be safer to use a checked conversion (e.g.,usize::try_from(id.0)) and treat conversion failure the same as out-of-range.