-
Notifications
You must be signed in to change notification settings - Fork 2.1k
asymcute: fix one byte out-of-bounds access in _len_get #18433
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
Conversation
As per Section 5.2.1 of the MQTT-SN specification, the MQTT-SN length header is either 1- or 3-octet long. If it is 3-octet long then the first octet is 0x01. The asymcute implementation currently only checks that the incoming packet is at least 2-octet long before attempting to parse it (MIN_PKT_LEN). However, if the first octet is 0x01 the packet must be more than 3 octet long in order to be valid. Since asymcute does not check this it reads one octet beyond the packet data for a 2-octet packet where the first octet has the value 0x01. This commit fixes this issue by adding an additional sanity check to _len_get.
621121d
to
7e6cb89
Compare
6b939d3
to
ccc8e92
Compare
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.
Looks good and change makes sense.
❗ This may cause a semantic merge conflict with #18434, once that is merged: |
Build error is unrelated. |
This will now need a rebase anyway |
ccc8e92
to
8d771b9
Compare
Rebased and made the necessary adjustments for the |
Head branch was pushed to by a user without write access
4d616c5
to
06d572c
Compare
This needs a backport to the 2022.07 branch as well. |
Contribution description
As per Section 5.2.1 of the MQTT-SN specification, the MQTT-SN length header is either 1- or 3-octet long. If it is 3-octet long then the first octet is
0x01
. The asymcute implementation currently only checks that the incoming packet is at least 2-octet long before attempting to parse it (MIN_PKT_LE
N):RIOT/sys/net/application_layer/asymcute/asymcute.c
Line 578 in 4dcb8ed
However, if the first octet is
0x01
the packet must be more than 3 octet long in order to be valid. Since asymcute does not check this it reads one octet beyond the packet data (viabyteorder_bebuftohs
which reads auint16_t
in_len_get
) for a 2-octet packet where the first octet has the value0x01
. This commit fixes this issue by adding an additional sanity check to_len_get
.Testing procedure
I think this should (hopefully) be obvious from reading the code and comparing consulting the aforementioned section in the MQTT-SN specification.
Also note that emcute has an explicit check for this:
RIOT/sys/net/application_layer/emcute/emcute.c
Lines 531 to 534 in b0f4781
Issues/PRs references
None.