]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix misaligned SP for libfuzzer entry
authorKeith Randall <khr@golang.org>
Tue, 9 May 2023 22:55:45 +0000 (15:55 -0700)
committerKeith Randall <khr@golang.org>
Wed, 10 May 2023 04:57:07 +0000 (04:57 +0000)
libfuzzer is written in C and so requires by the C abi that SP be
aligned correctly mod 16. Normally CALLs need to have SP aligned to 0
mod 16, but because we're simulating a CALL (which pushes a return
address) with a JMP (which doesn't), we need to align to 8 mod 16
before JMPing.

This is not causing any current problems that I know of. All the
functions called from this callsite that I checked don't rely on
correct alignment.  So this CL is just futureproofing.

Update #49075

Change-Id: I13fcbe9aaf2853056a6d44dc3aa64b7db689e144
Reviewed-on: https://go-review.googlesource.com/c/go/+/494117
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
src/runtime/libfuzzer_amd64.s

index 7f184d9cb64e45f1f819b581ec1f2c1287cd46c9..e30b768a05a49a9908d335c944ccc9db7865d510 100644 (file)
@@ -93,6 +93,7 @@ TEXT  runtime·libfuzzerCallTraceIntCmp(SB), NOSPLIT, $0-32
        MOVQ    (g_sched+gobuf_sp)(R10), SP
 call:
        ANDQ    $~15, SP        // alignment for gcc ABI
+       SUBQ    $8, SP
        // Load the address of the end of the function and push it into the stack.
        // This address will be jumped to after executing the return instruction
        // from the return sled. There we reset the stack pointer and return.