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

オープン 初心者向け
#3,781 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
networking

調査の方向性

src/Mesh.cpp の Mesh::onRecvPacket にある TRACE 分岐で、isHashMatch がパケットを読み取る前に、残りのペイロード長とホップサイズを比較します。報告には再現ケースが含まれています。3 バイトのパスモードで、フラグは 4 バイトのホップを示し、ハッシュは 3 バイトしかありません。既存の TRACE テストを確認するか、このケースのテストを追加してください。受信側が payload_len を超えて読み取らず、不正な trace を一貫して処理すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C
スター
3.9k
フォーク
1.5k
平均マージ
2日 21時間
マージ済み PR(30日)
34

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

meshcore-dev/MeshCore のほかの issue

meshcore-dev/MeshCore の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。