Re: [PATCH bpf-next v3 3/6] bpf: Add SHA hash kfunc for cryptographic hashing

From: Song Liu

Date: Tue Dec 16 2025 - 16:59:05 EST


On Sun, Dec 7, 2025 at 7:01 PM Daniel Hodges <git@xxxxxxxxxxxxxxxx> wrote:
[...]
> +
> + if (!ctx->type->hash)
> + return -EOPNOTSUPP;
> +
> + data_len = __bpf_dynptr_size(data_kern);
> + out_len = __bpf_dynptr_size(out_kern);
> +
> + if (data_len == 0)
> + return -EINVAL;
> +
> + if (!ctx->type->digestsize)
> + return -EOPNOTSUPP;
> +
> + unsigned int digestsize = ctx->type->digestsize(ctx->tfm);

./scripts/checkpatch.pl will complain about this:

WARNING: Missing a blank line after declarations
#109: FILE: kernel/bpf/crypto.c:387:
+ unsigned int digestsize = ctx->type->digestsize(ctx->tfm);
+ if (out_len < digestsize)

Please run ./scripts/checkpatch.pl on all the patches. It also highlights
some other issues, such as we need to update the MAINTAINERS file.

Also, we don't want variable declaration in the middle of a code
block.

> + if (out_len < digestsize)
> + return -EINVAL;
> +
[...]
> static const struct btf_kfunc_id_set crypt_kfunc_set = {
> @@ -383,6 +442,7 @@ static int __init crypto_kfunc_init(void)
> ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &crypt_kfunc_set);
> ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_ACT, &crypt_kfunc_set);
> ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &crypt_kfunc_set);
> + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &crypt_kfunc_set);

This enables all kfuncs in crypt_kfunc_set for BPF_PROG_TYPE_SYSCALL.
We need a clear explanation why this is needed.

Thanks,
Song