Draft
Conversation
6c254be to
154a194
Compare
3584074 to
e97840a
Compare
cd2fa2f to
9d8783f
Compare
7da9352 to
e400cf5
Compare
46a840e to
d56d9c3
Compare
3 tasks
2f89458 to
aca3c3d
Compare
Contributor
CBMC Results (ML-KEM-512)Full Results (187 proofs)
|
Contributor
CBMC Results (ML-KEM-768)Full Results (187 proofs)
|
Contributor
CBMC Results (ML-KEM-1024)Full Results (187 proofs)
|
This commit adds an ABI checker for all AArch64 assembly in mlkem-native.
The purpose of an ABI checker is to ensure that assembly files obey
the required calling conventions. For AArch64 specifically, it is
required by the AAPCS that x19-x30 and d8-d15 are unmodified.
It is important to test this since failure to obey the AAPCS can lead
to rare but fatal bugs depending on the exact compiler and compilation
settings.
On a high level, the ABI checker works as follows:
1. An assembly callstub
void asm_call_stub(struct register_state *input,
struct register_state *output,
void (*function_ptr)(void))
is implemented which calls the function specified by function_ptr
on the input register state input, and returns the output register
state in output. Importantly, it does _not_ assume that function_ptr
obeys the AAPCS, so must be implemented in assembly. This is done for
AArch64 only so far.
2. Randomized ABI checker
Based on asm_call_stub, we implement an ABI checker which calls
the target function with random register inputs and checks that the
output register state has retained the callee saved registers.
3. Pointer inputs
Most functions read/write memory specified via parameters. Calling
those functions with random input would lead to segmentation faults.
The ABI checker therefore does not randomize those arguments, but
instead sets up valid pointers of the right size for them.
For now, we always align the input pointers via MLK_ALIGN. A future
extension should take alignment constraints into account and vary
the alignment of the inputs within those constraints.
The ABI checker gets the information about which inputs are pointers
from the YAML specification of AArch64 assembly.
Some implementation details:
- autogen is extended to generate one test/abicheck/check_FUNCNAME.c
file per function under test. All tests are declared and enumerated
in the autogenerated test/abicheck/checks_all.h.
- The handwritten test/abicheck/abicheck.c invokes all per-function
ABI checks.
- We integrate the abicheck build by extending test/mk/components.mk
with specific build rules. This allows us to partly piggy back on
existing Makefile infrastructure, such as setting execution wrappers
or cross prefixes. On the other hand, a lot of custom hackery is
currently needed to get past the preprocessor directives guarding
individual assembly files. This should be improved in the future.
- scripts/tests is extended to allow for tests abicheck, and
tests all supports --abicheck and --no-abicheck. By default,
the abicheck _is_ run with tests all.
Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
deb58f5 to
b227394
Compare
Extend the ABI checker to cover all x86_64 assembly in mlkem-native. The x86_64 System V ABI requires preservation of rbx, rbp, and r12-r15. Unlike AArch64, no SIMD registers are callee-saved. Changes: - Add YAML metadata to all 21 dev x86_64 assembly files (20 arith + 1 keccak), propagated to mlkem/ via simpasm - Add x86_64_callstub.S implementing the register state capture/restore for x86_64 System V - Extend abicheckutil.c/h with x86_64_register_state struct and compliance check - Generalize autogen gen_abicheck() to handle both architectures via an arch_configs table; output filenames are now suffixed with the architecture (e.g. check_ntt_asm_aarch64.c) - Extend components.mk with x86_64 build rules including constant data files (consts.c, compress_consts.c, etc.) Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds ABI checkers for all AArch64 and x86_64 assembly in mlkem-native.
The purpose of an ABI checker is to ensure that assembly files obey the required calling conventions. For AArch64, the AAPCS requires that x19-x30 and d8-d15 are preserved. For x86_64, the System V ABI requires
that rbx, rbp, and r12-r15 are preserved.
It is important to test this since failure to obey the calling convention can lead to rare but fatal bugs depending on the exact compiler and compilation settings.
On a high level, the ABI checker works as follows:
is implemented which calls the function specified by function_ptr on the input register state input, and returns the output register state in output. Importantly, it does not assume that function_ptr obeys the
calling convention, so must be implemented in assembly.
Based on the call stub, we implement an ABI checker which calls the target function with known register inputs and checks that the output register state has retained the callee-saved registers.
Most functions read/write memory specified via parameters. Calling those functions with random input would lead to segmentation faults. The ABI checker therefore does not randomize those arguments, but instead sets
up valid aligned buffers of the right size for them.
The ABI checker gets the information about which inputs are pointers from the YAML specification embedded in each assembly file.
Some implementation details:
prefixes. On the other hand, a lot of custom hackery is currently needed to get past the preprocessor directives guarding individual assembly files. This should be improved in the future.