Skip to content
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

Fix RawHardwareAddress panic when parsing to specific link layer address #1027

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

thvdveld
Copy link
Contributor

@thvdveld thvdveld commented Jan 3, 2025

The RawHardwareAddress::parse() method panics if the length of the address is invalid. More specific, for an Ethernet address, the length should exactly be 6 bytes, and for an IEEE 802.15.4 address, the length should exactly be 8 bytes. Previously, we only checked if the size of the input was at least the size of the link layer address. Since Ethernet::from_bytes() does a copy_from_slice, the length of the input should be exactly 6 bytes. A panic can be triggered when the length is for example 7 bytes, while the medium-ethernet and medium-ieee802154 features are enabled. This commit fixes the panic by checking if the length of the input is exactly the size of the link layer address.

This panic was discovered by people from Radically Open Security.

The `RawHardwareAddress::parse()` method panics if the length of the
address is invalid. More specific, for an Ethernet address, the length
should exactly be 6 bytes, and for an IEEE 802.15.4 address, the length
should exactly be 8 bytes. Previously, we only checked if the size of
the input was at least the size of the link layer address. Since
`Ethernet::from_bytes()` does a copy_from_slice, the length of the input
should be exactly 6 bytes. A panic can be triggered when the length is
for example 7 bytes, while the `medium-ethernet` and `medium-ieee802154`
features are enabled. This commit fixes the panic by checking if the
length of the input is exactly the size of the link layer address.

This panic was discovered by people from Radically Open Security.

Signed-off-by: Thibaut Vandervelden <[email protected]>
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.89%. Comparing base (104898b) to head (31fda8f).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1027   +/-   ##
=======================================
  Coverage   80.88%   80.89%           
=======================================
  Files          81       81           
  Lines       28447    28448    +1     
=======================================
+ Hits        23010    23012    +2     
+ Misses       5437     5436    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@whitequark whitequark left a comment

Choose a reason for hiding this comment

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

Good catch!

@Dirbaio Dirbaio added this pull request to the merge queue Jan 3, 2025
Merged via the queue into smoltcp-rs:main with commit 3a30d0c Jan 3, 2025
15 checks passed
@thvdveld thvdveld deleted the fix-lladdr-parse-panic branch January 3, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants