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

未关闭 适合新手
#3,781 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
networking

调研方向

从 src/Mesh.cpp 中 Mesh::onRecvPacket 的 TRACE 分支开始,在 isHashMatch 读取数据包之前,将剩余 payload 长度与 hop 大小进行比较。报告包含一个可复现的案例:3 字节路径模式,flags 声明 hop 为 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 小时
30 天内合并 PR
34

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

meshcore-dev/MeshCore 的其他 Issue

查看 meshcore-dev/MeshCore 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。