CVE-2026-18416
Beschrijving NL
De CoAP link-format helper match_path_uri() in subsys/net/lib/coap/coap_link_format.c vergelijkt een geregistreerd bronpad met de URI die wordt uitgevoerd in een URI-query href= optie. Die URI is niet nul beëindigd, maar de binnenste tekenlus heeft zijn index k eenmaal per padteken geavanceerd zonder het ooit te testen tegen de optielengte len. Wanneer een geregistreerd padsegment langer is dan de meegeleverde URI en de URI er een voorvoegsel van is, leest de lus URI[len] en verder, voorbij het einde van de optiewaarde. Het pad wordt bereikt vanuit coap_well_known_core_get_len() en coap_well_known_core_get() via match_queries_resource(), d.w.z. door een niet-geverifieerd GET /.wellknown/core?href=/ -verzoek naar een apparaat dat/.wellknown/core bedient (voor het CoAP-serversubsysteem, CONFIG_COAP_SERVER_WELL_KNOWN_CORE, standaard y) en ten minste één bron heeft die struct COAP_core_metadata-attributen declareert. De overgelezen bereikt de ontvangstbuffer niet. De bekende kernbouwers ontleden de query in een stack-local struct coap_option, waarvan de waarde een vaste matrix is (waarde[12] of CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE bytes) waarin de optie-bytes worden gekopieerd, dus URI wijst naar die kopie. Lezen langs len leest daarom de ongebruikte, niet-geïnitialiseerde staart van de array en, wanneer de optie deze vult, de bytes er net voorbij in hetzelfde stackframe. (In de ZoAP-bibliotheek van v1.8.0 tot v1.9.x was de optiewaarde in plaats daarvan een aanwijzer in het ontvangen pakket en liep de overlezing voorbij de optie in de pakketbuffer.)
De impact is begrensd. Het aantal gelezen bytes voorbij het einde wordt beperkt door de lengte van het resourcepadsegment en elke extra byte wordt alleen gelezen als het toevallig gelijk is aan het volgende padteken, dus in de praktijk is de overgelezen één byte. Het kan ook geen invloed hebben op het antwoord: het retourneren van een match vereist dat de uiteindelijke vergelijkingsindex len - 1 of len is, beide binnen de grenzen, dus buiten de grenzen sturen bytes alleen de lus naar de volgende kandidaatbron. Het gevolg is ongedefinieerd gedrag, geen openbaarmaking van informatie en geen overeenkomende fout. De oplossing voegt een k >= len-bewaking toe aan de bovenkant van de binnenste lus, zodat elke URI[k] -dereferentie binnen de optiewaarde valt, terwijl een achterliggende * wildcard nog steeds kan overeenkomen met een langer pad.
Origineel (Engels) tonen
The CoAP link-format helper match_path_uri() in subsys/net/lib/coap/coap_link_format.c compares a registered resource path against the URI carried in a Uri-Query href= option. That URI is not NUL terminated, but the inner character loop advanced its index k once per path character without ever testing it against the option length len. When a registered path segment is longer than the supplied URI and the URI is a prefix of it, the loop reads uri[len] and beyond, past the end of the option value.
The path is reached from coap_well_known_core_get_len() and coap_well_known_core_get() via match_queries_resource(), i.e. by any unauthenticated GET /.well-known/core?href=/ request to a device that serves /.well-known/core (for the CoAP server subsystem, CONFIG_COAP_SERVER_WELL_KNOWN_CORE, default y) and has at least one resource that declares struct coap_core_metadata attributes.
The over-read does not reach the receive buffer. The well-known-core builders parse the query into a stack-local struct coap_option, whose value is a fixed array (value[12], or CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE bytes) that the option bytes are copied into, so uri points into that copy. Reading past len therefore reads the unused, uninitialized tail of the array and, when the option fills it, the bytes just past it in the same stack frame. (In the ZoAP library of v1.8.0 to v1.9.x the option value was instead a pointer into the received packet, and the over-read ran past the option inside the packet buffer.)
The impact is bounded. The number of bytes read past the end is limited by the length of the resource path segment, and each additional byte is only read if it happens to equal the next path character, so in practice the over-read is one byte. It also cannot influence the response: returning a match requires the final compared index to be len - 1 or len, both in bounds, so out-of-bounds bytes only ever steer the loop to the next candidate resource. The consequence is undefined behaviour, not information disclosure and not a matching error.
The fix adds a k >= len guard at the top of the inner loop, so every uri[k] dereference is within the option value while still allowing a trailing * wildcard to match a longer path.