From: Martin KaFai Lau <martin.lau@linux.dev>
To: Vadim Fedorenko <vadfed@meta.com>
Cc: netdev@vger.kernel.org, linux-crypto@vger.kernel.org,
bpf@vger.kernel.org, Victor Stewart <v@nametag.social>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Jakub Kicinski <kuba@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Mykola Lysenko <mykolal@fb.com>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: Re: [PATCH bpf-next v8 3/3] selftests: bpf: crypto skcipher algo selftests
Date: Wed, 24 Jan 2024 17:26:24 -0800 [thread overview]
Message-ID: <ca2ca170-b76c-4fc3-aa44-cae4a1e25aa4@linux.dev> (raw)
In-Reply-To: <20240115220803.1973440-3-vadfed@meta.com>
On 1/15/24 2:08 PM, Vadim Fedorenko wrote:
> +static void deinit_afalg(void)
> +{
> + if (tfmfd)
The test should be (tfmfd != -1) ?
> + close(tfmfd);
> + if (opfd)
Same here.
> + close(opfd);
> +}
[ ... ]
> +SEC("?fentry.s/bpf_fentry_test1")
> +__failure __msg("Unreleased reference")
The error message is not checked. Take a look at how other tests use RUN_TESTS.
> +int BPF_PROG(crypto_acquire)
> +{
> + struct bpf_crypto_ctx *cctx;
> + struct bpf_dynptr key = {};
> + int err = 0;
> +
> + status = 0;
> +
> + bpf_dynptr_from_mem(crypto_key, sizeof(crypto_key), 0, &key);
> + cctx = bpf_crypto_ctx_create("skcipher", "ecb(aes)", &key, 0, &err);
> +
> + if (!cctx) {
> + status = err;
> + return 0;
> + }
> +
> + cctx = bpf_crypto_ctx_acquire(cctx);
> + if (!cctx)
> + return -EINVAL;
> +
> + bpf_crypto_ctx_release(cctx);
> +
> + return 0;
> +}
> +
> +SEC("tc")
> +int decrypt_sanity(struct __sk_buff *skb)
> +{
> + struct __crypto_ctx_value *v;
> + struct bpf_crypto_ctx *ctx;
> + struct bpf_dynptr psrc, pdst, iv;
> + int err;
> +
> + err = skb_dynptr_validate(skb, &psrc);
> + if (err < 0) {
> + status = err;
> + return TC_ACT_SHOT;
> + }
> +
> + v = crypto_ctx_value_lookup();
> + if (!v) {
> + status = -ENOENT;
> + return TC_ACT_SHOT;
> + }
> +
> + ctx = v->ctx;
> + if (!ctx) {
> + status = -ENOENT;
> + return TC_ACT_SHOT;
> + }
> +
> + bpf_dynptr_from_mem(dst, sizeof(dst), 0, &pdst);
> + /* iv dynptr has to be initialized with 0 size, but proper memory region
> + * has to be provided anyway
> + */
> + bpf_dynptr_from_mem(dst, 0, 0, &iv);
It would be nice to allow passing NULL as an optional "iv" arg. It could be a
future improvement.
Overall lgtm. Please add a cover letter in v4 and also the benchmark test that
was brought up a while back.
> +
> + status = bpf_crypto_decrypt(ctx, &psrc, &pdst, &iv);
> +
> + return TC_ACT_SHOT;
> +}
> +
> +SEC("tc")
> +int encrypt_sanity(struct __sk_buff *skb)
> +{
> + struct __crypto_ctx_value *v;
> + struct bpf_crypto_ctx *ctx;
> + struct bpf_dynptr psrc, pdst, iv;
> + int err;
> +
> + status = 0;
> +
> + err = skb_dynptr_validate(skb, &psrc);
> + if (err < 0) {
> + status = err;
> + return TC_ACT_SHOT;
> + }
> +
> + v = crypto_ctx_value_lookup();
> + if (!v) {
> + status = -ENOENT;
> + return TC_ACT_SHOT;
> + }
> +
> + ctx = v->ctx;
> + if (!ctx) {
> + status = -ENOENT;
> + return TC_ACT_SHOT;
> + }
> +
> + bpf_dynptr_from_mem(dst, sizeof(dst), 0, &pdst);
> + /* iv dynptr has to be initialized with 0 size, but proper memory region
> + * has to be provided anyway
> + */
> + bpf_dynptr_from_mem(dst, 0, 0, &iv);
> +
> + status = bpf_crypto_encrypt(ctx, &psrc, &pdst, &iv);
> +
> + return TC_ACT_SHOT;
> +}
> +
> +char __license[] SEC("license") = "GPL";
next prev parent reply other threads:[~2024-01-25 1:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 22:08 [PATCH bpf-next v8 1/3] bpf: make common crypto API for TC/XDP programs Vadim Fedorenko
2024-01-15 22:08 ` [PATCH bpf-next v8 2/3] bpf: crypto: add skcipher to bpf crypto Vadim Fedorenko
2024-01-25 1:14 ` Martin KaFai Lau
2024-01-25 9:24 ` Herbert Xu
2024-01-15 22:08 ` [PATCH bpf-next v8 3/3] selftests: bpf: crypto skcipher algo selftests Vadim Fedorenko
2024-01-25 1:26 ` Martin KaFai Lau [this message]
2024-02-21 8:43 ` Jakub Sitnicki
2024-02-21 9:19 ` Jakub Sitnicki
2024-01-23 17:51 ` [PATCH bpf-next v8 1/3] bpf: make common crypto API for TC/XDP programs Vadim Fedorenko
2024-01-24 0:12 ` Martin KaFai Lau
2024-01-25 1:10 ` Martin KaFai Lau
2024-01-25 11:19 ` Vadim Fedorenko
2024-01-25 22:34 ` Martin KaFai Lau
2024-01-26 10:30 ` Vadim Fedorenko
2024-01-26 17:38 ` Vadim Fedorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca2ca170-b76c-4fc3-aa44-cae4a1e25aa4@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=v@nametag.social \
--cc=vadfed@meta.com \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).