#include "crypto_common.h"
const volatile unsigned int len = 16;
-char cipher[128] = {};
+/*
+ * cipher[] and key[] are 8-byte aligned and 'params' is kept off the stack to
+ * work around an LLVM code generation bug. clang lowers the memcpy() of these
+ * byte-aligned globals into a per-byte load/store sequence staged on the stack,
+ * and additionally materializes the on-stack 'struct bpf_crypto_params' twice.
+ * Both blow the 512-byte BPF stack limit. Aligning the sources lets clang copy
+ * word-wise, and a global 'params' removes the large object from the stack.
+ */
+char cipher[128] __attribute__((aligned(8))) = {};
u32 key_len, authsize;
char dst[256] = {};
-u8 key[256] = {};
+u8 key[256] __attribute__((aligned(8))) = {};
+static struct bpf_crypto_params params;
long hits = 0;
int status;
int crypto_setup(void *args)
{
struct bpf_crypto_ctx *cctx;
- struct bpf_crypto_params params = {
- .type = "skcipher",
- .key_len = key_len,
- .authsize = authsize,
- };
int err = 0;
status = 0;
return 0;
}
+ __builtin_memcpy(¶ms.type, "skcipher", sizeof("skcipher"));
+ params.key_len = key_len;
+ params.authsize = authsize;
__builtin_memcpy(¶ms.algo, cipher, sizeof(cipher));
__builtin_memcpy(¶ms.key, key, sizeof(key));
cctx = bpf_crypto_ctx_create(¶ms, sizeof(params), &err);
#include "bpf_kfuncs.h"
#include "crypto_common.h"
-unsigned char key[256] = {};
+/*
+ * key[] and algo[] are 8-byte aligned and 'params' is kept off the stack to
+ * work around an LLVM code generation bug. clang lowers the memcpy() of these
+ * byte-aligned globals into a per-byte load/store sequence staged on the stack,
+ * and additionally materializes the on-stack 'struct bpf_crypto_params' twice.
+ * Both blow the 512-byte BPF stack limit. Aligning the sources lets clang copy
+ * word-wise, and a global 'params' removes the large object from the stack.
+ */
+unsigned char key[256] __attribute__((aligned(8))) = {};
u16 udp_test_port = 7777;
u32 authsize, key_len;
-char algo[128] = {};
+char algo[128] __attribute__((aligned(8))) = {};
char dst[16] = {}, dst_bad[8] = {};
+static struct bpf_crypto_params params;
int status;
static int skb_dynptr_validate(struct __sk_buff *skb, struct bpf_dynptr *psrc)
SEC("syscall")
int skb_crypto_setup(void *ctx)
{
- struct bpf_crypto_params params = {
- .type = "skcipher",
- .key_len = key_len,
- .authsize = authsize,
- };
struct bpf_crypto_ctx *cctx;
int err;
return 0;
}
+ __builtin_memcpy(¶ms.type, "skcipher", sizeof("skcipher"));
+ params.key_len = key_len;
+ params.authsize = authsize;
__builtin_memcpy(¶ms.algo, algo, sizeof(algo));
__builtin_memcpy(¶ms.key, key, sizeof(key));