Skip to content

wasm2c: missing guard force_read error with escape hatch - #2826

Merged
shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:noforceread
Aug 21, 2026
Merged

shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:noforceread

Conversation

@shravanrn

@shravanrn shravanrn commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

This PR ensures that when guard pages are used the force_read macro is either

  • explicitly defined for the given platform
  • explicitly opted out with WASM_RT_NONCONFORMING_ALLOW_OOB_READ_ELIMINATION

rather than silently failing to define it for unknown platforms

This change also allows the embedder to opt to disable force_reads (this is off by default, since it is non conforming). This is independently a performance optimization when Wasm conformance is not required as it speeds up several sandboxing workloads by a large amount

  • Sandboxed XML parsing with libExpat by 5%
  • Sandboxed Audio speed adjustment with libSoundTouch by 10%

wasm2c is not the first compiler to add the option for an embedder to disable dead reads. Currently Wamr and aWsm enable this by default and don't have a way to disable it, while Wasmer enables it by default and has a switch to disable it. I think wasm2c should remain conformant and not go that far, but it can provide an off-by-default option for this. The actual feature is only about 5 lines so is easy enough to maintain.

@shravanrn

Copy link
Copy Markdown
Collaborator Author

@sbc100 I have split out the change as requested. As noted above, this is a change I definitely want to land and use soon due to the performance implications.

@shravanrn
shravanrn force-pushed the noforceread branch 3 times, most recently from cebcc4e to f7b161c Compare August 17, 2026 00:40
@shravanrn

Copy link
Copy Markdown
Collaborator Author

@sbc100 @keithw Just following up. Did y'all have thoughts about landing this? Any chance one of you can review?

Comment thread test/wasm2c/hello.txt Resolved
@shravanrn shravanrn changed the title wasm2c: allow embedder to configure elimination of dead OOB reads wasm2c: missing guard force_read error with escape hatch Aug 21, 2026
@shravanrn

Copy link
Copy Markdown
Collaborator Author

@sbc100 I have updated the commit and description to be a reflect that this is general force_read usage cleanup. Please have a look when you get a chance.

@shravanrn
shravanrn requested a review from sbc100 August 21, 2026 05:14

@keithw keithw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all lgtm, with the understanding that we are going to clean up this forest of preprocessor macros in some future version of wasm2c. :-)

Comment thread src/template/wasm2c.declarations.c Resolved
@shravanrn

shravanrn commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

This all lgtm, with the understanding that we are going to clean up this forest of preprocessor macros in some future version of wasm2c. :-)

Yup, I think we can start on this incrementally. I think the way to tackle this is probably start the split from macros into a compile time flag one-by-one starting with the guard-page vs bounds-check emission. This is mostly cleanly separable --- the only funny edge case is non-64k wasm memory sizes (the code right not does malloc even if mmap is requested which is very confusing). I'll cleanup the macro version of that first in a separate PR, before we start with splitting things into compile time flags

@shravanrn
shravanrn enabled auto-merge (rebase) August 21, 2026 19:56
@shravanrn
shravanrn merged commit c886b0a into WebAssembly:main Aug 21, 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.

3 participants