Skip to content

Fix out-of-bounds read when tracing global.set and table ops - #2802

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:trace-imported-index
Jul 29, 2026
Merged

sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:trace-imported-index

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

ASan, spectest-interp --trace on a module that imports a global and also defines one:

==73766==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60e0000002a4
READ of size 8 at 0x60e0000002a4 thread T0
    #1 Thread::TraceSource::GetGlobalType(unsigned int) interp.cc:3022
    #2 Thread::TraceSource::Pick(unsigned int, Instr) interp.cc:2954
    #3 Istream::Trace(...) istream.cc:887
0x60e0000002a4 is located 12 bytes after 152-byte region [0x60e000000200,0x60e000000298)

Noticed it while reading the trace helpers. ModuleDesc::globals and ModuleDesc::tables hold only the defined entries, imports live in ModuleDesc::imports. But the global.set/table.* immediate is the module-level index, which counts imports first. One imported global plus one defined global is already enough to run off the end. GetTableElementType has the same shape at interp.cc:3026, reached from table.grow and table.fill.

The garbage ValueType that comes back then decides how the operand Value is read, so a debug build aborts on the CheckType assert in interp.h and a release build prints an arbitrary reference index.

Both immediates now resolve against the instance, which is what the GlobalSet, DoTableGrow and DoTableFill handlers already do. Regression test added under test/interp.

spectest-interp --trace on a module that imports a global and also
defines one, ASan build:

==73766==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x60e0000002a4
READ of size 8 at 0x60e0000002a4 thread T0
    WebAssembly#1 Thread::TraceSource::GetGlobalType(unsigned int) interp.cc:3022
    WebAssembly#2 Thread::TraceSource::Pick(unsigned int, Instr) interp.cc:2954
    WebAssembly#3 Istream::Trace(...) istream.cc:887
0x60e0000002a4 is located 12 bytes after 152-byte region

ModuleDesc::globals and ModuleDesc::tables hold only the defined
entries; imports live in ModuleDesc::imports. The global.set/table.*
immediate is the module-level index and counts imports first, so one
imported global plus one defined global already runs off the end.
GetTableElementType has the same shape.

The garbage ValueType that comes back decides how the operand Value is
read, so a debug build aborts on the CheckType assert in interp.h and a
release build prints an arbitrary reference index.

Resolve both immediates against the instance instead, which is what the
GlobalSet, DoTableGrow and DoTableFill handlers already do.
@sbc100
sbc100 merged commit f8e5413 into WebAssembly:main Jul 29, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants