From: bot+bpf-ci@kernel.org
To: ebiggers@kernel.org,bpf@vger.kernel.org,vadim.fedorenko@linux.dev,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com
Cc: linux-crypto@vger.kernel.org,linux-kernel@vger.kernel.org,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,john.fastabend@gmail.com,kmehltretter@gmail.com,ebiggers@kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v4] bpf: crypto: Use AES-CBC and AES-ECB libraries
Date: Wed, 23 Sep 2026 04:22:57 +0000 (UTC) [thread overview]
Message-ID: <a5e07fdd93b0f6b38dfce4cf977e88eac653bed08ee713372bf31bc6cff349e7@mail.kernel.org> (raw)
In-Reply-To: <20260923032703.59816-1-ebiggers@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 2894 bytes --]
> diff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c
> index 51f89cecefb4..784e2bd5ca92 100644
> --- a/kernel/bpf/crypto.c
> +++ b/kernel/bpf/crypto.c
[ ... ]
> @@ -36,94 +30,53 @@ struct bpf_crypto_params {
> u32 authsize;
> };
>
> +enum bpf_crypto_algo_id {
> + BPF_ALGO_AES_CBC,
> + BPF_ALGO_AES_ECB,
> +};
> +
> +/**
> + * struct bpf_crypto_ctx - refcounted BPF crypto context structure
> + * @algo: The crypto algorithm ID
> + * @key: The crypto key
> + * @rcu: The RCU head used to free the crypto context with RCU safety.
> + * @usage: Object reference counter. When the refcount goes to 0, the
> + * memory is released back to the BPF allocator, which provides
> + * RCU safety.
> + */
> +struct bpf_crypto_ctx {
> + enum bpf_crypto_algo_id algo;
> + union {
> + struct aes_key aes;
> + } key;
> + struct rcu_head rcu;
> + refcount_t usage;
> +};
This isn't a bug, but struct aes_enckey pads itself so the round keys
can be 16-byte aligned for better performance (as documented in
include/crypto/aes.h). Putting the 4-byte algo enum before the key union
means key.aes lands at offset 4, so the round keys can never hit that
alignment. Would putting key first (or aligning it) be worth considering
here?
[ ... ]
> +static int bpf_aes_cbc_crypt(u8 *dst, u32 dst_len, const u8 *src, u32 src_len,
> + u8 *iv, u32 iv_len,
> + const struct bpf_crypto_ctx *ctx, bool decrypt)
> +{
> + if (iv_len != AES_BLOCK_SIZE)
> + return -EINVAL;
> + if (src_len % AES_BLOCK_SIZE || dst_len < src_len)
> + return -EINVAL;
> + if (decrypt)
> + aes_cbc_decrypt(dst, src, src_len, iv, &ctx->key.aes);
> + else
> + aes_cbc_encrypt(dst, src, src_len, iv, &ctx->key.aes);
> + return 0;
> +}
> +
> +static int bpf_aes_ecb_crypt(u8 *dst, u32 dst_len, const u8 *src, u32 src_len,
> + u8 *iv, u32 iv_len,
> + const struct bpf_crypto_ctx *ctx, bool decrypt)
> +{
> + if (iv_len != 0)
> + return -EINVAL;
> + if (src_len % AES_BLOCK_SIZE || dst_len < src_len)
> + return -EINVAL;
> + if (decrypt)
> + aes_ecb_decrypt(dst, src, src_len, &ctx->key.aes);
> + else
> + aes_ecb_encrypt(dst, src, src_len, &ctx->key.aes);
> + return 0;
> +}
This isn't a bug, but both helpers repeat the same src_len %
AES_BLOCK_SIZE and dst_len < src_len checks. Could that validation stay
in bpf_crypto_crypt() next to the existing length checks, leaving only
the iv_len check per mode?
Also, bpf_aes_ecb_crypt() takes an iv parameter but never uses it (only
iv_len is checked). Would it read more clearly to drop the iv argument
from this function, or drop both iv and iv_len and do the iv_len != 0
check in the ECB arm of bpf_crypto_crypt()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35815287581
next prev parent reply other threads:[~2026-09-23 4:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 3:27 Eric Biggers
2026-09-23 4:22 ` bot+bpf-ci [this message]
2026-09-23 4:55 ` Eric Biggers
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=a5e07fdd93b0f6b38dfce4cf977e88eac653bed08ee713372bf31bc6cff349e7@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=ebiggers@kernel.org \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kmehltretter@gmail.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=vadim.fedorenko@linux.dev \
--cc=yonghong.song@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
all inboxes | Powered by JetHome®