contiki-ng / contiki-ng

Contiki-NG: The OS for Next Generation IoT Devices
https://www.contiki-ng.org/
BSD 3-Clause "New" or "Revised" License
1.3k stars 698 forks source link

Out of bounds read in coap message parser #1312

Closed mjurczak closed 3 years ago

mjurczak commented 4 years ago

Description of defect

References:

https://github.com/contiki-ng/contiki-ng/tree/release/v4.5

File:

coap.c

Analysis:

Memory access beyond the input packet buffer may occur in several places in coap_parse_message() function due to insufficient boundary checks before read access is made. The content of packet beyond the parsed packet is processed as if it was part of the incoming message.

Minimal pakcet length is not validated priot to mandatory header parsing: https://github.com/contiki-ng/contiki-ng/blob/831b86ac5e79e6b0aaa3f23476581daad6bc7b72/os/net/app-layer/coap/coap.c#L417-L433

Token is read without prior validation if the entire memory is within packet buffer: https://github.com/contiki-ng/contiki-ng/blob/831b86ac5e79e6b0aaa3f23476581daad6bc7b72/os/net/app-layer/coap/coap.c#L447

Option delta and option length bytes are accessed via incremented pointer without verification if the pointer is withing packet buffer: https://github.com/contiki-ng/contiki-ng/blob/831b86ac5e79e6b0aaa3f23476581daad6bc7b72/os/net/app-layer/coap/coap.c#L482-L502

Type:

Result:

Target(s) affected by this defect ?

Patch proposal: https://github.com/contiki-ng/contiki-ng/compare/develop...mjurczak:bugfix/coap_read_out_of_bounds

mjurczak commented 4 years ago

https://github.com/contiki-ng/contiki-ng/pull/1313