Skip to content

wasm2c: (Security) ensure tailcalls use initialized instance references for all cases - #2857

Merged
shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:fix-tailcalls
Sep 15, 2026
Merged

shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:fix-tailcalls

Conversation

@shravanrn

Copy link
Copy Markdown
Collaborator

This PR fixes a case in the tail-call implementation in wasm2c where the instance_ptr is not initialized before being passed to a callee --- on a ReturnCall to a non-imported function. As an added defense in depth instance_ptr is explicitly initialized to zero to ensure such bugs would result in an unexploitable crash in the future.

@shravanrn
shravanrn requested review from keithw and sbc100 September 15, 2026 06:48
@shravanrn shravanrn changed the title wasm2c: (Security) ensure tailcalls use initialized instance references wasm2c: (Security) ensure tailcalls use initialized instance references for all cases Sep 15, 2026
Comment thread test/wasm2c/tail-calls.txt

@sbc100 sbc100 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.

lgtm % @zherczeg's questions.

Also, can we at a test? Or is there some reason why this is tricky to test?

@keithw

keithw commented Sep 15, 2026

Copy link
Copy Markdown
Member

Yeah, I'm a little confused why none of the tail-call tests would trigger this. Are there really zero test cases where a return_call is made to a function in the same module?? If so, that seems like what we need to be fixing...

@shravanrn

shravanrn commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Also, can we at a test?

Yeah, I'm a little confused why none of the tail-call tests would trigger this. Are there really zero test cases where a return_call is made to a function in the same module?? If so, that seems like what we need to be fixing...

@keithw @sbc100 This will trigger only when a tail call into the same module also uses memory. Which is a combination I don't think is covered in the test suite. I have a test floating around somewhere that can trigger this, but I haven't merged this in yet. I can add that test in a separate commit, but I would like to land the security fix asap, as it may take a me a couple of days before I get free time to work on this again

@keithw

keithw commented Sep 15, 2026

Copy link
Copy Markdown
Member

Yeah, I wouldn't add the test here -- it should be upstream.

@sbc100

sbc100 commented Sep 15, 2026

Copy link
Copy Markdown
Member

We do quite often add tests here, even when there is a plan to push them upstream eventually.

lgtm either way though

@shravanrn
shravanrn enabled auto-merge (rebase) September 15, 2026 19:17
@shravanrn
shravanrn merged commit 18a2ea3 into WebAssembly:main Sep 15, 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.

4 participants