Skip to content

[24.0] Backport Cranelift: x64: fix incorrect load-sinking in copysign operator. (#12437)#13213

Merged
cfallin merged 2 commits intobytecodealliance:release-24.0.0from
cfallin:cve-copysign-backport-24
Apr 28, 2026
Merged

[24.0] Backport Cranelift: x64: fix incorrect load-sinking in copysign operator. (#12437)#13213
cfallin merged 2 commits intobytecodealliance:release-24.0.0from
cfallin:cve-copysign-backport-24

Conversation

@cfallin
Copy link
Copy Markdown
Member

@cfallin cfallin commented Apr 27, 2026

The implementation of the fcopysign operator uses vector bitwise AND instructions on the floating-point/vector registers containing the inputs to the operator. This is a reasonable implementation as the instruction set does not have scalar (single-lane) bitwise operators. However, when load-sinking automatically kicks in for an operand to an andps, it can turn a 64-bit load (f64.load) into a 128-bit load incorrectly.

This load-widening can cause out-of-bounds accesses where they were not expected. When dynamic bounds checks are enabled, we compile assuming the correct load-operator width is codegen'd; a too-wide load could read beyond the checked bound, either into unmapped memory (crashing the process) or, worse, valid data outside the sandbox. In the case of fcopysign the result of that read is not directly available, because it will go into the high (unused) lane, but the out-of-bounds read itself is a problem.

Thanks to louismerlin for reporting!

@cfallin cfallin requested review from a team as code owners April 27, 2026 20:08
@cfallin cfallin requested review from alexcrichton and uweigand and removed request for a team April 27, 2026 20:08
Comment thread RELEASES.md
…gn` operator. (bytecodealliance#12437)

The implementation of the `fcopysign` operator uses vector bitwise AND
instructions on the floating-point/vector registers containing the
inputs to the operator. This is a reasonable implementation as the
instruction set does not have scalar (single-lane) bitwise
operators. However, when load-sinking automatically kicks in for an
operand to an `andps`, it can turn a 64-bit load (`f64.load`) into a
128-bit load incorrectly.

This load-widening can cause out-of-bounds accesses where they were
not expected. When dynamic bounds checks are enabled, we compile
assuming the correct load-operator width is codegen'd; a too-wide load
could read beyond the checked bound, either into unmapped
memory (crashing the process) or, worse, valid data outside the
sandbox. In the case of `fcopysign` the result of that read is not
directly available, because it will go into the high (unused)
lane, but the out-of-bounds read itself is a problem.

Thanks to louismerlin for reporting!
@cfallin cfallin force-pushed the cve-copysign-backport-24 branch from 1d50846 to cf3ab46 Compare April 27, 2026 20:11
@cfallin cfallin enabled auto-merge (squash) April 27, 2026 20:11
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen wasmtime:docs Issues related to Wasmtime's documentation labels Apr 27, 2026
@cfallin cfallin merged commit 588c319 into bytecodealliance:release-24.0.0 Apr 28, 2026
124 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator wasmtime:docs Issues related to Wasmtime's documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants