-
Notifications
You must be signed in to change notification settings - Fork 30
SPDM - enhance the payload size check upon receiving #616
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
SPDM - enhance the payload size check upon receiving #616
Conversation
70b4040 to
227199c
Compare
src/migtd/src/spdm/mod.rs
Outdated
| return Err(0_usize); | ||
| } | ||
|
|
||
| let mut buffer = buffer.lock(); |
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.
Please don't lock() twice.
The above check should be put below the lock().
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.
Updated. sorry for such incautious problem.
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.
Pull Request Overview
This PR enhances payload size validation in the SPDM receive function to prevent buffer overflow and integer overflow vulnerabilities. The changes add an early buffer size check and refactor the payload size comparison to avoid potential integer underflow.
- Added early validation to ensure the buffer can accommodate the SPDM message header
- Refactored payload size comparison to prevent integer underflow when buffer length is smaller than header size
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/migtd/src/spdm/mod.rs
Outdated
| let payload_size = vmcall_msg_header.length as usize; | ||
|
|
||
| if buffer.len() < payload_size + VMCALL_SPDM_MESSAGE_HEADER_SIZE { | ||
| if payload_size > buffer.len() - VMCALL_SPDM_MESSAGE_HEADER_SIZE { |
Copilot
AI
Nov 21, 2025
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.
This check can still underflow if buffer.len() is less than VMCALL_SPDM_MESSAGE_HEADER_SIZE. While the early check at line 65 prevents this for the initial buffer lock, the buffer reference at line 69 is a new mutable lock that could potentially have a different length. Consider using checked_sub() or restructuring to use the result from the early check: if payload_size > buffer.len().saturating_sub(VMCALL_SPDM_MESSAGE_HEADER_SIZE)
| if payload_size > buffer.len() - VMCALL_SPDM_MESSAGE_HEADER_SIZE { | |
| if payload_size > buffer.len().saturating_sub(VMCALL_SPDM_MESSAGE_HEADER_SIZE) { |
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.
updated.
Enhance the payload size check in SPDM receive function to prevent buffer overflow and interger overflow.
227199c to
dc533b0
Compare
Enhance the payload size check in SPDM receive function to prevent
buffer overflow and interger overflow.
Fix problem 2 of issue #603