Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

cranelift(x64): reject callee-pop stack args that don't fit `ret imm16` (#14629)

Roman Volosatovs2ccff02c1ff8
diff --git a/cranelift/codegen/src/isa/x64/abi.rs b/cranelift/codegen/src/isa/x64/abi.rs
index 8b2afbd93f..e4818f06b2 100644
--- a/cranelift/codegen/src/isa/x64/abi.rs
+++ b/cranelift/codegen/src/isa/x64/abi.rs
@@ -413,6 +413,13 @@ impl ABIMachineSpec for X64ABIMachineSpec {
next_stack = align_to(next_stack, 16);
+ if args_or_rets == ArgsOrRets::Args
+ && matches!(call_conv, CallConv::Tail | CallConv::Winch)
+ && next_stack > u32::from(u16::MAX)
+ {
+ return Err(crate::CodegenError::ImplLimitExceeded);
+ }
+
Ok((next_stack, extra_arg_idx))
}
diff --git a/cranelift/filetests/filetests/isa/x64/callee-pop-too-large.clif b/cranelift/filetests/filetests/isa/x64/callee-pop-too-large.clif
new file mode 100644
index 0000000000..66e7690a0d
--- /dev/null
+++ b/cranelift/filetests/filetests/isa/x64/callee-pop-too-large.clif
@@ -0,0 +1,8 @@
+test compile expect-fail
+target x86_64
+
+function %winch(i64 sarg(70000)) -> i64 winch {
+block0(v0: i64):
+ v1 = load.i64 v0
+ return v1
+}