-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fixed a critical bug, allowing to crash the whole system with a specially crafted LoRa frame #15355
Conversation
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.
Thank you for the fix!
Looks good, just one thing:
Please change the commit message to somthing like
pkg/semtech-loramac: check return value of recv() in NETDEV_EVENT_RX_COMPLETE
so the commit history stays neat and CI is happy :)
eb27039
to
4d5812e
Compare
if (len > 0) { | ||
dev->driver->recv(dev, radio_payload, len, &packet_info); | ||
semtech_loramac_radio_events.RxDone(radio_payload, | ||
len, packet_info.rssi, | ||
packet_info.snr); | ||
} /* len could be -EBADMSG, in which case a CRC error message will be received shortly */ |
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.
Ok so CI says we can now reduce the scope of radio_payload
as it's only used within the branch.
However, to avoid excessive nesting we might as well do
if (len > 0) { | |
dev->driver->recv(dev, radio_payload, len, &packet_info); | |
semtech_loramac_radio_events.RxDone(radio_payload, | |
len, packet_info.rssi, | |
packet_info.snr); | |
} /* len could be -EBADMSG, in which case a CRC error message will be received shortly */ | |
/* len could be -EBADMSG, in which case a CRC error message will be received shortly */ | |
if (len < 0) { | |
break; | |
} | |
dev->driver->recv(dev, radio_payload, len, &packet_info); | |
semtech_loramac_radio_events.RxDone(radio_payload, | |
len, packet_info.rssi, | |
packet_info.snr); |
that should make CI happy as well.
Seems that the same problem is mentioned in issue #14962. |
Contribution description
As sometimes SX127x driver can return a -EBADMSG from recv(), it is necessary to check the returned value. Currently len is size_t, which expands to unsigned int at least on ARM Cortex-based platforms, causing the -EBADMSG to be interpreted as an (insanely) large value. The subsequent call to recv() overwrites all the memory available, causing a HardFault.
Testing procedure
Whenever LoRaMAC is ready to receive, send a frame with corrupt CRC. The version without a fix will crash.
Issues/PRs references