[libc-commits] [libc] [libc] fortify jmp buffer for x86-64 (PR #112769)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Fri Oct 18 10:46:19 PDT 2024
================
@@ -11,35 +11,97 @@
#include "src/__support/macros/config.h"
#include "src/setjmp/setjmp_impl.h"
+#if LIBC_COPT_SETJMP_ENABLE_FORTIFICATION
+#include "src/setjmp/checksum.h"
+#endif
+
#if !defined(LIBC_TARGET_ARCH_IS_X86_64)
#error "Invalid file include"
#endif
-namespace LIBC_NAMESPACE_DECL {
+#if LIBC_COPT_SETJMP_ENABLE_FORTIFICATION
+#define ACCUMULATE_CHECKSUM() \
----------------
SchrodingerZhu wrote:
fixed. also, it is easy to see there are quality issues in current implementation but I think it is a reasonable compromise for this initial attempt. I have mentioned the issues in the newly added comments and I am open to further improvement if anyone has better ideas.
```
// For now, the checksum is computed with a simple multiply-xor-rotation
// algorithm. The pesudo code is as follows:
//
// def checksum(x, acc):
// masked = x ^ MASK
// high, low = full_multiply(masked, acc)
// return rotate(high ^ low, ROTATION)
//
// Similar other multiplication-based hashing, zero inputs
// for the `full_multiply` function may pollute the checksum with zero.
// However, user inputs are always masked where the initial ACC amd MASK are
// generated with random entropy and ROTATION is a fixed prime number. It should
// be of a ultra-low chance for masked or acc being zero given a good quality of
// system-level entropy.
```
https://github.com/llvm/llvm-project/pull/112769
More information about the libc-commits
mailing list