TRACE handler reads past the received payload when hop size exceeds remaining data

Aperta Adatta ai principianti
#3,781 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c
Ambito
networking

Direzione di ricerca

Inizia in src/Mesh.cpp, nel ramo TRACE di Mesh::onRecvPacket, e confronta la lunghezza rimanente del payload con la dimensione dell'hop prima che isHashMatch legga il pacchetto. Il report include un caso riproducibile: modalità percorso a 3 byte con flag che dichiarano hop a 4 byte e solo 3 byte di hash. Controlla i test TRACE esistenti o aggiungi una copertura per quel caso; il lavoro è completato quando il ricevitore non legge oltre payload_len e gestisce in modo coerente la trace malformata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Firmware: repeater-v1.18.0 (81dbae5), same code on current main

Description

In Mesh::onRecvPacket (src/Mesh.cpp), the TRACE branch checks:

uint8_t len = pkt->payload_len - i;
uint16_t offset = (uint16_t)pkt->path_len << path_sz;
if (offset >= len) {
  onTraceRecv(...);
} else if (self_id.isHashMatch(&pkt->payload[i + offset], 1 << path_sz) && ...) {

There is no check that len - offset >= (1 << path_sz). If a TRACE's flags declare a larger hop size than the data actually carries, isHashMatch compares bytes beyond payload_len. Those bytes are stale contents of the packet buffer, so the forward decision becomes nondeterministic.

How it shows up

A third-party companion (Wadamesh, T-Deck) in 3-byte path mode sends TRACE with flags = 2 (4-byte hops) and only 3 hash bytes. Against a 1.18 repeater, the first trace was not forwarded; later identical traces (10/10) were. That matches a stale 4th byte that sometimes equals the repeater's pub_key[3]. The sender is wrong too (ALLFATHER-BV/wadamesh#818), but the receiver should not depend on undefined memory.

Suggested fix

uint8_t hsz = 1 << path_sz;
if (offset >= len) {
  onTraceRecv(...);
} else if (len - offset >= hsz &&
           self_id.isHashMatch(&pkt->payload[i + offset], hsz) && ...) {

Optionally treat len % hsz != 0 as malformed and drop the packet.

Lingua principale
C
Stelle
3.9k
Fork
1.5k
Merge medio
2g 21h
PR unite (30g)
34

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di meshcore-dev/MeshCore

Tutte le issue di meshcore-dev/MeshCore

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.