69 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */3 4#include "vmlinux.h"5#include <bpf/bpf_helpers.h>6#include <bpf/bpf_tracing.h>7#include "bpf_misc.h"8#include "bpf_kfuncs.h"9#include "crypto_common.h"10 11int status;12SEC("syscall")13int crypto_release(void *ctx)14{15 struct bpf_crypto_params params = {16 .type = "skcipher",17 .algo = "ecb(aes)",18 .key_len = 16,19 };20 21 struct bpf_crypto_ctx *cctx;22 int err = 0;23 24 status = 0;25 26 cctx = bpf_crypto_ctx_create(¶ms, sizeof(params), &err);27 28 if (!cctx) {29 status = err;30 return 0;31 }32 33 bpf_crypto_ctx_release(cctx);34 35 return 0;36}37 38SEC("syscall")39__failure __msg("Unreleased reference")40int crypto_acquire(void *ctx)41{42 struct bpf_crypto_params params = {43 .type = "skcipher",44 .algo = "ecb(aes)",45 .key_len = 16,46 };47 struct bpf_crypto_ctx *cctx;48 int err = 0;49 50 status = 0;51 52 cctx = bpf_crypto_ctx_create(¶ms, sizeof(params), &err);53 54 if (!cctx) {55 status = err;56 return 0;57 }58 59 cctx = bpf_crypto_ctx_acquire(cctx);60 if (!cctx)61 return -EINVAL;62 63 bpf_crypto_ctx_release(cctx);64 65 return 0;66}67 68char __license[] SEC("license") = "GPL";69