[Bug][TIR] `s_tir.Schedule.cache_read` omits domain bounds predicate on shifted conditional reads, causing negative-index heap buffer underflow (`SIGABRT`/`SIGSEGV`)
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in src/s_tir/schedule/primitive/cache_read_write.cc, in MakeCacheStage, and compare its cache block predicate with predicate generation in ComputeAt. Use the supplied reproduction to inspect the scheduled B_local block and confirm the missing bounds predicate causes the negative index. Done means the cache copy preserves bounds safety and the reproduction exits successfully with the expected results.
由索引模型根据 Issue 内容生成。
描述
Expected behavior
Applying valid S-TIR primitives (split, compute_at, cache_read) to a producer-consumer PrimFunc where the consumer conditionally reads a shifted index (T.if_then_else(4 <= v0, B[v0 - 4, v1], A[v0, v1])) must preserve bounds safety and produce identical results (sum=12288.0, exit code 0).
Actual behavior
s_tir.Schedule.cache_read generates an unguarded B_local cache-copy block with v0 = T.axis.spatial(2, ax0 - 4 + ax0_1) and predicate = true (missing T.where(4 <= ax0)), even though the adjacent compute_at producer block in the same loop correctly carries T.where(4 <= ax0).
After CompactBufferAllocation, B and B_local are compacted to (1024,) and unconditionally accessed at negative indices -4096..-1 for ax0 in 0..3:
B_local[ax0 * 1024 + ax1 - T.max(0, ax0 - 4) * 1024 - 4096] = B[...]
At runtime this underflows the heap allocation, corrupting TVM's WorkspacePool and glibc heap metadata and crashing with SIGABRT (corrupted double-linked list / double free or corruption (out)) or SIGSEGV depending on heap layout.
Environment
- TVM:
0.27.0(7b5acb32bd271342a24130f4ef439ff6c2e52c6c) - Upstream status: verified still unfixed on
apache/tvmmain(84657c01e5d3672cfd299bd3d5c77bff3888a1a9, 2026-12-02) - OS: Linux x86_64
Steps to reproduce
import numpy as np
import tvm
from tvm import s_tir
from tvm.script import tirx as T
@T.prim_func(s_tir=True)
def slice_then_concat(
X: T.Buffer((T.int64(5), T.int64(2048)), "float32"),
A: T.Buffer((T.int64(4), T.int64(2048)), "float32"),
C: T.Buffer((T.int64(6), T.int64(2048)), "float32"),
):
B = T.sblock_alloc_buffer((T.int64(2), T.int64(2048)), "float32")
for ax0, ax1 in T.grid(T.int64(2), T.int64(2048)):
with T.sblock("slice"):
v0, v1 = T.axis.remap("SS", [ax0, ax1])
B[v0, v1] = X[v0 + T.int64(3), v1]
for ax0, ax1 in T.grid(T.int64(6), T.int64(2048)):
with T.sblock("concat"):
v0, v1 = T.axis.remap("SS", [ax0, ax1])
C[v0, v1] = T.if_then_else(T.int64(4) <= v0, B[v0 - T.int64(4), v1], A[v0, v1])
sch = s_tir.Schedule(slice_then_concat)
blk_s = sch.get_sblock("slice")
blk_c = sch.get_sblock("concat")
_, l1 = sch.get_loops(blk_c)
l1_o, _ = sch.split(l1, factors=[None, 1024])
sch.compute_at(blk_s, l1_o, preserve_unit_loops=True)
sch.cache_read(blk_c, 0, "local")
f = tvm.compile(sch.mod, target="llvm")
f(
tvm.runtime.tensor(np.ones((5, 2048), "float32")),
tvm.runtime.tensor(np.ones((4, 2048), "float32")),
tvm.runtime.tensor(np.zeros((6, 2048), "float32")),
)
# Crashes with SIGABRT (e.g. corrupted double-linked list / double free or corruption) or SIGSEGV
Suggested fix
In src/s_tir/schedule/primitive/cache_read_write.cc (MakeCacheStage), derive the SBlockRealize predicate from the domain bounds of each cache block iter var (0 <= iter_value < dom->extent, matching compute_at / ComputeAt predicate generation) rather than hardcoding IntImm::Bool(true).
- 主要语言
- Python
- 星标
- 13.9k
- 派生
- 4.1k
- 平均合并
- 4 天 22 小时
- 30 天内合并 PR
- 22
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/tvm 的其他 Issue
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is None可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensors未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 3 天内回复
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradients可能已有人在做 @pierceluu10 于 4 天前认领。 未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputs可能已有人在做 @tandede 于 9 天前认领。 未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 3 天内回复
-
needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 78/100
web-push-libs/pywebpush#216 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
AgriciDaniel/claude-seo#572 ·
维护者通常 5 天内回复
-
area:print-dispatch
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
area: docs domain: technical-writing good first issue type: documentation
难度 2/5 1-3 小时 新手友好度 80/100
Deepak3699/Ai_Mentor#919 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复