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

Fixed a critical bug, allowing to crash the whole system with a specially crafted LoRa frame #15355

Merged
merged 2 commits into from
Nov 2, 2020

Conversation

a-podshivalov
Copy link
Contributor

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

@benpicco benpicco added Area: network Area: Networking Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Oct 30, 2020
Copy link
Contributor

@benpicco benpicco left a 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 :)

@benpicco benpicco requested a review from bergzand October 30, 2020 21:12
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 30, 2020
@benpicco benpicco requested a review from fjmolinas October 30, 2020 21:45
Comment on lines 545 to 550
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 */
Copy link
Contributor

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

Suggested change
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.

@a-podshivalov
Copy link
Contributor Author

Seems that the same problem is mentioned in issue #14962.

@benpicco benpicco linked an issue Oct 31, 2020 that may be closed by this pull request
@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 31, 2020
@benpicco benpicco merged commit 2198598 into RIOT-OS:master Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LoRaWan node ISR stack overflowed
2 participants