| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/27 00:15 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_CRYPTO"
],
"FocusSymbols": [
"bpf_crypto_ctx_create",
"bpf_crypto_encrypt",
"bpf_crypto_decrypt",
"bpf_crypto_crypt",
"bpf_aes_cbc_crypt",
"bpf_aes_ecb_crypt"
],
"KMSANReasoning": "The patch refactors BPF crypto support by replacing the dynamic skcipher crypto API registration with direct calls to kernel AES library routines (CRYPTO_LIB_AES_CBC and CRYPTO_LIB_AES_ECB). \n\nFrom a memory initialization perspective:\n- bpf_crypto_ctx is allocated using kzalloc_obj(), which zeroes all context fields prior to usage.\n- Error codes and local variables in bpf_crypto_ctx_create() and bpf_crypto_crypt() are initialized on all paths before evaluation.\n- No kernel data structures or padded structs are copied to userspace (no copy_to_user, put_user, netlink, or socket options involved).\n- Buffer and dynptr length validations are strictly checked (e.g. AES block size multiples, dst_len \u003e= src_len, exact IV size).\n- Any potential memory safety issues (such as buffer overruns during encryption/decryption or refcount/use-after-free issues with the crypto context) are squarely within the domain of KASAN rather than KMSAN.\n\nTherefore, the changes do not expose uninitialized memory risks or kernel-to-user info-leaks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch refactors the BPF crypto subsystem to directly use AES library functions (AES-CBC and AES-ECB) rather than the generic crypto skcipher API, adding new validation logic, direct key setup, encryption/decryption helpers, and a new WARN_ON_ONCE assertion. These changes modify reachable BPF kfuncs executable via standard BPF syscall programs and warrant fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/27 00:15 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit c80e54e97a241421dbaaa989b63fd2cee65db73f\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Sep 27 00:15:27 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 140eafcbbd782..cf806c2b788e3 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -4936,8 +4936,6 @@ BPF [CRYPTO]\n M:\tVadim Fedorenko \u003cvadim.fedorenko@linux.dev\u003e\n L:\tbpf@vger.kernel.org\n S:\tMaintained\n-F:\tcrypto/bpf_crypto_skcipher.c\n-F:\tinclude/linux/bpf_crypto.h\n F:\tkernel/bpf/crypto.c\n \n BPF [DOCUMENTATION] (Related to Standardization)\ndiff --git a/crypto/Makefile b/crypto/Makefile\nindex 8386d55a9755e..33bb5ad595e8f 100644\n--- a/crypto/Makefile\n+++ b/crypto/Makefile\n@@ -22,9 +22,6 @@ crypto_skcipher-y += lskcipher.o\n crypto_skcipher-y += skcipher.o\n \n obj-$(CONFIG_CRYPTO_SKCIPHER2) += crypto_skcipher.o\n-ifeq ($(CONFIG_BPF_SYSCALL),y)\n-obj-$(CONFIG_CRYPTO_SKCIPHER2) += bpf_crypto_skcipher.o\n-endif\n \n obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o\n obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o\ndiff --git a/crypto/bpf_crypto_skcipher.c b/crypto/bpf_crypto_skcipher.c\ndeleted file mode 100644\nindex a88798d3e8c87..0000000000000\n--- a/crypto/bpf_crypto_skcipher.c\n+++ /dev/null\n@@ -1,83 +0,0 @@\n-// SPDX-License-Identifier: GPL-2.0-only\n-/* Copyright (c) 2024 Meta, Inc */\n-#include \u003clinux/types.h\u003e\n-#include \u003clinux/module.h\u003e\n-#include \u003clinux/bpf_crypto.h\u003e\n-#include \u003ccrypto/skcipher.h\u003e\n-\n-static void *bpf_crypto_lskcipher_alloc_tfm(const char *algo)\n-{\n-\treturn crypto_alloc_lskcipher(algo, 0, 0);\n-}\n-\n-static void bpf_crypto_lskcipher_free_tfm(void *tfm)\n-{\n-\tcrypto_free_lskcipher(tfm);\n-}\n-\n-static int bpf_crypto_lskcipher_has_algo(const char *algo)\n-{\n-\treturn crypto_has_skcipher(algo, CRYPTO_ALG_TYPE_LSKCIPHER, CRYPTO_ALG_TYPE_MASK);\n-}\n-\n-static int bpf_crypto_lskcipher_setkey(void *tfm, const u8 *key, unsigned int keylen)\n-{\n-\treturn crypto_lskcipher_setkey(tfm, key, keylen);\n-}\n-\n-static u32 bpf_crypto_lskcipher_get_flags(void *tfm)\n-{\n-\treturn crypto_lskcipher_get_flags(tfm);\n-}\n-\n-static unsigned int bpf_crypto_lskcipher_ivsize(void *tfm)\n-{\n-\treturn crypto_lskcipher_ivsize(tfm);\n-}\n-\n-static unsigned int bpf_crypto_lskcipher_statesize(void *tfm)\n-{\n-\treturn crypto_lskcipher_statesize(tfm);\n-}\n-\n-static int bpf_crypto_lskcipher_encrypt(void *tfm, const u8 *src, u8 *dst,\n-\t\t\t\t\tunsigned int len, u8 *siv)\n-{\n-\treturn crypto_lskcipher_encrypt(tfm, src, dst, len, siv);\n-}\n-\n-static int bpf_crypto_lskcipher_decrypt(void *tfm, const u8 *src, u8 *dst,\n-\t\t\t\t\tunsigned int len, u8 *siv)\n-{\n-\treturn crypto_lskcipher_decrypt(tfm, src, dst, len, siv);\n-}\n-\n-static const struct bpf_crypto_type bpf_crypto_lskcipher_type = {\n-\t.alloc_tfm\t= bpf_crypto_lskcipher_alloc_tfm,\n-\t.free_tfm\t= bpf_crypto_lskcipher_free_tfm,\n-\t.has_algo\t= bpf_crypto_lskcipher_has_algo,\n-\t.setkey\t\t= bpf_crypto_lskcipher_setkey,\n-\t.encrypt\t= bpf_crypto_lskcipher_encrypt,\n-\t.decrypt\t= bpf_crypto_lskcipher_decrypt,\n-\t.ivsize\t\t= bpf_crypto_lskcipher_ivsize,\n-\t.statesize\t= bpf_crypto_lskcipher_statesize,\n-\t.get_flags\t= bpf_crypto_lskcipher_get_flags,\n-\t.owner\t\t= THIS_MODULE,\n-\t.name\t\t= \"skcipher\",\n-};\n-\n-static int __init bpf_crypto_skcipher_init(void)\n-{\n-\treturn bpf_crypto_register_type(\u0026bpf_crypto_lskcipher_type);\n-}\n-\n-static void __exit bpf_crypto_skcipher_exit(void)\n-{\n-\tint err = bpf_crypto_unregister_type(\u0026bpf_crypto_lskcipher_type);\n-\tWARN_ON_ONCE(err);\n-}\n-\n-module_init(bpf_crypto_skcipher_init);\n-module_exit(bpf_crypto_skcipher_exit);\n-MODULE_LICENSE(\"GPL\");\n-MODULE_DESCRIPTION(\"Symmetric key cipher support for BPF\");\ndiff --git a/include/linux/bpf_crypto.h b/include/linux/bpf_crypto.h\ndeleted file mode 100644\nindex a41e71d4e2d9f..0000000000000\n--- a/include/linux/bpf_crypto.h\n+++ /dev/null\n@@ -1,24 +0,0 @@\n-/* SPDX-License-Identifier: GPL-2.0-only */\n-/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */\n-#ifndef _BPF_CRYPTO_H\n-#define _BPF_CRYPTO_H\n-\n-struct bpf_crypto_type {\n-\tvoid *(*alloc_tfm)(const char *algo);\n-\tvoid (*free_tfm)(void *tfm);\n-\tint (*has_algo)(const char *algo);\n-\tint (*setkey)(void *tfm, const u8 *key, unsigned int keylen);\n-\tint (*setauthsize)(void *tfm, unsigned int authsize);\n-\tint (*encrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);\n-\tint (*decrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);\n-\tunsigned int (*ivsize)(void *tfm);\n-\tunsigned int (*statesize)(void *tfm);\n-\tu32 (*get_flags)(void *tfm);\n-\tstruct module *owner;\n-\tchar name[14];\n-};\n-\n-int bpf_crypto_register_type(const struct bpf_crypto_type *type);\n-int bpf_crypto_unregister_type(const struct bpf_crypto_type *type);\n-\n-#endif /* _BPF_CRYPTO_H */\ndiff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig\nindex d7d25477ef481..98493e32db2ad 100644\n--- a/kernel/bpf/Kconfig\n+++ b/kernel/bpf/Kconfig\n@@ -91,6 +91,15 @@ config BPF_UNPRIV_DEFAULT_OFF\n \n \t If you are unsure how to answer this question, answer Y.\n \n+config BPF_CRYPTO\n+\tdef_bool y\n+\tdepends on BPF_SYSCALL\n+\tselect CRYPTO_LIB_AES_CBC\n+\tselect CRYPTO_LIB_AES_ECB\n+\thelp\n+\t Provide the kfuncs needed for BPF programs to encrypt and decrypt\n+\t data. The supported algorithms are AES-CBC and AES-ECB.\n+\n source \"kernel/bpf/preload/Kconfig\"\n \n config BPF_LSM\ndiff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile\nindex 9a92c348bbda6..c1f9b0d3468d3 100644\n--- a/kernel/bpf/Makefile\n+++ b/kernel/bpf/Makefile\n@@ -58,9 +58,7 @@ obj-$(CONFIG_BPF_SYSCALL) += cpumask.o\n # semantics within pahole are revisited accordingly.\n obj-${CONFIG_BPF_LSM} += bpf_lsm_proto.o bpf_lsm.o\n endif\n-ifneq ($(CONFIG_CRYPTO),)\n-obj-$(CONFIG_BPF_SYSCALL) += crypto.o\n-endif\n+obj-$(CONFIG_BPF_CRYPTO) += crypto.o\n obj-$(CONFIG_BPF_PRELOAD) += preload/\n \n obj-$(CONFIG_BPF_SYSCALL) += relo_core.o\ndiff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c\nindex 3f3fe2450fc6c..69bc29d0a4d4d 100644\n--- a/kernel/bpf/crypto.c\n+++ b/kernel/bpf/crypto.c\n@@ -1,19 +1,13 @@\n // SPDX-License-Identifier: GPL-2.0-only\n /* Copyright (c) 2024 Meta, Inc */\n #include \u003clinux/bpf.h\u003e\n-#include \u003clinux/bpf_crypto.h\u003e\n #include \u003clinux/bpf_mem_alloc.h\u003e\n #include \u003clinux/btf.h\u003e\n #include \u003clinux/btf_ids.h\u003e\n #include \u003clinux/filter.h\u003e\n-#include \u003clinux/scatterlist.h\u003e\n #include \u003clinux/skbuff.h\u003e\n-#include \u003ccrypto/skcipher.h\u003e\n-\n-struct bpf_crypto_type_list {\n-\tconst struct bpf_crypto_type *type;\n-\tstruct list_head list;\n-};\n+#include \u003ccrypto/aes-cbc.h\u003e\n+#include \u003ccrypto/aes-ecb.h\u003e\n \n /* BPF crypto initialization parameters struct */\n /**\n@@ -36,94 +30,53 @@ struct bpf_crypto_params {\n \tu32 authsize;\n };\n \n-static LIST_HEAD(bpf_crypto_types);\n-static DECLARE_RWSEM(bpf_crypto_types_sem);\n+enum bpf_crypto_algo_id {\n+\tBPF_ALGO_AES_CBC,\n+\tBPF_ALGO_AES_ECB,\n+};\n+\n+static const struct {\n+\tconst char *type_name;\n+\tconst char *algo_name;\n+\tenum bpf_crypto_algo_id algo;\n+} bpf_crypto_algos[] = {\n+\t{ \"skcipher\", \"cbc(aes)\", BPF_ALGO_AES_CBC },\n+\t{ \"skcipher\", \"ecb(aes)\", BPF_ALGO_AES_ECB },\n+};\n+\n+static bool bpf_crypto_find_algo(const struct bpf_crypto_params *params,\n+\t\t\t\t enum bpf_crypto_algo_id *id_ret)\n+{\n+\tfor (size_t i = 0; i \u003c ARRAY_SIZE(bpf_crypto_algos); i++) {\n+\t\tif (strncmp(bpf_crypto_algos[i].type_name, params-\u003etype,\n+\t\t\t sizeof(params-\u003etype)) == 0 \u0026\u0026\n+\t\t strncmp(bpf_crypto_algos[i].algo_name, params-\u003ealgo,\n+\t\t\t sizeof(params-\u003ealgo)) == 0) {\n+\t\t\t*id_ret = bpf_crypto_algos[i].algo;\n+\t\t\treturn true;\n+\t\t}\n+\t}\n+\treturn false;\n+}\n \n /**\n * struct bpf_crypto_ctx - refcounted BPF crypto context structure\n- * @type:\tThe pointer to bpf crypto type\n- * @tfm:\tThe pointer to instance of crypto API struct.\n- * @siv_len: Size of IV and state storage for cipher\n+ * @key:\tThe crypto key\n+ * @algo:\tThe crypto algorithm ID\n * @rcu:\tThe RCU head used to free the crypto context with RCU safety.\n * @usage:\tObject reference counter. When the refcount goes to 0, the\n *\t\tmemory is released back to the BPF allocator, which provides\n *\t\tRCU safety.\n */\n struct bpf_crypto_ctx {\n-\tconst struct bpf_crypto_type *type;\n-\tvoid *tfm;\n-\tu32 siv_len;\n+\tunion {\n+\t\tstruct aes_key aes;\n+\t} key;\n+\tenum bpf_crypto_algo_id algo;\n \tstruct rcu_head rcu;\n \trefcount_t usage;\n };\n \n-int bpf_crypto_register_type(const struct bpf_crypto_type *type)\n-{\n-\tstruct bpf_crypto_type_list *node;\n-\tint err = -EBUSY;\n-\n-\tdown_write(\u0026bpf_crypto_types_sem);\n-\tlist_for_each_entry(node, \u0026bpf_crypto_types, list) {\n-\t\tif (!strcmp(node-\u003etype-\u003ename, type-\u003ename))\n-\t\t\tgoto unlock;\n-\t}\n-\n-\tnode = kmalloc_obj(*node);\n-\terr = -ENOMEM;\n-\tif (!node)\n-\t\tgoto unlock;\n-\n-\tnode-\u003etype = type;\n-\tlist_add(\u0026node-\u003elist, \u0026bpf_crypto_types);\n-\terr = 0;\n-\n-unlock:\n-\tup_write(\u0026bpf_crypto_types_sem);\n-\n-\treturn err;\n-}\n-EXPORT_SYMBOL_GPL(bpf_crypto_register_type);\n-\n-int bpf_crypto_unregister_type(const struct bpf_crypto_type *type)\n-{\n-\tstruct bpf_crypto_type_list *node;\n-\tint err = -ENOENT;\n-\n-\tdown_write(\u0026bpf_crypto_types_sem);\n-\tlist_for_each_entry(node, \u0026bpf_crypto_types, list) {\n-\t\tif (strcmp(node-\u003etype-\u003ename, type-\u003ename))\n-\t\t\tcontinue;\n-\n-\t\tlist_del(\u0026node-\u003elist);\n-\t\tkfree(node);\n-\t\terr = 0;\n-\t\tbreak;\n-\t}\n-\tup_write(\u0026bpf_crypto_types_sem);\n-\n-\treturn err;\n-}\n-EXPORT_SYMBOL_GPL(bpf_crypto_unregister_type);\n-\n-static const struct bpf_crypto_type *bpf_crypto_get_type(const char *name)\n-{\n-\tconst struct bpf_crypto_type *type = ERR_PTR(-ENOENT);\n-\tstruct bpf_crypto_type_list *node;\n-\n-\tdown_read(\u0026bpf_crypto_types_sem);\n-\tlist_for_each_entry(node, \u0026bpf_crypto_types, list) {\n-\t\tif (strcmp(node-\u003etype-\u003ename, name))\n-\t\t\tcontinue;\n-\n-\t\tif (try_module_get(node-\u003etype-\u003eowner))\n-\t\t\ttype = node-\u003etype;\n-\t\tbreak;\n-\t}\n-\tup_read(\u0026bpf_crypto_types_sem);\n-\n-\treturn type;\n-}\n-\n __bpf_kfunc_start_defs();\n \n /**\n@@ -132,93 +85,70 @@ __bpf_kfunc_start_defs();\n * Allocates a crypto context that can be used, acquired, and released by\n * a BPF program. The crypto context returned by this function must either\n * be embedded in a map as a kptr, or freed with bpf_crypto_ctx_release().\n- * As crypto API functions use GFP_KERNEL allocations, this function can\n- * only be used in sleepable BPF programs.\n+ * As this uses a GFP_KERNEL allocation, this function can only be used in\n+ * sleepable BPF programs.\n *\n * bpf_crypto_ctx_create() allocates memory for crypto context.\n * It may return NULL if no memory is available.\n * @params:\tpointer to struct bpf_crypto_params which contains all the\n *\t\tdetails needed to initialise crypto context.\n- * @params__sz:\tsize of steuct bpf_crypto_params usef by bpf program\n- * @err:\tinteger to store error code when NULL is returned.\n+ * @params__sz:\tsize of struct bpf_crypto_params used by bpf program\n+ * @err_ret:\tinteger to store error code when NULL is returned.\n */\n __bpf_kfunc struct bpf_crypto_ctx *\n bpf_crypto_ctx_create(const struct bpf_crypto_params *params, u32 params__sz,\n-\t\t int *err)\n+\t\t int *err_ret)\n {\n-\tconst struct bpf_crypto_type *type;\n \tstruct bpf_crypto_ctx *ctx;\n+\tint err;\n \n \tif (!params ||\n \t params__sz != sizeof(struct bpf_crypto_params) ||\n \t params-\u003ereserved[0] || params-\u003ereserved[1]) {\n-\t\t*err = -EINVAL;\n+\t\t*err_ret = -EINVAL;\n \t\treturn NULL;\n \t}\n \n-\ttype = bpf_crypto_get_type(params-\u003etype);\n-\tif (IS_ERR(type)) {\n-\t\t*err = PTR_ERR(type);\n-\t\treturn NULL;\n-\t}\n-\n-\tif (!type-\u003ehas_algo(params-\u003ealgo)) {\n-\t\t*err = -EOPNOTSUPP;\n-\t\tgoto err_module_put;\n-\t}\n-\n-\tif (!!params-\u003eauthsize ^ !!type-\u003esetauthsize) {\n-\t\t*err = -EOPNOTSUPP;\n-\t\tgoto err_module_put;\n-\t}\n-\n \tif (!params-\u003ekey_len || params-\u003ekey_len \u003e sizeof(params-\u003ekey)) {\n-\t\t*err = -EINVAL;\n-\t\tgoto err_module_put;\n+\t\t*err_ret = -EINVAL;\n+\t\treturn NULL;\n \t}\n \n \tctx = kzalloc_obj(*ctx);\n \tif (!ctx) {\n-\t\t*err = -ENOMEM;\n-\t\tgoto err_module_put;\n+\t\t*err_ret = -ENOMEM;\n+\t\treturn NULL;\n \t}\n \n-\tctx-\u003etype = type;\n-\tctx-\u003etfm = type-\u003ealloc_tfm(params-\u003ealgo);\n-\tif (IS_ERR(ctx-\u003etfm)) {\n-\t\t*err = PTR_ERR(ctx-\u003etfm);\n-\t\tgoto err_free_ctx;\n+\tif (!bpf_crypto_find_algo(params, \u0026ctx-\u003ealgo)) {\n+\t\terr = -EOPNOTSUPP;\n+\t\tgoto out;\n \t}\n \n-\tif (params-\u003eauthsize) {\n-\t\t*err = type-\u003esetauthsize(ctx-\u003etfm, params-\u003eauthsize);\n-\t\tif (*err)\n-\t\t\tgoto err_free_tfm;\n+\tswitch (ctx-\u003ealgo) {\n+\tcase BPF_ALGO_AES_CBC:\n+\tcase BPF_ALGO_AES_ECB:\n+\t\tif (params-\u003eauthsize)\n+\t\t\terr = -EOPNOTSUPP;\n+\t\telse\n+\t\t\terr = aes_preparekey(\u0026ctx-\u003ekey.aes, params-\u003ekey,\n+\t\t\t\t\t params-\u003ekey_len);\n+\t\tbreak;\n+\tdefault:\n+\t\tWARN_ON_ONCE(1);\n+\t\terr = -EOPNOTSUPP;\n+\t\tbreak;\n \t}\n \n-\t*err = type-\u003esetkey(ctx-\u003etfm, params-\u003ekey, params-\u003ekey_len);\n-\tif (*err)\n-\t\tgoto err_free_tfm;\n-\n-\tif (type-\u003eget_flags(ctx-\u003etfm) \u0026 CRYPTO_TFM_NEED_KEY) {\n-\t\t*err = -EINVAL;\n-\t\tgoto err_free_tfm;\n+out:\n+\tif (err) {\n+\t\tkfree_sensitive(ctx);\n+\t\t*err_ret = err;\n+\t\treturn NULL;\n \t}\n-\n-\tctx-\u003esiv_len = type-\u003eivsize(ctx-\u003etfm) + type-\u003estatesize(ctx-\u003etfm);\n-\n \trefcount_set(\u0026ctx-\u003eusage, 1);\n-\n+\t*err_ret = 0;\n \treturn ctx;\n-\n-err_free_tfm:\n-\ttype-\u003efree_tfm(ctx-\u003etfm);\n-err_free_ctx:\n-\tkfree(ctx);\n-err_module_put:\n-\tmodule_put(type-\u003eowner);\n-\n-\treturn NULL;\n }\n \n static void crypto_free_cb(struct rcu_head *head)\n@@ -226,9 +156,7 @@ static void crypto_free_cb(struct rcu_head *head)\n \tstruct bpf_crypto_ctx *ctx;\n \n \tctx = container_of(head, struct bpf_crypto_ctx, rcu);\n-\tctx-\u003etype-\u003efree_tfm(ctx-\u003etfm);\n-\tmodule_put(ctx-\u003etype-\u003eowner);\n-\tkfree(ctx);\n+\tkfree_sensitive(ctx);\n }\n \n /**\n@@ -268,27 +196,53 @@ __bpf_kfunc void bpf_crypto_ctx_release_dtor(void *ctx)\n }\n CFI_NOSEAL(bpf_crypto_ctx_release_dtor);\n \n+static int bpf_aes_cbc_crypt(u8 *dst, u32 dst_len, const u8 *src, u32 src_len,\n+\t\t\t u8 *iv, u32 iv_len,\n+\t\t\t const struct bpf_crypto_ctx *ctx, bool decrypt)\n+{\n+\tif (iv_len != AES_BLOCK_SIZE)\n+\t\treturn -EINVAL;\n+\tif (src_len % AES_BLOCK_SIZE || dst_len \u003c src_len)\n+\t\treturn -EINVAL;\n+\tif (decrypt)\n+\t\taes_cbc_decrypt(dst, src, src_len, iv, \u0026ctx-\u003ekey.aes);\n+\telse\n+\t\taes_cbc_encrypt(dst, src, src_len, iv, \u0026ctx-\u003ekey.aes);\n+\treturn 0;\n+}\n+\n+static int bpf_aes_ecb_crypt(u8 *dst, u32 dst_len, const u8 *src, u32 src_len,\n+\t\t\t u8 *iv, u32 iv_len,\n+\t\t\t const struct bpf_crypto_ctx *ctx, bool decrypt)\n+{\n+\tif (iv_len != 0)\n+\t\treturn -EINVAL;\n+\tif (src_len % AES_BLOCK_SIZE || dst_len \u003c src_len)\n+\t\treturn -EINVAL;\n+\tif (decrypt)\n+\t\taes_ecb_decrypt(dst, src, src_len, \u0026ctx-\u003ekey.aes);\n+\telse\n+\t\taes_ecb_encrypt(dst, src, src_len, \u0026ctx-\u003ekey.aes);\n+\treturn 0;\n+}\n+\n static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,\n \t\t\t const struct bpf_dynptr_kern *src,\n \t\t\t const struct bpf_dynptr_kern *dst,\n-\t\t\t const struct bpf_dynptr_kern *siv,\n+\t\t\t const struct bpf_dynptr_kern *iv,\n \t\t\t bool decrypt)\n {\n-\tu32 src_len, dst_len, siv_len;\n+\tu32 src_len, dst_len, iv_len;\n \tconst u8 *psrc;\n \tu8 *pdst, *piv;\n-\tint err;\n \n \tif (__bpf_dynptr_is_rdonly(dst))\n \t\treturn -EINVAL;\n \n-\tsiv_len = siv ? __bpf_dynptr_size(siv) : 0;\n+\tiv_len = iv ? __bpf_dynptr_size(iv) : 0;\n \tsrc_len = __bpf_dynptr_size(src);\n \tdst_len = __bpf_dynptr_size(dst);\n-\tif (!src_len || !dst_len || src_len \u003e dst_len)\n-\t\treturn -EINVAL;\n-\n-\tif (siv_len != ctx-\u003esiv_len)\n+\tif (!src_len || !dst_len)\n \t\treturn -EINVAL;\n \n \tpsrc = __bpf_dynptr_data(src, src_len);\n@@ -298,14 +252,20 @@ static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,\n \tif (!pdst)\n \t\treturn -EINVAL;\n \n-\tpiv = siv_len ? __bpf_dynptr_data_rw(siv, siv_len) : NULL;\n-\tif (siv_len \u0026\u0026 !piv)\n+\tpiv = iv_len ? __bpf_dynptr_data_rw(iv, iv_len) : NULL;\n+\tif (iv_len \u0026\u0026 !piv)\n \t\treturn -EINVAL;\n \n-\terr = decrypt ? ctx-\u003etype-\u003edecrypt(ctx-\u003etfm, psrc, pdst, src_len, piv)\n-\t\t : ctx-\u003etype-\u003eencrypt(ctx-\u003etfm, psrc, pdst, src_len, piv);\n-\n-\treturn err;\n+\tswitch (ctx-\u003ealgo) {\n+\tcase BPF_ALGO_AES_CBC:\n+\t\treturn bpf_aes_cbc_crypt(pdst, dst_len, psrc, src_len, piv,\n+\t\t\t\t\t iv_len, ctx, decrypt);\n+\tcase BPF_ALGO_AES_ECB:\n+\t\treturn bpf_aes_ecb_crypt(pdst, dst_len, psrc, src_len, piv,\n+\t\t\t\t\t iv_len, ctx, decrypt);\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n }\n \n /**\n@@ -313,20 +273,20 @@ static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,\n * @ctx:\t\tThe crypto context being used. The ctx must be a trusted pointer.\n * @src:\t\tbpf_dynptr to the encrypted data. Must be a trusted pointer.\n * @dst:\t\tbpf_dynptr to the buffer where to store the result. Must be a trusted pointer.\n- * @siv__nullable:\tbpf_dynptr to IV data and state data to be used by decryptor. May be NULL.\n+ * @iv__nullable:\tbpf_dynptr to the initialization vector. May be NULL.\n *\n * Decrypts provided buffer using IV data and the crypto context. Crypto context must be configured.\n */\n __bpf_kfunc int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx,\n \t\t\t\t const struct bpf_dynptr *src,\n \t\t\t\t const struct bpf_dynptr *dst,\n-\t\t\t\t const struct bpf_dynptr *siv__nullable)\n+\t\t\t\t const struct bpf_dynptr *iv__nullable)\n {\n \tconst struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;\n \tconst struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;\n-\tconst struct bpf_dynptr_kern *siv_kern = (struct bpf_dynptr_kern *)siv__nullable;\n+\tconst struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;\n \n-\treturn bpf_crypto_crypt(ctx, src_kern, dst_kern, siv_kern, true);\n+\treturn bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, true);\n }\n \n /**\n@@ -334,20 +294,20 @@ __bpf_kfunc int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx,\n * @ctx:\t\tThe crypto context being used. The ctx must be a trusted pointer.\n * @src:\t\tbpf_dynptr to the plain data. Must be a trusted pointer.\n * @dst:\t\tbpf_dynptr to the buffer where to store the result. Must be a trusted pointer.\n- * @siv__nullable:\tbpf_dynptr to IV data and state data to be used by decryptor. May be NULL.\n+ * @iv__nullable:\tbpf_dynptr to the initialization vector. May be NULL.\n *\n * Encrypts provided buffer using IV data and the crypto context. Crypto context must be configured.\n */\n __bpf_kfunc int bpf_crypto_encrypt(struct bpf_crypto_ctx *ctx,\n \t\t\t\t const struct bpf_dynptr *src,\n \t\t\t\t const struct bpf_dynptr *dst,\n-\t\t\t\t const struct bpf_dynptr *siv__nullable)\n+\t\t\t\t const struct bpf_dynptr *iv__nullable)\n {\n \tconst struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;\n \tconst struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;\n-\tconst struct bpf_dynptr_kern *siv_kern = (struct bpf_dynptr_kern *)siv__nullable;\n+\tconst struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;\n \n-\treturn bpf_crypto_crypt(ctx, src_kern, dst_kern, siv_kern, false);\n+\treturn bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, false);\n }\n \n __bpf_kfunc_end_defs();\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 865b6c6eb8dd7..4077c88d95252 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -4742,7 +4742,7 @@ BTF_ID(struct, cgroup)\n BTF_ID(struct, bpf_cpumask)\n #endif\n BTF_ID(struct, task_struct)\n-#ifdef CONFIG_CRYPTO\n+#ifdef CONFIG_BPF_CRYPTO\n BTF_ID(struct, bpf_crypto_ctx)\n #endif\n #ifdef CONFIG_INET\ndiff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config\nindex d292cb60a5a4e..2b883b388f90c 100644\n--- a/tools/testing/selftests/bpf/config\n+++ b/tools/testing/selftests/bpf/config\n@@ -18,7 +18,7 @@ CONFIG_CRYPTO_SHA512=y\n CONFIG_CRYPTO_USER_API=y\n CONFIG_CRYPTO_USER_API_HASH=y\n CONFIG_CRYPTO_USER_API_SKCIPHER=y\n-CONFIG_CRYPTO_SKCIPHER=y\n+CONFIG_CRYPTO_CBC=y\n CONFIG_CRYPTO_ECB=y\n CONFIG_CRYPTO_AES=y\n CONFIG_DEBUG_INFO=y\n"
} |
| 2/1 | 2026/09/27 00:15 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_CRYPTO"
],
"FocusSymbols": [
"bpf_crypto_ctx_create",
"bpf_crypto_encrypt",
"bpf_crypto_decrypt",
"bpf_crypto_crypt",
"bpf_aes_cbc_crypt",
"bpf_aes_ecb_crypt"
],
"Reasoning": "The patch refactors the BPF crypto subsystem to directly use AES library functions (AES-CBC and AES-ECB) rather than the generic crypto skcipher API, adding new validation logic, direct key setup, encryption/decryption helpers, and a new WARN_ON_ONCE assertion. These changes modify reachable BPF kfuncs executable via standard BPF syscall programs and warrant fuzzing.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit c80e54e97a241421dbaaa989b63fd2cee65db73f
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 27 00:15:27 2026 +0000
syz-cluster: applied patch under review
diff --git a/MAINTAINERS b/MAINTAINERS
index 140eafcbbd782..cf806c2b788e3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4936,8 +4936,6 @@ BPF [CRYPTO]
M: Vadim Fedorenko <vadim.fedorenko@linux.dev>
L: bpf@vger.kernel.org
S: Maintained
-F: crypto/bpf_crypto_skcipher.c
-F: include/linux/bpf_crypto.h
F: kernel/bpf/crypto.c
BPF [DOCUMENTATION] (Related to Standardization)
diff --git a/crypto/Makefile b/crypto/Makefile
index 8386d55a9755e..33bb5ad595e8f 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -22,9 +22,6 @@ crypto_skcipher-y += lskcipher.o
crypto_skcipher-y += skcipher.o
obj-$(CONFIG_CRYPTO_SKCIPHER2) += crypto_skcipher.o
-ifeq ($(CONFIG_BPF_SYSCALL),y)
-obj-$(CONFIG_CRYPTO_SKCIPHER2) += bpf_crypto_skcipher.o
-endif
obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o
diff --git a/crypto/bpf_crypto_skcipher.c b/crypto/bpf_crypto_skcipher.c
deleted file mode 100644
index a88798d3e8c87..0000000000000
--- a/crypto/bpf_crypto_skcipher.c
+++ /dev/null
@@ -1,83 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/* Copyright (c) 2024 Meta, Inc */
-#include <linux/types.h>
-#include <linux/module.h>
-#include <linux/bpf_crypto.h>
-#include <crypto/skcipher.h>
-
-static void *bpf_crypto_lskcipher_alloc_tfm(const char *algo)
-{
- return crypto_alloc_lskcipher(algo, 0, 0);
-}
-
-static void bpf_crypto_lskcipher_free_tfm(void *tfm)
-{
- crypto_free_lskcipher(tfm);
-}
-
-static int bpf_crypto_lskcipher_has_algo(const char *algo)
-{
- return crypto_has_skcipher(algo, CRYPTO_ALG_TYPE_LSKCIPHER, CRYPTO_ALG_TYPE_MASK);
-}
-
-static int bpf_crypto_lskcipher_setkey(void *tfm, const u8 *key, unsigned int keylen)
-{
- return crypto_lskcipher_setkey(tfm, key, keylen);
-}
-
-static u32 bpf_crypto_lskcipher_get_flags(void *tfm)
-{
- return crypto_lskcipher_get_flags(tfm);
-}
-
-static unsigned int bpf_crypto_lskcipher_ivsize(void *tfm)
-{
- return crypto_lskcipher_ivsize(tfm);
-}
-
-static unsigned int bpf_crypto_lskcipher_statesize(void *tfm)
-{
- return crypto_lskcipher_statesize(tfm);
-}
-
-static int bpf_crypto_lskcipher_encrypt(void *tfm, const u8 *src, u8 *dst,
- unsigned int len, u8 *siv)
-{
- return crypto_lskcipher_encrypt(tfm, src, dst, len, siv);
-}
-
-static int bpf_crypto_lskcipher_decrypt(void *tfm, const u8 *src, u8 *dst,
- unsigned int len, u8 *siv)
-{
- return crypto_lskcipher_decrypt(tfm, src, dst, len, siv);
-}
-
-static const struct bpf_crypto_type bpf_crypto_lskcipher_type = {
- .alloc_tfm = bpf_crypto_lskcipher_alloc_tfm,
- .free_tfm = bpf_crypto_lskcipher_free_tfm,
- .has_algo = bpf_crypto_lskcipher_has_algo,
- .setkey = bpf_crypto_lskcipher_setkey,
- .encrypt = bpf_crypto_lskcipher_encrypt,
- .decrypt = bpf_crypto_lskcipher_decrypt,
- .ivsize = bpf_crypto_lskcipher_ivsize,
- .statesize = bpf_crypto_lskcipher_statesize,
- .get_flags = bpf_crypto_lskcipher_get_flags,
- .owner = THIS_MODULE,
- .name = "skcipher",
-};
-
-static int __init bpf_crypto_skcipher_init(void)
-{
- return bpf_crypto_register_type(&bpf_crypto_lskcipher_type);
-}
-
-static void __exit bpf_crypto_skcipher_exit(void)
-{
- int err = bpf_crypto_unregister_type(&bpf_crypto_lskcipher_type);
- WARN_ON_ONCE(err);
-}
-
-module_init(bpf_crypto_skcipher_init);
-module_exit(bpf_crypto_skcipher_exit);
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Symmetric key cipher support for BPF");
diff --git a/include/linux/bpf_crypto.h b/include/linux/bpf_crypto.h
deleted file mode 100644
index a41e71d4e2d9f..0000000000000
--- a/include/linux/bpf_crypto.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
-#ifndef _BPF_CRYPTO_H
-#define _BPF_CRYPTO_H
-
-struct bpf_crypto_type {
- void *(*alloc_tfm)(const char *algo);
- void (*free_tfm)(void *tfm);
- int (*has_algo)(const char *algo);
- int (*setkey)(void *tfm, const u8 *key, unsigned int keylen);
- int (*setauthsize)(void *tfm, unsigned int authsize);
- int (*encrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);
- int (*decrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);
- unsigned int (*ivsize)(void *tfm);
- unsigned int (*statesize)(void *tfm);
- u32 (*get_flags)(void *tfm);
- struct module *owner;
- char name[14];
-};
-
-int bpf_crypto_register_type(const struct bpf_crypto_type *type);
-int bpf_crypto_unregister_type(const struct bpf_crypto_type *type);
-
-#endif /* _BPF_CRYPTO_H */
diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig
index d7d25477ef481..98493e32db2ad 100644
--- a/kernel/bpf/Kconfig
+++ b/kernel/bpf/Kconfig
@@ -91,6 +91,15 @@ config BPF_UNPRIV_DEFAULT_OFF
If you are unsure how to answer this question, answer Y.
+config BPF_CRYPTO
+ def_bool y
+ depends on BPF_SYSCALL
+ select CRYPTO_LIB_AES_CBC
+ select CRYPTO_LIB_AES_ECB
+ help
+ Provide the kfuncs needed for BPF programs to encrypt and decrypt
+ data. The supported algorithms are AES-CBC and AES-ECB.
+
source "kernel/bpf/preload/Kconfig"
config BPF_LSM
diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index 9a92c348bbda6..c1f9b0d3468d3 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -58,9 +58,7 @@ obj-$(CONFIG_BPF_SYSCALL) += cpumask.o
# semantics within pahole are revisited accordingly.
obj-${CONFIG_BPF_LSM} += bpf_lsm_proto.o bpf_lsm.o
endif
-ifneq ($(CONFIG_CRYPTO),)
-obj-$(CONFIG_BPF_SYSCALL) += crypto.o
-endif
+obj-$(CONFIG_BPF_CRYPTO) += crypto.o
obj-$(CONFIG_BPF_PRELOAD) += preload/
obj-$(CONFIG_BPF_SYSCALL) += relo_core.o
diff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c
index 3f3fe2450fc6c..69bc29d0a4d4d 100644
--- a/kernel/bpf/crypto.c
+++ b/kernel/bpf/crypto.c
@@ -1,19 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2024 Meta, Inc */
#include <linux/bpf.h>
-#include <linux/bpf_crypto.h>
#include <linux/bpf_mem_alloc.h>
#include <linux/btf.h>
#include <linux/btf_ids.h>
#include <linux/filter.h>
-#include <linux/scatterlist.h>
#include <linux/skbuff.h>
-#include <crypto/skcipher.h>
-
-struct bpf_crypto_type_list {
- const struct bpf_crypto_type *type;
- struct list_head list;
-};
+#include <crypto/aes-cbc.h>
+#include <crypto/aes-ecb.h>
/* BPF crypto initialization parameters struct */
/**
@@ -36,94 +30,53 @@ struct bpf_crypto_params {
u32 authsize;
};
-static LIST_HEAD(bpf_crypto_types);
-static DECLARE_RWSEM(bpf_crypto_types_sem);
+enum bpf_crypto_algo_id {
+ BPF_ALGO_AES_CBC,
+ BPF_ALGO_AES_ECB,
+};
+
+static const struct {
+ const char *type_name;
+ const char *algo_name;
+ enum bpf_crypto_algo_id algo;
+} bpf_crypto_algos[] = {
+ { "skcipher", "cbc(aes)", BPF_ALGO_AES_CBC },
+ { "skcipher", "ecb(aes)", BPF_ALGO_AES_ECB },
+};
+
+static bool bpf_crypto_find_algo(const struct bpf_crypto_params *params,
+ enum bpf_crypto_algo_id *id_ret)
+{
+ for (size_t i = 0; i < ARRAY_SIZE(bpf_crypto_algos); i++) {
+ if (strncmp(bpf_crypto_algos[i].type_name, params->type,
+ sizeof(params->type)) == 0 &&
+ strncmp(bpf_crypto_algos[i].algo_name, params->algo,
+ sizeof(params->algo)) == 0) {
+ *id_ret = bpf_crypto_algos[i].algo;
+ return true;
+ }
+ }
+ return false;
+}
/**
* struct bpf_crypto_ctx - refcounted BPF crypto context structure
- * @type: The pointer to bpf crypto type
- * @tfm: The pointer to instance of crypto API struct.
- * @siv_len: Size of IV and state storage for cipher
+ * @key: The crypto key
+ * @algo: The crypto algorithm ID
* @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 {
- const struct bpf_crypto_type *type;
- void *tfm;
- u32 siv_len;
+ union {
+ struct aes_key aes;
+ } key;
+ enum bpf_crypto_algo_id algo;
struct rcu_head rcu;
refcount_t usage;
};
-int bpf_crypto_register_type(const struct bpf_crypto_type *type)
-{
- struct bpf_crypto_type_list *node;
- int err = -EBUSY;
-
- down_write(&bpf_crypto_types_sem);
- list_for_each_entry(node, &bpf_crypto_types, list) {
- if (!strcmp(node->type->name, type->name))
- goto unlock;
- }
-
- node = kmalloc_obj(*node);
- err = -ENOMEM;
- if (!node)
- goto unlock;
-
- node->type = type;
- list_add(&node->list, &bpf_crypto_types);
- err = 0;
-
-unlock:
- up_write(&bpf_crypto_types_sem);
-
- return err;
-}
-EXPORT_SYMBOL_GPL(bpf_crypto_register_type);
-
-int bpf_crypto_unregister_type(const struct bpf_crypto_type *type)
-{
- struct bpf_crypto_type_list *node;
- int err = -ENOENT;
-
- down_write(&bpf_crypto_types_sem);
- list_for_each_entry(node, &bpf_crypto_types, list) {
- if (strcmp(node->type->name, type->name))
- continue;
-
- list_del(&node->list);
- kfree(node);
- err = 0;
- break;
- }
- up_write(&bpf_crypto_types_sem);
-
- return err;
-}
-EXPORT_SYMBOL_GPL(bpf_crypto_unregister_type);
-
-static const struct bpf_crypto_type *bpf_crypto_get_type(const char *name)
-{
- const struct bpf_crypto_type *type = ERR_PTR(-ENOENT);
- struct bpf_crypto_type_list *node;
-
- down_read(&bpf_crypto_types_sem);
- list_for_each_entry(node, &bpf_crypto_types, list) {
- if (strcmp(node->type->name, name))
- continue;
-
- if (try_module_get(node->type->owner))
- type = node->type;
- break;
- }
- up_read(&bpf_crypto_types_sem);
-
- return type;
-}
-
__bpf_kfunc_start_defs();
/**
@@ -132,93 +85,70 @@ __bpf_kfunc_start_defs();
* Allocates a crypto context that can be used, acquired, and released by
* a BPF program. The crypto context returned by this function must either
* be embedded in a map as a kptr, or freed with bpf_crypto_ctx_release().
- * As crypto API functions use GFP_KERNEL allocations, this function can
- * only be used in sleepable BPF programs.
+ * As this uses a GFP_KERNEL allocation, this function can only be used in
+ * sleepable BPF programs.
*
* bpf_crypto_ctx_create() allocates memory for crypto context.
* It may return NULL if no memory is available.
* @params: pointer to struct bpf_crypto_params which contains all the
* details needed to initialise crypto context.
- * @params__sz: size of steuct bpf_crypto_params usef by bpf program
- * @err: integer to store error code when NULL is returned.
+ * @params__sz: size of struct bpf_crypto_params used by bpf program
+ * @err_ret: integer to store error code when NULL is returned.
*/
__bpf_kfunc struct bpf_crypto_ctx *
bpf_crypto_ctx_create(const struct bpf_crypto_params *params, u32 params__sz,
- int *err)
+ int *err_ret)
{
- const struct bpf_crypto_type *type;
struct bpf_crypto_ctx *ctx;
+ int err;
if (!params ||
params__sz != sizeof(struct bpf_crypto_params) ||
params->reserved[0] || params->reserved[1]) {
- *err = -EINVAL;
+ *err_ret = -EINVAL;
return NULL;
}
- type = bpf_crypto_get_type(params->type);
- if (IS_ERR(type)) {
- *err = PTR_ERR(type);
- return NULL;
- }
-
- if (!type->has_algo(params->algo)) {
- *err = -EOPNOTSUPP;
- goto err_module_put;
- }
-
- if (!!params->authsize ^ !!type->setauthsize) {
- *err = -EOPNOTSUPP;
- goto err_module_put;
- }
-
if (!params->key_len || params->key_len > sizeof(params->key)) {
- *err = -EINVAL;
- goto err_module_put;
+ *err_ret = -EINVAL;
+ return NULL;
}
ctx = kzalloc_obj(*ctx);
if (!ctx) {
- *err = -ENOMEM;
- goto err_module_put;
+ *err_ret = -ENOMEM;
+ return NULL;
}
- ctx->type = type;
- ctx->tfm = type->alloc_tfm(params->algo);
- if (IS_ERR(ctx->tfm)) {
- *err = PTR_ERR(ctx->tfm);
- goto err_free_ctx;
+ if (!bpf_crypto_find_algo(params, &ctx->algo)) {
+ err = -EOPNOTSUPP;
+ goto out;
}
- if (params->authsize) {
- *err = type->setauthsize(ctx->tfm, params->authsize);
- if (*err)
- goto err_free_tfm;
+ switch (ctx->algo) {
+ case BPF_ALGO_AES_CBC:
+ case BPF_ALGO_AES_ECB:
+ if (params->authsize)
+ err = -EOPNOTSUPP;
+ else
+ err = aes_preparekey(&ctx->key.aes, params->key,
+ params->key_len);
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ err = -EOPNOTSUPP;
+ break;
}
- *err = type->setkey(ctx->tfm, params->key, params->key_len);
- if (*err)
- goto err_free_tfm;
-
- if (type->get_flags(ctx->tfm) & CRYPTO_TFM_NEED_KEY) {
- *err = -EINVAL;
- goto err_free_tfm;
+out:
+ if (err) {
+ kfree_sensitive(ctx);
+ *err_ret = err;
+ return NULL;
}
-
- ctx->siv_len = type->ivsize(ctx->tfm) + type->statesize(ctx->tfm);
-
refcount_set(&ctx->usage, 1);
-
+ *err_ret = 0;
return ctx;
-
-err_free_tfm:
- type->free_tfm(ctx->tfm);
-err_free_ctx:
- kfree(ctx);
-err_module_put:
- module_put(type->owner);
-
- return NULL;
}
static void crypto_free_cb(struct rcu_head *head)
@@ -226,9 +156,7 @@ static void crypto_free_cb(struct rcu_head *head)
struct bpf_crypto_ctx *ctx;
ctx = container_of(head, struct bpf_crypto_ctx, rcu);
- ctx->type->free_tfm(ctx->tfm);
- module_put(ctx->type->owner);
- kfree(ctx);
+ kfree_sensitive(ctx);
}
/**
@@ -268,27 +196,53 @@ __bpf_kfunc void bpf_crypto_ctx_release_dtor(void *ctx)
}
CFI_NOSEAL(bpf_crypto_ctx_release_dtor);
+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;
+}
+
static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr_kern *src,
const struct bpf_dynptr_kern *dst,
- const struct bpf_dynptr_kern *siv,
+ const struct bpf_dynptr_kern *iv,
bool decrypt)
{
- u32 src_len, dst_len, siv_len;
+ u32 src_len, dst_len, iv_len;
const u8 *psrc;
u8 *pdst, *piv;
- int err;
if (__bpf_dynptr_is_rdonly(dst))
return -EINVAL;
- siv_len = siv ? __bpf_dynptr_size(siv) : 0;
+ iv_len = iv ? __bpf_dynptr_size(iv) : 0;
src_len = __bpf_dynptr_size(src);
dst_len = __bpf_dynptr_size(dst);
- if (!src_len || !dst_len || src_len > dst_len)
- return -EINVAL;
-
- if (siv_len != ctx->siv_len)
+ if (!src_len || !dst_len)
return -EINVAL;
psrc = __bpf_dynptr_data(src, src_len);
@@ -298,14 +252,20 @@ static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
if (!pdst)
return -EINVAL;
- piv = siv_len ? __bpf_dynptr_data_rw(siv, siv_len) : NULL;
- if (siv_len && !piv)
+ piv = iv_len ? __bpf_dynptr_data_rw(iv, iv_len) : NULL;
+ if (iv_len && !piv)
return -EINVAL;
- err = decrypt ? ctx->type->decrypt(ctx->tfm, psrc, pdst, src_len, piv)
- : ctx->type->encrypt(ctx->tfm, psrc, pdst, src_len, piv);
-
- return err;
+ switch (ctx->algo) {
+ case BPF_ALGO_AES_CBC:
+ return bpf_aes_cbc_crypt(pdst, dst_len, psrc, src_len, piv,
+ iv_len, ctx, decrypt);
+ case BPF_ALGO_AES_ECB:
+ return bpf_aes_ecb_crypt(pdst, dst_len, psrc, src_len, piv,
+ iv_len, ctx, decrypt);
+ default:
+ return -EINVAL;
+ }
}
/**
@@ -313,20 +273,20 @@ static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
* @ctx: The crypto context being used. The ctx must be a trusted pointer.
* @src: bpf_dynptr to the encrypted data. Must be a trusted pointer.
* @dst: bpf_dynptr to the buffer where to store the result. Must be a trusted pointer.
- * @siv__nullable: bpf_dynptr to IV data and state data to be used by decryptor. May be NULL.
+ * @iv__nullable: bpf_dynptr to the initialization vector. May be NULL.
*
* Decrypts provided buffer using IV data and the crypto context. Crypto context must be configured.
*/
__bpf_kfunc int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr *src,
const struct bpf_dynptr *dst,
- const struct bpf_dynptr *siv__nullable)
+ const struct bpf_dynptr *iv__nullable)
{
const struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;
const struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;
- const struct bpf_dynptr_kern *siv_kern = (struct bpf_dynptr_kern *)siv__nullable;
+ const struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;
- return bpf_crypto_crypt(ctx, src_kern, dst_kern, siv_kern, true);
+ return bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, true);
}
/**
@@ -334,20 +294,20 @@ __bpf_kfunc int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx,
* @ctx: The crypto context being used. The ctx must be a trusted pointer.
* @src: bpf_dynptr to the plain data. Must be a trusted pointer.
* @dst: bpf_dynptr to the buffer where to store the result. Must be a trusted pointer.
- * @siv__nullable: bpf_dynptr to IV data and state data to be used by decryptor. May be NULL.
+ * @iv__nullable: bpf_dynptr to the initialization vector. May be NULL.
*
* Encrypts provided buffer using IV data and the crypto context. Crypto context must be configured.
*/
__bpf_kfunc int bpf_crypto_encrypt(struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr *src,
const struct bpf_dynptr *dst,
- const struct bpf_dynptr *siv__nullable)
+ const struct bpf_dynptr *iv__nullable)
{
const struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;
const struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;
- const struct bpf_dynptr_kern *siv_kern = (struct bpf_dynptr_kern *)siv__nullable;
+ const struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;
- return bpf_crypto_crypt(ctx, src_kern, dst_kern, siv_kern, false);
+ return bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, false);
}
__bpf_kfunc_end_defs();
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 865b6c6eb8dd7..4077c88d95252 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -4742,7 +4742,7 @@ BTF_ID(struct, cgroup)
BTF_ID(struct, bpf_cpumask)
#endif
BTF_ID(struct, task_struct)
-#ifdef CONFIG_CRYPTO
+#ifdef CONFIG_BPF_CRYPTO
BTF_ID(struct, bpf_crypto_ctx)
#endif
#ifdef CONFIG_INET
diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index d292cb60a5a4e..2b883b388f90c 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -18,7 +18,7 @@ CONFIG_CRYPTO_SHA512=y
CONFIG_CRYPTO_USER_API=y
CONFIG_CRYPTO_USER_API_HASH=y
CONFIG_CRYPTO_USER_API_SKCIPHER=y
-CONFIG_CRYPTO_SKCIPHER=y
+CONFIG_CRYPTO_CBC=y
CONFIG_CRYPTO_ECB=y
CONFIG_CRYPTO_AES=y
CONFIG_DEBUG_INFO=y
|
| 3/2 | 2026/09/27 00:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 10637 output: 31 thoughts: 591 Thoughts: **Analyzing the BPF Crypto Patch** Okay, let's dive into this patch and dissect the modifications. My initial assessment is that this is a significant refactor of the BPF crypto functionality. The patch touches several files, starting with the `MAINTAINERS` file, which is always a good sign. It signals that changes are being made to a well-defined subsystem. The most substantial changes seem to be concentrated in the `crypto/` and `kernel/bpf/` directories. Specifically, the patch deletes `bpf_crypto_skcipher.c` and `include/linux/bpf_crypto.h`, suggesting a removal of the skcipher abstraction, and removes the dynamic cipher lookup. The inclusion of `config BPF_CRYPTO` in `kernel/bpf/Kconfig` is critical, this indicates a new configuration option. The `kernel/bpf/Makefile` is updated to account for the new configuration directive. The core of the change appears to be in `kernel/bpf/crypto.c`. Here, the patch replaces the existing crypto API and `skcipher` abstraction with direct calls to AES primitives from `crypto/aes-cbc.h` and `crypto/aes-ecb.h`. This is a pretty major shift, moving away from a more generic interface towards hardcoded AES-CBC and AES-ECB implementations. They've also simplified the `bpf_crypto_ctx` structure and eliminated the registration/unregistration mechanism (`bpf_crypto_register_type`, `bpf_crypto_unregister_type`), and added helper functions. The change in `kernel/bpf/verifier.c` to use `#ifdef CONFIG_BPF_CRYPTO` instead of `#ifdef CONFIG_CRYPTO` for `BTF_ID(struct, bpf_crypto_ctx)` is a simple adaptation, reflecting the configuration change. Now, considering the location and modifications, this code impacts BPF, which is explicitly listed as a core subsystem. The reachability seems clear, the BPF crypto kfuncs (`bpf_crypto_ctx_create`, etc.) can be called by BPF programs loaded through the `bpf()` syscall and is fuzzed by syzkaller. I'll now need to go into a detailed inspection of `kernel/bpf/crypto.c`, to check how the kfuncs are used. I will use tools such as `grepper` or `read-file` to check the code. |
| 4/2 | 2026/09/27 00:15 | tool | grepper |
0mError:no matches Args: {
"Expression": "bpf_crypto_init",
"PathPrefix": "kernel/bpf/"
}Results: {
"error": "no matches"
} |
| 5/2 | 2026/09/27 00:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11795 output: 36 thoughts: 29 Thoughts: Okay, let's dive into the core of this `crypto.c` BPF implementation. I need to get a comprehensive understanding of the remaining code, specifically from line 300 to the end of the file. I want to build a mental map of what's happening beyond this line number. I'll read through the rest of the file to see how it fits into the broader picture and identify the overall patterns that emerge. |
| 6/2 | 2026/09/27 00:15 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/crypto.c",
"FirstLine": 295,
"LineCount": 80
}Results: {
"Contents": " 295:\t * @src:\t\tbpf_dynptr to the plain data. Must be a trusted pointer.\n 296:\t * @dst:\t\tbpf_dynptr to the buffer where to store the result. Must be a trusted pointer.\n 297:\t * @iv__nullable:\tbpf_dynptr to the initialization vector. May be NULL.\n 298:\t *\n 299:\t * Encrypts provided buffer using IV data and the crypto context. Crypto context must be configured.\n 300:\t */\n 301:\t__bpf_kfunc int bpf_crypto_encrypt(struct bpf_crypto_ctx *ctx,\n 302:\t\t\t\t\t const struct bpf_dynptr *src,\n 303:\t\t\t\t\t const struct bpf_dynptr *dst,\n 304:\t\t\t\t\t const struct bpf_dynptr *iv__nullable)\n 305:\t{\n 306:\t\tconst struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;\n 307:\t\tconst struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;\n 308:\t\tconst struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;\n 309:\t\n 310:\t\treturn bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, false);\n 311:\t}\n 312:\t\n 313:\t__bpf_kfunc_end_defs();\n 314:\t\n 315:\tBTF_KFUNCS_START(crypt_init_kfunc_btf_ids)\n 316:\tBTF_ID_FLAGS(func, bpf_crypto_ctx_create, KF_ACQUIRE | KF_RET_NULL | KF_SLEEPABLE)\n 317:\tBTF_ID_FLAGS(func, bpf_crypto_ctx_release, KF_RELEASE)\n 318:\tBTF_ID_FLAGS(func, bpf_crypto_ctx_acquire, KF_ACQUIRE | KF_RCU | KF_RET_NULL)\n 319:\tBTF_KFUNCS_END(crypt_init_kfunc_btf_ids)\n 320:\t\n 321:\tstatic const struct btf_kfunc_id_set crypt_init_kfunc_set = {\n 322:\t\t.owner = THIS_MODULE,\n 323:\t\t.set = \u0026crypt_init_kfunc_btf_ids,\n 324:\t};\n 325:\t\n 326:\tBTF_KFUNCS_START(crypt_kfunc_btf_ids)\n 327:\tBTF_ID_FLAGS(func, bpf_crypto_decrypt, KF_RCU)\n 328:\tBTF_ID_FLAGS(func, bpf_crypto_encrypt, KF_RCU)\n 329:\tBTF_KFUNCS_END(crypt_kfunc_btf_ids)\n 330:\t\n 331:\tstatic const struct btf_kfunc_id_set crypt_kfunc_set = {\n 332:\t\t.owner = THIS_MODULE,\n 333:\t\t.set = \u0026crypt_kfunc_btf_ids,\n 334:\t};\n 335:\t\n 336:\tBTF_ID_LIST(bpf_crypto_dtor_ids)\n 337:\tBTF_ID(struct, bpf_crypto_ctx)\n 338:\tBTF_ID(func, bpf_crypto_ctx_release_dtor)\n 339:\t\n 340:\tstatic int __init crypto_kfunc_init(void)\n 341:\t{\n 342:\t\tint ret;\n 343:\t\tconst struct btf_id_dtor_kfunc bpf_crypto_dtors[] = {\n 344:\t\t\t{\n 345:\t\t\t\t.btf_id\t = bpf_crypto_dtor_ids[0],\n 346:\t\t\t\t.kfunc_btf_id = bpf_crypto_dtor_ids[1]\n 347:\t\t\t},\n 348:\t\t};\n 349:\t\n 350:\t\tret = register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, \u0026crypt_kfunc_set);\n 351:\t\tret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_ACT, \u0026crypt_kfunc_set);\n 352:\t\tret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, \u0026crypt_kfunc_set);\n 353:\t\tret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL,\n 354:\t\t\t\t\t\t \u0026crypt_init_kfunc_set);\n 355:\t\treturn ret ?: register_btf_id_dtor_kfuncs(bpf_crypto_dtors,\n 356:\t\t\t\t\t\t\t ARRAY_SIZE(bpf_crypto_dtors),\n 357:\t\t\t\t\t\t\t THIS_MODULE);\n 358:\t}\n 359:\t\n 360:\tlate_initcall(crypto_kfunc_init);\n"
} |
| 7/2 | 2026/09/27 00:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13331 output: 34 thoughts: 1201 Thoughts: **Analyzing the BPF Crypto Changes** Okay, let's break down these BPF crypto changes. First, it looks like `late_initcall(crypto_kfunc_init)` is registering the kfuncs. This is being used for different BPF program types like sched, XDP, and syscall. Interesting. Now, focusing on `crypto.c`, there's a significant shift. The old `bpf_crypto_find_algo` is gone. Instead, there's a new algorithm lookup that directly matches `params->type` (which is "skcipher") with specific algorithms like "cbc(aes)" or "ecb(aes)". This is a pretty big simplification, removing the need for the more generic dynamic type lookups. `bpf_crypto_ctx_create` also sees some changes. The old dynamic type lookups and crypto API allocations (`crypto_alloc_lskcipher`) are completely bypassed. It's now doing direct key preparation. It uses a switch statement based on the algorithm type. And there's a `WARN_ON_ONCE(1)`! This means there's a new runtime assertion in reachable code, which is good to catch unexpected cases. In `bpf_aes_cbc_crypt` and `bpf_aes_ecb_crypt`, the implementations are pretty straightforward. There are checks on IV length, source/destination lengths (must be multiples of `AES_BLOCK_SIZE`, dst len >= src len), and then calls to standard AES encrypt/decrypt functions. Looking deeper into the `bpf_crypto_crypt` function, there are some changes in the checks and memory management. The check for `src_len > dst_len` is gone. Instead, the check is now inside the `bpf_aes_*_crypt` functions. There's also `kfree_sensitive(ctx);` in `crypto_free_cb`, which is the right way to free sensitive data. It looks like it's now using `kzalloc_obj(*ctx)` instead of kmalloc, so zeroed-out memory, and it also uses sensitive free functions. The most notable change is the complete removal of `bpf_crypto_register_type`, `bpf_crypto_unregister_type`, and the entire modular skcipher provider in `crypto/bpf_crypto_skcipher.c`. All the flexibility of that design has been traded for this new model. This removes a lot of complexity, which is good. Finally, checking the Kconfig dependencies... `kernel/bpf/Kconfig` shows that `BPF_CRYPTO` is enabled by default (`def_bool y`) and depends on `BPF_SYSCALL`. It also selects `CRYPTO_LIB_AES_CBC` and `CRYPTO_LIB_AES_ECB`, which makes sense. Based on the `Makefile`, `crypto.o` is only compiled if `BPF_CRYPTO` is defined. This is all standard BPF setup, really. No other significant dependencies. |
| 8/2 | 2026/09/27 00:15 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/Kconfig",
"FirstLine": 85,
"LineCount": 30
}Results: {
"Contents": " 85:\t\t disable it by setting it to 1 (from which no other transition to\n 86:\t\t 0 is possible anymore).\n 87:\t\n 88:\t\t Unprivileged BPF could be used to exploit certain potential\n 89:\t\t speculative execution side-channel vulnerabilities on unmitigated\n 90:\t\t affected hardware.\n 91:\t\n 92:\t\t If you are unsure how to answer this question, answer Y.\n 93:\t\n 94:\tconfig BPF_CRYPTO\n 95:\t\tdef_bool y\n 96:\t\tdepends on BPF_SYSCALL\n 97:\t\tselect CRYPTO_LIB_AES_CBC\n 98:\t\tselect CRYPTO_LIB_AES_ECB\n 99:\t\thelp\n 100:\t\t Provide the kfuncs needed for BPF programs to encrypt and decrypt\n 101:\t\t data. The supported algorithms are AES-CBC and AES-ECB.\n 102:\t\n 103:\tsource \"kernel/bpf/preload/Kconfig\"\n 104:\t\n 105:\tconfig BPF_LSM\n 106:\t\tbool \"Enable BPF LSM Instrumentation\"\n 107:\t\tdepends on BPF_EVENTS\n 108:\t\tdepends on BPF_SYSCALL\n 109:\t\tdepends on SECURITY\n 110:\t\tdepends on BPF_JIT\n 111:\t\thelp\n 112:\t\t Enables instrumentation of the security hooks with BPF programs for\n 113:\t\t implementing dynamic MAC and Audit Policies.\n 114:\t\n"
} |
| 9/2 | 2026/09/27 00:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15621 output: 23 thoughts: 62 Thoughts: **My Assessment of Kernel Crypto Configuration** Okay, so I'm looking at this kernel config, specifically the relationship between `BPF_CRYPTO` and `BPF_SYSCALL`. Clearly, `BPF_CRYPTO` leverages `BPF_SYSCALL`, which makes sense. I need to make sure that dependency is handled correctly. Furthermore, I see the selection of `CRYPTO_LIB_AES_CBC` and `CRYPTO_LIB_AES_ECB`, which is good. Now, before I move on, I want to confirm that `CRYPTO_LIB_AES_CBC` itself doesn't have any hidden dependencies that I need to be aware of. Gotta make sure the foundation is solid before I build on it. |
| 10/2 | 2026/09/27 00:15 | tool | grepper |
0mArgs:{
"Expression": "config CRYPTO_LIB_AES_CBC"
}Results: {
"Output": "lib/crypto/Kconfig=27=config CRYPTO_LIB_AESCFB\n--\nlib/crypto/Kconfig-31-\nlib/crypto/Kconfig:32:config CRYPTO_LIB_AES_CBC\nlib/crypto/Kconfig-33-\ttristate\n--\nlib/crypto/Kconfig-37-\nlib/crypto/Kconfig:38:config CRYPTO_LIB_AES_CBC_MACS\nlib/crypto/Kconfig-39-\ttristate\n--\nlib/crypto/tests/Kconfig-2-\nlib/crypto/tests/Kconfig:3:config CRYPTO_LIB_AES_CBC_MACS_KUNIT_TEST\nlib/crypto/tests/Kconfig-4-\ttristate \"KUnit tests for AES-CMAC, AES-XCBC-MAC, and AES-CBC-MAC\" if !KUNIT_ALL_TESTS\n"
} |
| 11/2 | 2026/09/27 00:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16088 output: 33 thoughts: 18 Thoughts: Here's my take on those thoughts: **Navigating the Kconfig Labyrinth** Okay, so I'm thinking, let's dive into the `lib/crypto/Kconfig` file. I've got a hunch about something going on, and based on past experience I'm going to zero in on line 32. It’s where I suspect the relevant configuration options or dependencies might be defined, or at least a good place to start my investigation. This is the starting point to understand the broader implications and context. Time to get my hands dirty and see what we can find. |
| 12/2 | 2026/09/27 00:15 | tool | read-file |
0mArgs:{
"File": "lib/crypto/Kconfig",
"FirstLine": 25,
"LineCount": 25
}Results: {
"Contents": " 25:\t\tdefault y if X86\n 26:\t\n 27:\tconfig CRYPTO_LIB_AESCFB\n 28:\t\ttristate\n 29:\t\tselect CRYPTO_LIB_AES\n 30:\t\tselect CRYPTO_LIB_UTILS\n 31:\t\n 32:\tconfig CRYPTO_LIB_AES_CBC\n 33:\t\ttristate\n 34:\t\tselect CRYPTO_LIB_AES\n 35:\t\thelp\n 36:\t\t The AES-CBC and AES-CBC-CTS library functions.\n 37:\t\n 38:\tconfig CRYPTO_LIB_AES_CBC_MACS\n 39:\t\ttristate\n 40:\t\tselect CRYPTO_LIB_AES\n 41:\t\thelp\n 42:\t\t The AES-CMAC, AES-XCBC-MAC, and AES-CBC-MAC library functions. Select\n 43:\t\t this if your module uses any of the functions from\n 44:\t\t \u003ccrypto/aes-cbc-macs.h\u003e.\n 45:\t\n 46:\tconfig CRYPTO_LIB_AES_CCM\n 47:\t\ttristate\n 48:\t\tselect CRYPTO_LIB_AES\n 49:\t\tselect CRYPTO_LIB_AES_CBC_MACS\n"
} |
| 13/2 | 2026/09/27 00:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16599 output: 188 thoughts: 1327 Thoughts: **Analysis of BPF Crypto Implementation for Fuzzing** Okay, so I'm looking at this BPF crypto implementation and the first thing I notice is the lack of extra dependencies for `CRYPTO_LIB_AES_CBC` and `CRYPTO_LIB_AES_ECB`, which is good. `BPF_CRYPTO` depends on `BPF_SYSCALL`, and that makes sense given the nature of BPF. The general BPF configuration is `CONFIG_BPF`, of course. Now, I need to see what's actually changed in `kernel/bpf/crypto.c`. I've identified these functions as potential entrypoints or areas of modified logic: `bpf_crypto_ctx_create`, `bpf_crypto_decrypt`, `bpf_crypto_encrypt`, `bpf_crypto_crypt`, `bpf_aes_cbc_crypt`, `bpf_aes_ecb_crypt`, `bpf_crypto_find_algo`, `crypto_free_cb`, and `bpf_crypto_ctx_release_dtor`. `bpf_aes_cbc_crypt` and `bpf_aes_ecb_crypt` are static, which is important to note. But `bpf_crypto_ctx_create`, `bpf_crypto_decrypt`, and `bpf_crypto_encrypt` are kfuncs exported via BTF / `__bpf_kfunc`. That means they are definitely non-static C functions, compiled into the kernel image and registered as kfuncs, and have symbols in vmlinux. Let me verify this, yep, they're non-static. The definitions in `kernel/bpf/crypto.c` confirm this: `__bpf_kfunc struct bpf_crypto_ctx * bpf_crypto_ctx_create(...)`, `__bpf_kfunc int bpf_crypto_decrypt(...)`, and `__bpf_kfunc int bpf_crypto_encrypt(...)`. Static functions like `bpf_crypto_crypt`, `bpf_aes_cbc_crypt`, `bpf_aes_ecb_crypt`, and `bpf_crypto_find_algo` exist, and they might or might not be preserved in kallsyms due to compiler inlining. However, the kfuncs, are definitely there. Since Syzkaller kcov coverage uses symbol names from `/proc/kallsyms` (or nm vmlinux), and kfuncs are non-static, they'll always be present. Static functions might also be present if not inlined. The guidelines for identifying functions to fuzz are clear: I need to focus on functions implementing the new logic or are the direct API entrypoints. Considering that, I'm going to include `bpf_crypto_ctx_create`, `bpf_crypto_encrypt`, and `bpf_crypto_decrypt` as they are the direct API entrypoints. Now, is this worth fuzzing? Let's break it down: 1. **Core Subsystems:** The BPF subsystem is definitely modified, specifically `kernel/bpf/crypto.c` and `kernel/bpf/verifier.c`. 2. **Reachable Executable Code:** Userspace can load BPF programs, which can invoke `bpf_crypto_ctx_create`, `bpf_crypto_encrypt`, and `bpf_crypto_decrypt` through the BPF syscall. 3. **Major Logic Modification:** This is a big one. The whole crypto backend was reworked from the generic crypto API to direct library AES calls. This involves changes in how keys, IVs, buffer sizes, and contexts are handled and validated. 4. **Runtime Assertions:** That new `WARN_ON_ONCE(1)` in `bpf_crypto_ctx_create` is a red flag, which makes this worth fuzzing. 5. **WorthFuzzing = true.** I need to confirm the required configurations: `CONFIG_BPF_SYSCALL` and `CONFIG_BPF_CRYPTO` (which depends on the former). Just to be thorough, I'm double-checking the symbols one last time: `bpf_crypto_ctx_create`, `bpf_crypto_encrypt`, `bpf_crypto_decrypt`, `bpf_crypto_crypt`, `bpf_aes_cbc_crypt`, and `bpf_aes_ecb_crypt`. I should check what other files are affected. The only other relevant change is in `verifier.c`: `BTF_ID(struct, bpf_crypto_ctx)` was under `#ifdef CONFIG_CRYPTO`, but is now `#ifdef CONFIG_BPF_CRYPTO`. That' |
| 14/2 | 2026/09/27 00:16 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_CRYPTO"
],
"FocusSymbols": [
"bpf_crypto_ctx_create",
"bpf_crypto_encrypt",
"bpf_crypto_decrypt",
"bpf_crypto_crypt",
"bpf_aes_cbc_crypt",
"bpf_aes_ecb_crypt"
],
"Reasoning": "The patch refactors the BPF crypto subsystem to directly use AES library functions (AES-CBC and AES-ECB) rather than the generic crypto skcipher API, adding new validation logic, direct key setup, encryption/decryption helpers, and a new WARN_ON_ONCE assertion. These changes modify reachable BPF kfuncs executable via standard BPF syscall programs and warrant fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_CRYPTO"
],
"FocusSymbols": [
"bpf_crypto_ctx_create",
"bpf_crypto_encrypt",
"bpf_crypto_decrypt",
"bpf_crypto_crypt",
"bpf_aes_cbc_crypt",
"bpf_aes_ecb_crypt"
],
"Reasoning": "The patch refactors the BPF crypto subsystem to directly use AES library functions (AES-CBC and AES-ECB) rather than the generic crypto skcipher API, adding new validation logic, direct key setup, encryption/decryption helpers, and a new WARN_ON_ONCE assertion. These changes modify reachable BPF kfuncs executable via standard BPF syscall programs and warrant fuzzing.",
"WorthFuzzing": true
} |
| 15/1 | 2026/09/27 00:16 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 16/2 | 2026/09/27 00:16 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch refactors BPF crypto support by replacing the dynamic skcipher crypto API registration with direct calls to kernel AES library routines (CRYPTO_LIB_AES_CBC and CRYPTO_LIB_AES_ECB). \n\nFrom a memory initialization perspective:\n- bpf_crypto_ctx is allocated using kzalloc_obj(), which zeroes all context fields prior to usage.\n- Error codes and local variables in bpf_crypto_ctx_create() and bpf_crypto_crypt() are initialized on all paths before evaluation.\n- No kernel data structures or padded structs are copied to userspace (no copy_to_user, put_user, netlink, or socket options involved).\n- Buffer and dynptr length validations are strictly checked (e.g. AES block size multiples, dst_len \u003e= src_len, exact IV size).\n- Any potential memory safety issues (such as buffer overruns during encryption/decryption or refcount/use-after-free issues with the crypto context) are squarely within the domain of KASAN rather than KMSAN.\n\nTherefore, the changes do not expose uninitialized memory risks or kernel-to-user info-leaks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit c80e54e97a241421dbaaa989b63fd2cee65db73f
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 27 00:15:27 2026 +0000
syz-cluster: applied patch under review
diff --git a/MAINTAINERS b/MAINTAINERS
index 140eafcbbd782..cf806c2b788e3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4936,8 +4936,6 @@ BPF [CRYPTO]
M: Vadim Fedorenko <vadim.fedorenko@linux.dev>
L: bpf@vger.kernel.org
S: Maintained
-F: crypto/bpf_crypto_skcipher.c
-F: include/linux/bpf_crypto.h
F: kernel/bpf/crypto.c
BPF [DOCUMENTATION] (Related to Standardization)
diff --git a/crypto/Makefile b/crypto/Makefile
index 8386d55a9755e..33bb5ad595e8f 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -22,9 +22,6 @@ crypto_skcipher-y += lskcipher.o
crypto_skcipher-y += skcipher.o
obj-$(CONFIG_CRYPTO_SKCIPHER2) += crypto_skcipher.o
-ifeq ($(CONFIG_BPF_SYSCALL),y)
-obj-$(CONFIG_CRYPTO_SKCIPHER2) += bpf_crypto_skcipher.o
-endif
obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
obj-$(CONFIG_CRYPTO_ECHAINIV) += echainiv.o
diff --git a/crypto/bpf_crypto_skcipher.c b/crypto/bpf_crypto_skcipher.c
deleted file mode 100644
index a88798d3e8c87..0000000000000
--- a/crypto/bpf_crypto_skcipher.c
+++ /dev/null
@@ -1,83 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/* Copyright (c) 2024 Meta, Inc */
-#include <linux/types.h>
-#include <linux/module.h>
-#include <linux/bpf_crypto.h>
-#include <crypto/skcipher.h>
-
-static void *bpf_crypto_lskcipher_alloc_tfm(const char *algo)
-{
- return crypto_alloc_lskcipher(algo, 0, 0);
-}
-
-static void bpf_crypto_lskcipher_free_tfm(void *tfm)
-{
- crypto_free_lskcipher(tfm);
-}
-
-static int bpf_crypto_lskcipher_has_algo(const char *algo)
-{
- return crypto_has_skcipher(algo, CRYPTO_ALG_TYPE_LSKCIPHER, CRYPTO_ALG_TYPE_MASK);
-}
-
-static int bpf_crypto_lskcipher_setkey(void *tfm, const u8 *key, unsigned int keylen)
-{
- return crypto_lskcipher_setkey(tfm, key, keylen);
-}
-
-static u32 bpf_crypto_lskcipher_get_flags(void *tfm)
-{
- return crypto_lskcipher_get_flags(tfm);
-}
-
-static unsigned int bpf_crypto_lskcipher_ivsize(void *tfm)
-{
- return crypto_lskcipher_ivsize(tfm);
-}
-
-static unsigned int bpf_crypto_lskcipher_statesize(void *tfm)
-{
- return crypto_lskcipher_statesize(tfm);
-}
-
-static int bpf_crypto_lskcipher_encrypt(void *tfm, const u8 *src, u8 *dst,
- unsigned int len, u8 *siv)
-{
- return crypto_lskcipher_encrypt(tfm, src, dst, len, siv);
-}
-
-static int bpf_crypto_lskcipher_decrypt(void *tfm, const u8 *src, u8 *dst,
- unsigned int len, u8 *siv)
-{
- return crypto_lskcipher_decrypt(tfm, src, dst, len, siv);
-}
-
-static const struct bpf_crypto_type bpf_crypto_lskcipher_type = {
- .alloc_tfm = bpf_crypto_lskcipher_alloc_tfm,
- .free_tfm = bpf_crypto_lskcipher_free_tfm,
- .has_algo = bpf_crypto_lskcipher_has_algo,
- .setkey = bpf_crypto_lskcipher_setkey,
- .encrypt = bpf_crypto_lskcipher_encrypt,
- .decrypt = bpf_crypto_lskcipher_decrypt,
- .ivsize = bpf_crypto_lskcipher_ivsize,
- .statesize = bpf_crypto_lskcipher_statesize,
- .get_flags = bpf_crypto_lskcipher_get_flags,
- .owner = THIS_MODULE,
- .name = "skcipher",
-};
-
-static int __init bpf_crypto_skcipher_init(void)
-{
- return bpf_crypto_register_type(&bpf_crypto_lskcipher_type);
-}
-
-static void __exit bpf_crypto_skcipher_exit(void)
-{
- int err = bpf_crypto_unregister_type(&bpf_crypto_lskcipher_type);
- WARN_ON_ONCE(err);
-}
-
-module_init(bpf_crypto_skcipher_init);
-module_exit(bpf_crypto_skcipher_exit);
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Symmetric key cipher support for BPF");
diff --git a/include/linux/bpf_crypto.h b/include/linux/bpf_crypto.h
deleted file mode 100644
index a41e71d4e2d9f..0000000000000
--- a/include/linux/bpf_crypto.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
-#ifndef _BPF_CRYPTO_H
-#define _BPF_CRYPTO_H
-
-struct bpf_crypto_type {
- void *(*alloc_tfm)(const char *algo);
- void (*free_tfm)(void *tfm);
- int (*has_algo)(const char *algo);
- int (*setkey)(void *tfm, const u8 *key, unsigned int keylen);
- int (*setauthsize)(void *tfm, unsigned int authsize);
- int (*encrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);
- int (*decrypt)(void *tfm, const u8 *src, u8 *dst, unsigned int len, u8 *iv);
- unsigned int (*ivsize)(void *tfm);
- unsigned int (*statesize)(void *tfm);
- u32 (*get_flags)(void *tfm);
- struct module *owner;
- char name[14];
-};
-
-int bpf_crypto_register_type(const struct bpf_crypto_type *type);
-int bpf_crypto_unregister_type(const struct bpf_crypto_type *type);
-
-#endif /* _BPF_CRYPTO_H */
diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig
index d7d25477ef481..98493e32db2ad 100644
--- a/kernel/bpf/Kconfig
+++ b/kernel/bpf/Kconfig
@@ -91,6 +91,15 @@ config BPF_UNPRIV_DEFAULT_OFF
If you are unsure how to answer this question, answer Y.
+config BPF_CRYPTO
+ def_bool y
+ depends on BPF_SYSCALL
+ select CRYPTO_LIB_AES_CBC
+ select CRYPTO_LIB_AES_ECB
+ help
+ Provide the kfuncs needed for BPF programs to encrypt and decrypt
+ data. The supported algorithms are AES-CBC and AES-ECB.
+
source "kernel/bpf/preload/Kconfig"
config BPF_LSM
diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index 9a92c348bbda6..c1f9b0d3468d3 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -58,9 +58,7 @@ obj-$(CONFIG_BPF_SYSCALL) += cpumask.o
# semantics within pahole are revisited accordingly.
obj-${CONFIG_BPF_LSM} += bpf_lsm_proto.o bpf_lsm.o
endif
-ifneq ($(CONFIG_CRYPTO),)
-obj-$(CONFIG_BPF_SYSCALL) += crypto.o
-endif
+obj-$(CONFIG_BPF_CRYPTO) += crypto.o
obj-$(CONFIG_BPF_PRELOAD) += preload/
obj-$(CONFIG_BPF_SYSCALL) += relo_core.o
diff --git a/kernel/bpf/crypto.c b/kernel/bpf/crypto.c
index 3f3fe2450fc6c..69bc29d0a4d4d 100644
--- a/kernel/bpf/crypto.c
+++ b/kernel/bpf/crypto.c
@@ -1,19 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2024 Meta, Inc */
#include <linux/bpf.h>
-#include <linux/bpf_crypto.h>
#include <linux/bpf_mem_alloc.h>
#include <linux/btf.h>
#include <linux/btf_ids.h>
#include <linux/filter.h>
-#include <linux/scatterlist.h>
#include <linux/skbuff.h>
-#include <crypto/skcipher.h>
-
-struct bpf_crypto_type_list {
- const struct bpf_crypto_type *type;
- struct list_head list;
-};
+#include <crypto/aes-cbc.h>
+#include <crypto/aes-ecb.h>
/* BPF crypto initialization parameters struct */
/**
@@ -36,94 +30,53 @@ struct bpf_crypto_params {
u32 authsize;
};
-static LIST_HEAD(bpf_crypto_types);
-static DECLARE_RWSEM(bpf_crypto_types_sem);
+enum bpf_crypto_algo_id {
+ BPF_ALGO_AES_CBC,
+ BPF_ALGO_AES_ECB,
+};
+
+static const struct {
+ const char *type_name;
+ const char *algo_name;
+ enum bpf_crypto_algo_id algo;
+} bpf_crypto_algos[] = {
+ { "skcipher", "cbc(aes)", BPF_ALGO_AES_CBC },
+ { "skcipher", "ecb(aes)", BPF_ALGO_AES_ECB },
+};
+
+static bool bpf_crypto_find_algo(const struct bpf_crypto_params *params,
+ enum bpf_crypto_algo_id *id_ret)
+{
+ for (size_t i = 0; i < ARRAY_SIZE(bpf_crypto_algos); i++) {
+ if (strncmp(bpf_crypto_algos[i].type_name, params->type,
+ sizeof(params->type)) == 0 &&
+ strncmp(bpf_crypto_algos[i].algo_name, params->algo,
+ sizeof(params->algo)) == 0) {
+ *id_ret = bpf_crypto_algos[i].algo;
+ return true;
+ }
+ }
+ return false;
+}
/**
* struct bpf_crypto_ctx - refcounted BPF crypto context structure
- * @type: The pointer to bpf crypto type
- * @tfm: The pointer to instance of crypto API struct.
- * @siv_len: Size of IV and state storage for cipher
+ * @key: The crypto key
+ * @algo: The crypto algorithm ID
* @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 {
- const struct bpf_crypto_type *type;
- void *tfm;
- u32 siv_len;
+ union {
+ struct aes_key aes;
+ } key;
+ enum bpf_crypto_algo_id algo;
struct rcu_head rcu;
refcount_t usage;
};
-int bpf_crypto_register_type(const struct bpf_crypto_type *type)
-{
- struct bpf_crypto_type_list *node;
- int err = -EBUSY;
-
- down_write(&bpf_crypto_types_sem);
- list_for_each_entry(node, &bpf_crypto_types, list) {
- if (!strcmp(node->type->name, type->name))
- goto unlock;
- }
-
- node = kmalloc_obj(*node);
- err = -ENOMEM;
- if (!node)
- goto unlock;
-
- node->type = type;
- list_add(&node->list, &bpf_crypto_types);
- err = 0;
-
-unlock:
- up_write(&bpf_crypto_types_sem);
-
- return err;
-}
-EXPORT_SYMBOL_GPL(bpf_crypto_register_type);
-
-int bpf_crypto_unregister_type(const struct bpf_crypto_type *type)
-{
- struct bpf_crypto_type_list *node;
- int err = -ENOENT;
-
- down_write(&bpf_crypto_types_sem);
- list_for_each_entry(node, &bpf_crypto_types, list) {
- if (strcmp(node->type->name, type->name))
- continue;
-
- list_del(&node->list);
- kfree(node);
- err = 0;
- break;
- }
- up_write(&bpf_crypto_types_sem);
-
- return err;
-}
-EXPORT_SYMBOL_GPL(bpf_crypto_unregister_type);
-
-static const struct bpf_crypto_type *bpf_crypto_get_type(const char *name)
-{
- const struct bpf_crypto_type *type = ERR_PTR(-ENOENT);
- struct bpf_crypto_type_list *node;
-
- down_read(&bpf_crypto_types_sem);
- list_for_each_entry(node, &bpf_crypto_types, list) {
- if (strcmp(node->type->name, name))
- continue;
-
- if (try_module_get(node->type->owner))
- type = node->type;
- break;
- }
- up_read(&bpf_crypto_types_sem);
-
- return type;
-}
-
__bpf_kfunc_start_defs();
/**
@@ -132,93 +85,70 @@ __bpf_kfunc_start_defs();
* Allocates a crypto context that can be used, acquired, and released by
* a BPF program. The crypto context returned by this function must either
* be embedded in a map as a kptr, or freed with bpf_crypto_ctx_release().
- * As crypto API functions use GFP_KERNEL allocations, this function can
- * only be used in sleepable BPF programs.
+ * As this uses a GFP_KERNEL allocation, this function can only be used in
+ * sleepable BPF programs.
*
* bpf_crypto_ctx_create() allocates memory for crypto context.
* It may return NULL if no memory is available.
* @params: pointer to struct bpf_crypto_params which contains all the
* details needed to initialise crypto context.
- * @params__sz: size of steuct bpf_crypto_params usef by bpf program
- * @err: integer to store error code when NULL is returned.
+ * @params__sz: size of struct bpf_crypto_params used by bpf program
+ * @err_ret: integer to store error code when NULL is returned.
*/
__bpf_kfunc struct bpf_crypto_ctx *
bpf_crypto_ctx_create(const struct bpf_crypto_params *params, u32 params__sz,
- int *err)
+ int *err_ret)
{
- const struct bpf_crypto_type *type;
struct bpf_crypto_ctx *ctx;
+ int err;
if (!params ||
params__sz != sizeof(struct bpf_crypto_params) ||
params->reserved[0] || params->reserved[1]) {
- *err = -EINVAL;
+ *err_ret = -EINVAL;
return NULL;
}
- type = bpf_crypto_get_type(params->type);
- if (IS_ERR(type)) {
- *err = PTR_ERR(type);
- return NULL;
- }
-
- if (!type->has_algo(params->algo)) {
- *err = -EOPNOTSUPP;
- goto err_module_put;
- }
-
- if (!!params->authsize ^ !!type->setauthsize) {
- *err = -EOPNOTSUPP;
- goto err_module_put;
- }
-
if (!params->key_len || params->key_len > sizeof(params->key)) {
- *err = -EINVAL;
- goto err_module_put;
+ *err_ret = -EINVAL;
+ return NULL;
}
ctx = kzalloc_obj(*ctx);
if (!ctx) {
- *err = -ENOMEM;
- goto err_module_put;
+ *err_ret = -ENOMEM;
+ return NULL;
}
- ctx->type = type;
- ctx->tfm = type->alloc_tfm(params->algo);
- if (IS_ERR(ctx->tfm)) {
- *err = PTR_ERR(ctx->tfm);
- goto err_free_ctx;
+ if (!bpf_crypto_find_algo(params, &ctx->algo)) {
+ err = -EOPNOTSUPP;
+ goto out;
}
- if (params->authsize) {
- *err = type->setauthsize(ctx->tfm, params->authsize);
- if (*err)
- goto err_free_tfm;
+ switch (ctx->algo) {
+ case BPF_ALGO_AES_CBC:
+ case BPF_ALGO_AES_ECB:
+ if (params->authsize)
+ err = -EOPNOTSUPP;
+ else
+ err = aes_preparekey(&ctx->key.aes, params->key,
+ params->key_len);
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ err = -EOPNOTSUPP;
+ break;
}
- *err = type->setkey(ctx->tfm, params->key, params->key_len);
- if (*err)
- goto err_free_tfm;
-
- if (type->get_flags(ctx->tfm) & CRYPTO_TFM_NEED_KEY) {
- *err = -EINVAL;
- goto err_free_tfm;
+out:
+ if (err) {
+ kfree_sensitive(ctx);
+ *err_ret = err;
+ return NULL;
}
-
- ctx->siv_len = type->ivsize(ctx->tfm) + type->statesize(ctx->tfm);
-
refcount_set(&ctx->usage, 1);
-
+ *err_ret = 0;
return ctx;
-
-err_free_tfm:
- type->free_tfm(ctx->tfm);
-err_free_ctx:
- kfree(ctx);
-err_module_put:
- module_put(type->owner);
-
- return NULL;
}
static void crypto_free_cb(struct rcu_head *head)
@@ -226,9 +156,7 @@ static void crypto_free_cb(struct rcu_head *head)
struct bpf_crypto_ctx *ctx;
ctx = container_of(head, struct bpf_crypto_ctx, rcu);
- ctx->type->free_tfm(ctx->tfm);
- module_put(ctx->type->owner);
- kfree(ctx);
+ kfree_sensitive(ctx);
}
/**
@@ -268,27 +196,53 @@ __bpf_kfunc void bpf_crypto_ctx_release_dtor(void *ctx)
}
CFI_NOSEAL(bpf_crypto_ctx_release_dtor);
+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;
+}
+
static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr_kern *src,
const struct bpf_dynptr_kern *dst,
- const struct bpf_dynptr_kern *siv,
+ const struct bpf_dynptr_kern *iv,
bool decrypt)
{
- u32 src_len, dst_len, siv_len;
+ u32 src_len, dst_len, iv_len;
const u8 *psrc;
u8 *pdst, *piv;
- int err;
if (__bpf_dynptr_is_rdonly(dst))
return -EINVAL;
- siv_len = siv ? __bpf_dynptr_size(siv) : 0;
+ iv_len = iv ? __bpf_dynptr_size(iv) : 0;
src_len = __bpf_dynptr_size(src);
dst_len = __bpf_dynptr_size(dst);
- if (!src_len || !dst_len || src_len > dst_len)
- return -EINVAL;
-
- if (siv_len != ctx->siv_len)
+ if (!src_len || !dst_len)
return -EINVAL;
psrc = __bpf_dynptr_data(src, src_len);
@@ -298,14 +252,20 @@ static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
if (!pdst)
return -EINVAL;
- piv = siv_len ? __bpf_dynptr_data_rw(siv, siv_len) : NULL;
- if (siv_len && !piv)
+ piv = iv_len ? __bpf_dynptr_data_rw(iv, iv_len) : NULL;
+ if (iv_len && !piv)
return -EINVAL;
- err = decrypt ? ctx->type->decrypt(ctx->tfm, psrc, pdst, src_len, piv)
- : ctx->type->encrypt(ctx->tfm, psrc, pdst, src_len, piv);
-
- return err;
+ switch (ctx->algo) {
+ case BPF_ALGO_AES_CBC:
+ return bpf_aes_cbc_crypt(pdst, dst_len, psrc, src_len, piv,
+ iv_len, ctx, decrypt);
+ case BPF_ALGO_AES_ECB:
+ return bpf_aes_ecb_crypt(pdst, dst_len, psrc, src_len, piv,
+ iv_len, ctx, decrypt);
+ default:
+ return -EINVAL;
+ }
}
/**
@@ -313,20 +273,20 @@ static int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,
* @ctx: The crypto context being used. The ctx must be a trusted pointer.
* @src: bpf_dynptr to the encrypted data. Must be a trusted pointer.
* @dst: bpf_dynptr to the buffer where to store the result. Must be a trusted pointer.
- * @siv__nullable: bpf_dynptr to IV data and state data to be used by decryptor. May be NULL.
+ * @iv__nullable: bpf_dynptr to the initialization vector. May be NULL.
*
* Decrypts provided buffer using IV data and the crypto context. Crypto context must be configured.
*/
__bpf_kfunc int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr *src,
const struct bpf_dynptr *dst,
- const struct bpf_dynptr *siv__nullable)
+ const struct bpf_dynptr *iv__nullable)
{
const struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;
const struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;
- const struct bpf_dynptr_kern *siv_kern = (struct bpf_dynptr_kern *)siv__nullable;
+ const struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;
- return bpf_crypto_crypt(ctx, src_kern, dst_kern, siv_kern, true);
+ return bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, true);
}
/**
@@ -334,20 +294,20 @@ __bpf_kfunc int bpf_crypto_decrypt(struct bpf_crypto_ctx *ctx,
* @ctx: The crypto context being used. The ctx must be a trusted pointer.
* @src: bpf_dynptr to the plain data. Must be a trusted pointer.
* @dst: bpf_dynptr to the buffer where to store the result. Must be a trusted pointer.
- * @siv__nullable: bpf_dynptr to IV data and state data to be used by decryptor. May be NULL.
+ * @iv__nullable: bpf_dynptr to the initialization vector. May be NULL.
*
* Encrypts provided buffer using IV data and the crypto context. Crypto context must be configured.
*/
__bpf_kfunc int bpf_crypto_encrypt(struct bpf_crypto_ctx *ctx,
const struct bpf_dynptr *src,
const struct bpf_dynptr *dst,
- const struct bpf_dynptr *siv__nullable)
+ const struct bpf_dynptr *iv__nullable)
{
const struct bpf_dynptr_kern *src_kern = (struct bpf_dynptr_kern *)src;
const struct bpf_dynptr_kern *dst_kern = (struct bpf_dynptr_kern *)dst;
- const struct bpf_dynptr_kern *siv_kern = (struct bpf_dynptr_kern *)siv__nullable;
+ const struct bpf_dynptr_kern *iv_kern = (struct bpf_dynptr_kern *)iv__nullable;
- return bpf_crypto_crypt(ctx, src_kern, dst_kern, siv_kern, false);
+ return bpf_crypto_crypt(ctx, src_kern, dst_kern, iv_kern, false);
}
__bpf_kfunc_end_defs();
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 865b6c6eb8dd7..4077c88d95252 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -4742,7 +4742,7 @@ BTF_ID(struct, cgroup)
BTF_ID(struct, bpf_cpumask)
#endif
BTF_ID(struct, task_struct)
-#ifdef CONFIG_CRYPTO
+#ifdef CONFIG_BPF_CRYPTO
BTF_ID(struct, bpf_crypto_ctx)
#endif
#ifdef CONFIG_INET
diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
index d292cb60a5a4e..2b883b388f90c 100644
--- a/tools/testing/selftests/bpf/config
+++ b/tools/testing/selftests/bpf/config
@@ -18,7 +18,7 @@ CONFIG_CRYPTO_SHA512=y
CONFIG_CRYPTO_USER_API=y
CONFIG_CRYPTO_USER_API_HASH=y
CONFIG_CRYPTO_USER_API_SKCIPHER=y
-CONFIG_CRYPTO_SKCIPHER=y
+CONFIG_CRYPTO_CBC=y
CONFIG_CRYPTO_ECB=y
CONFIG_CRYPTO_AES=y
CONFIG_DEBUG_INFO=y
|
| 17/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9849 output: 33 thoughts: 681 Thoughts: **KMSAN Fuzzing Session Evaluation** Okay, so I need to decide if this patch warrants a dedicated KMSAN fuzzing session. Let's think this through systematically, given my knowledge of kernel sanitizers. First, I need to remind myself of the KMSAN mandate: KMSAN's job is to sniff out reads of *uninitialized* memory, whether it's on the stack, heap, or page allocations, and also to catch kernel-to-user memory leaks. It’s important to note that a standard KASAN build already covers a lot of ground with its out-of-bounds, use-after-free, double-free, and general memory corruption checks, along with LOCKDEP and UB-sanitizers. The crucial rule is: if KASAN, LOCKDEP, or any of those other standard detectors *could* catch a bug, then there's no need for KMSAN. A dedicated KMSAN session is resource-intensive, so I only flag a patch for it when the code changes introduce or expose *uninitialized memory risks that KMSAN alone can find*. Now, onto the patch itself. It’s a refactoring of BPF crypto support, which is interesting. It looks like the patch is removing `crypto/bpf_crypto_skcipher.c` and `include/linux/bpf_crypto.h`, and replacing dynamic crypto type registration with direct in-kernel library calls, so instead of registering types, it directly uses `CRYPTO_LIB_AES_CBC` and `CRYPTO_LIB_AES_ECB` for functions like `aes_cbc_encrypt`, `aes_cbc_decrypt`, etc. I'm noting this, but I'll need to keep it in mind while I look for uninitialized memory issues. The patch modifies `kernel/bpf/crypto.c`, specifically. The `bpf_crypto_params` are there, along with the `bpf_crypto_algos` table for CBC and ECB. The `struct bpf_crypto_ctx` now has this `union` for the AES key and an `algo` enum. `bpf_crypto_ctx_create` stands out. It's doing a `kzalloc_obj`, which is good, and it’s preparing the key with `aes_preparekey`. It allocates `ctx` and does an `aes_preparekey` call. The return looks okay, and uses `kfree_sensitive` on error. Renaming the error argument to `err_ret` could be a nitpick, but the key thing is that it frees sensitive data if there's an error. The `bpf_aes_cbc_crypt` and `bpf_aes_ecb_crypt` functions seem to have standard checks for block size, `src_len`, and `dst_len`. They're using `__bpf_dynptr_data` and `__bpf_dynptr_data_rw` in `bpf_crypto_crypt`. Also, I see `kfree_sensitive(ctx)` in the destructor. The critical question: is there a point where uninitialized memory could be exposed, read, or copied to userspace, or even used in branching. It seems like the key is in the `bpf_crypto_ctx` and the `bpf_crypto_ctx_create` functions. I'm going to have to inspect `kernel/bpf/crypto.c` very closely, before and after the patch, to verify there's nothing exposed. I need to make *absolutely sure* that no part of the new code introduces any new risk. This refactoring could actually be *reducing* the risk, but the only way to be sure is to look carefully, with uninitialized memory front of mind. |
| 18/3 | 2026/09/27 00:16 | tool | grepper |
0mArgs:{
"Expression": "bpf_crypto_ctx_create",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/crypto.c=80=__bpf_kfunc_start_defs();\n--\nkernel/bpf/crypto.c-82-/**\nkernel/bpf/crypto.c:83: * bpf_crypto_ctx_create() - Create a mutable BPF crypto context.\nkernel/bpf/crypto.c-84- *\n--\nkernel/bpf/crypto.c-90- *\nkernel/bpf/crypto.c:91: * bpf_crypto_ctx_create() allocates memory for crypto context.\nkernel/bpf/crypto.c-92- * It may return NULL if no memory is available.\n--\nkernel/bpf/crypto.c=98=__bpf_kfunc struct bpf_crypto_ctx *\nkernel/bpf/crypto.c:99:bpf_crypto_ctx_create(const struct bpf_crypto_params *params, u32 params__sz,\nkernel/bpf/crypto.c-100-\t\t int *err_ret)\n--\nkernel/bpf/crypto.c=315=BTF_KFUNCS_START(crypt_init_kfunc_btf_ids)\nkernel/bpf/crypto.c:316:BTF_ID_FLAGS(func, bpf_crypto_ctx_create, KF_ACQUIRE | KF_RET_NULL | KF_SLEEPABLE)\nkernel/bpf/crypto.c-317-BTF_ID_FLAGS(func, bpf_crypto_ctx_release, KF_RELEASE)\n"
} |
| 19/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11745 output: 36 thoughts: 30 Thoughts: Okay, here's my interpretation of that request, formatted as requested: **Diving into kernel/bpf/crypto.c** Alright, let's get down to brass tacks. I need to understand the BPF crypto implementation, so I'm going to start by pulling up `kernel/bpf/crypto.c` and focusing on lines 80 through 330. That's usually where the core data structures and likely the main crypto function dispatch resides. I'll use `read-file` directly within the editor/debugger. This gives me the raw code, ready to examine. From a quick glance, that section should provide a good overview of the design. Once I have the code up I will begin looking for specific function calls and data structures to understand how different operations are handled. I'm looking for the essential parts. |
| 20/3 | 2026/09/27 00:16 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/crypto.c",
"FirstLine": 80,
"LineCount": 100
}Results: {
"Contents": " 80:\t__bpf_kfunc_start_defs();\n 81:\t\n 82:\t/**\n 83:\t * bpf_crypto_ctx_create() - Create a mutable BPF crypto context.\n 84:\t *\n 85:\t * Allocates a crypto context that can be used, acquired, and released by\n 86:\t * a BPF program. The crypto context returned by this function must either\n 87:\t * be embedded in a map as a kptr, or freed with bpf_crypto_ctx_release().\n 88:\t * As this uses a GFP_KERNEL allocation, this function can only be used in\n 89:\t * sleepable BPF programs.\n 90:\t *\n 91:\t * bpf_crypto_ctx_create() allocates memory for crypto context.\n 92:\t * It may return NULL if no memory is available.\n 93:\t * @params:\tpointer to struct bpf_crypto_params which contains all the\n 94:\t *\t\tdetails needed to initialise crypto context.\n 95:\t * @params__sz:\tsize of struct bpf_crypto_params used by bpf program\n 96:\t * @err_ret:\tinteger to store error code when NULL is returned.\n 97:\t */\n 98:\t__bpf_kfunc struct bpf_crypto_ctx *\n 99:\tbpf_crypto_ctx_create(const struct bpf_crypto_params *params, u32 params__sz,\n 100:\t\t\t int *err_ret)\n 101:\t{\n 102:\t\tstruct bpf_crypto_ctx *ctx;\n 103:\t\tint err;\n 104:\t\n 105:\t\tif (!params ||\n 106:\t\t params__sz != sizeof(struct bpf_crypto_params) ||\n 107:\t\t params-\u003ereserved[0] || params-\u003ereserved[1]) {\n 108:\t\t\t*err_ret = -EINVAL;\n 109:\t\t\treturn NULL;\n 110:\t\t}\n 111:\t\n 112:\t\tif (!params-\u003ekey_len || params-\u003ekey_len \u003e sizeof(params-\u003ekey)) {\n 113:\t\t\t*err_ret = -EINVAL;\n 114:\t\t\treturn NULL;\n 115:\t\t}\n 116:\t\n 117:\t\tctx = kzalloc_obj(*ctx);\n 118:\t\tif (!ctx) {\n 119:\t\t\t*err_ret = -ENOMEM;\n 120:\t\t\treturn NULL;\n 121:\t\t}\n 122:\t\n 123:\t\tif (!bpf_crypto_find_algo(params, \u0026ctx-\u003ealgo)) {\n 124:\t\t\terr = -EOPNOTSUPP;\n 125:\t\t\tgoto out;\n 126:\t\t}\n 127:\t\n 128:\t\tswitch (ctx-\u003ealgo) {\n 129:\t\tcase BPF_ALGO_AES_CBC:\n 130:\t\tcase BPF_ALGO_AES_ECB:\n 131:\t\t\tif (params-\u003eauthsize)\n 132:\t\t\t\terr = -EOPNOTSUPP;\n 133:\t\t\telse\n 134:\t\t\t\terr = aes_preparekey(\u0026ctx-\u003ekey.aes, params-\u003ekey,\n 135:\t\t\t\t\t\t params-\u003ekey_len);\n 136:\t\t\tbreak;\n 137:\t\tdefault:\n 138:\t\t\tWARN_ON_ONCE(1);\n 139:\t\t\terr = -EOPNOTSUPP;\n 140:\t\t\tbreak;\n 141:\t\t}\n 142:\t\n 143:\tout:\n 144:\t\tif (err) {\n 145:\t\t\tkfree_sensitive(ctx);\n 146:\t\t\t*err_ret = err;\n 147:\t\t\treturn NULL;\n 148:\t\t}\n 149:\t\trefcount_set(\u0026ctx-\u003eusage, 1);\n 150:\t\t*err_ret = 0;\n 151:\t\treturn ctx;\n 152:\t}\n 153:\t\n 154:\tstatic void crypto_free_cb(struct rcu_head *head)\n 155:\t{\n 156:\t\tstruct bpf_crypto_ctx *ctx;\n 157:\t\n 158:\t\tctx = container_of(head, struct bpf_crypto_ctx, rcu);\n 159:\t\tkfree_sensitive(ctx);\n 160:\t}\n 161:\t\n 162:\t/**\n 163:\t * bpf_crypto_ctx_acquire() - Acquire a reference to a BPF crypto context.\n 164:\t * @ctx: The BPF crypto context being acquired. The ctx must be a trusted\n 165:\t *\t pointer.\n 166:\t *\n 167:\t * Acquires a reference to a BPF crypto context. The context returned by this function\n 168:\t * must either be embedded in a map as a kptr, or freed with\n 169:\t * bpf_crypto_ctx_release().\n 170:\t */\n 171:\t__bpf_kfunc struct bpf_crypto_ctx *\n 172:\tbpf_crypto_ctx_acquire(struct bpf_crypto_ctx *ctx)\n 173:\t{\n 174:\t\tif (!refcount_inc_not_zero(\u0026ctx-\u003eusage))\n 175:\t\t\treturn NULL;\n 176:\t\treturn ctx;\n 177:\t}\n 178:\t\n 179:\t/**\n"
} |
| 21/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13440 output: 37 thoughts: 28 Thoughts: Okay, let's dive into this. I'm going to parse the next chunk of `kernel/bpf/crypto.c`, specifically lines 180 through 350. This seems like a core area, and I need to understand how the BPF subsystem interacts with cryptographic operations. I'll be looking for key function calls, data structures, and the general flow of logic related to cryptographic primitives, particularly as they relate to the BPF verifier or execution environment. My aim is to build a mental map of this part of the codebase. I need to be prepared to identify any potential performance bottlenecks or security vulnerabilities within this section. Given that this is crypto-related, I'll be paying close attention to any error handling or boundary checks. I also want to see how these routines interact with hardware acceleration, if at all, which will inform my understanding. This is going to be important to understand how BPF programs can securely and efficiently interact with hardware. |
| 22/3 | 2026/09/27 00:16 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/crypto.c",
"FirstLine": 180,
"LineCount": 100
}Results: {
"Contents": " 180:\t * bpf_crypto_ctx_release() - Release a previously acquired BPF crypto context.\n 181:\t * @ctx: The crypto context being released.\n 182:\t *\n 183:\t * Releases a previously acquired reference to a BPF crypto context. When the final\n 184:\t * reference of the BPF crypto context has been released, its memory\n 185:\t * will be released.\n 186:\t */\n 187:\t__bpf_kfunc void bpf_crypto_ctx_release(struct bpf_crypto_ctx *ctx)\n 188:\t{\n 189:\t\tif (refcount_dec_and_test(\u0026ctx-\u003eusage))\n 190:\t\t\tcall_rcu(\u0026ctx-\u003ercu, crypto_free_cb);\n 191:\t}\n 192:\t\n 193:\t__bpf_kfunc void bpf_crypto_ctx_release_dtor(void *ctx)\n 194:\t{\n 195:\t\tbpf_crypto_ctx_release(ctx);\n 196:\t}\n 197:\tCFI_NOSEAL(bpf_crypto_ctx_release_dtor);\n 198:\t\n 199:\tstatic int bpf_aes_cbc_crypt(u8 *dst, u32 dst_len, const u8 *src, u32 src_len,\n 200:\t\t\t\t u8 *iv, u32 iv_len,\n 201:\t\t\t\t const struct bpf_crypto_ctx *ctx, bool decrypt)\n 202:\t{\n 203:\t\tif (iv_len != AES_BLOCK_SIZE)\n 204:\t\t\treturn -EINVAL;\n 205:\t\tif (src_len % AES_BLOCK_SIZE || dst_len \u003c src_len)\n 206:\t\t\treturn -EINVAL;\n 207:\t\tif (decrypt)\n 208:\t\t\taes_cbc_decrypt(dst, src, src_len, iv, \u0026ctx-\u003ekey.aes);\n 209:\t\telse\n 210:\t\t\taes_cbc_encrypt(dst, src, src_len, iv, \u0026ctx-\u003ekey.aes);\n 211:\t\treturn 0;\n 212:\t}\n 213:\t\n 214:\tstatic int bpf_aes_ecb_crypt(u8 *dst, u32 dst_len, const u8 *src, u32 src_len,\n 215:\t\t\t\t u8 *iv, u32 iv_len,\n 216:\t\t\t\t const struct bpf_crypto_ctx *ctx, bool decrypt)\n 217:\t{\n 218:\t\tif (iv_len != 0)\n 219:\t\t\treturn -EINVAL;\n 220:\t\tif (src_len % AES_BLOCK_SIZE || dst_len \u003c src_len)\n 221:\t\t\treturn -EINVAL;\n 222:\t\tif (decrypt)\n 223:\t\t\taes_ecb_decrypt(dst, src, src_len, \u0026ctx-\u003ekey.aes);\n 224:\t\telse\n 225:\t\t\taes_ecb_encrypt(dst, src, src_len, \u0026ctx-\u003ekey.aes);\n 226:\t\treturn 0;\n 227:\t}\n 228:\t\n 229:\tstatic int bpf_crypto_crypt(const struct bpf_crypto_ctx *ctx,\n 230:\t\t\t\t const struct bpf_dynptr_kern *src,\n 231:\t\t\t\t const struct bpf_dynptr_kern *dst,\n 232:\t\t\t\t const struct bpf_dynptr_kern *iv,\n 233:\t\t\t\t bool decrypt)\n 234:\t{\n 235:\t\tu32 src_len, dst_len, iv_len;\n 236:\t\tconst u8 *psrc;\n 237:\t\tu8 *pdst, *piv;\n 238:\t\n 239:\t\tif (__bpf_dynptr_is_rdonly(dst))\n 240:\t\t\treturn -EINVAL;\n 241:\t\n 242:\t\tiv_len = iv ? __bpf_dynptr_size(iv) : 0;\n 243:\t\tsrc_len = __bpf_dynptr_size(src);\n 244:\t\tdst_len = __bpf_dynptr_size(dst);\n 245:\t\tif (!src_len || !dst_len)\n 246:\t\t\treturn -EINVAL;\n 247:\t\n 248:\t\tpsrc = __bpf_dynptr_data(src, src_len);\n 249:\t\tif (!psrc)\n 250:\t\t\treturn -EINVAL;\n 251:\t\tpdst = __bpf_dynptr_data_rw(dst, dst_len);\n 252:\t\tif (!pdst)\n 253:\t\t\treturn -EINVAL;\n 254:\t\n 255:\t\tpiv = iv_len ? __bpf_dynptr_data_rw(iv, iv_len) : NULL;\n 256:\t\tif (iv_len \u0026\u0026 !piv)\n 257:\t\t\treturn -EINVAL;\n 258:\t\n 259:\t\tswitch (ctx-\u003ealgo) {\n 260:\t\tcase BPF_ALGO_AES_CBC:\n 261:\t\t\treturn bpf_aes_cbc_crypt(pdst, dst_len, psrc, src_len, piv,\n 262:\t\t\t\t\t\t iv_len, ctx, decrypt);\n 263:\t\tcase BPF_ALGO_AES_ECB:\n 264:\t\t\treturn bpf_aes_ecb_crypt(pdst, dst_len, psrc, src_len, piv,\n 265:\t\t\t\t\t\t iv_len, ctx, decrypt);\n 266:\t\tdefault:\n 267:\t\t\treturn -EINVAL;\n 268:\t\t}\n 269:\t}\n 270:\t\n 271:\t/**\n 272:\t * bpf_crypto_decrypt() - Decrypt buffer using configured context and IV provided.\n 273:\t * @ctx:\t\tThe crypto context being used. The ctx must be a trusted pointer.\n 274:\t * @src:\t\tbpf_dynptr to the encrypted data. Must be a trusted pointer.\n 275:\t * @dst:\t\tbpf_dynptr to the buffer where to store the result. Must be a trusted pointer.\n 276:\t * @iv__nullable:\tbpf_dynptr to the initialization vector. May be NULL.\n 277:\t *\n 278:\t * Decrypts provided buffer using IV data and the crypto context. Crypto context must be configured.\n 279:\t */\n"
} |
| 23/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15441 output: 18 thoughts: 889 Thoughts: **Analyzing the BPF Crypto Implementation** Okay, let's break this down. First, I'm looking at how the `bpf_crypto_crypt` function handles the cryptographic operations. It starts with several sanity checks using `__bpf_dynptr_is_rdonly` and `__bpf_dynptr_size` to ensure the input data structures are valid and the sizes are reasonable. Specifically, it verifies that the destination dynamic pointer (`dst`) isn't read-only, and that both source (`src`) and destination have non-zero lengths. Then, I see the pointer data is extracted using `__bpf_dynptr_data` and `__bpf_dynptr_data_rw`. A crucial check verifies that these data retrievals are successful. The code then branches based on the algorithm specified in the context (`ctx->algo`). Currently, it supports AES in CBC and ECB modes. Looking at `bpf_aes_cbc_crypt`, I see it validates the Initialization Vector (IV) length, source length being a multiple of the AES block size (16 bytes), and that the destination buffer is at least as large as the source. It then calls either `aes_cbc_decrypt` or `aes_cbc_encrypt`. The same logic applies to `bpf_aes_ecb_crypt`, except the IV length check now verifies that the IV length is zero, as expected in ECB mode. The code verifies the source length is a multiple of the AES block size and calls either `aes_ecb_decrypt` or `aes_ecb_encrypt`. Next, I'm examining `bpf_crypto_ctx_create`. This function allocates and initializes the cryptographic context. It checks the input parameters (`params`), verifying their size and reserved fields. Crucially, it validates the key length. Then, the context `ctx` is allocated using `kzalloc_obj`, which zero-initializes the entire context. It's good that it's zeroed, but I need to understand what state this zeroes. I'll need to look at what `*ctx` actually represents, to check what is getting zeroed. I'll check `bpf_crypto_find_algo` and see it checks `params->type` and `params->algo`. Now, I'm focusing on the key setup. The code uses `aes_preparekey`. This is where the actual key material gets prepared for the AES operations. I'll need to go and find the definition of `aes_preparekey` in either `crypto/aes-cbc.h` or, perhaps, `include/crypto/aes-cbc.h`. I need to figure out how that function works to understand how the keys are being set up within the context. |
| 24/3 | 2026/09/27 00:16 | tool | grepper |
0mArgs:{
"Expression": "aes_preparekey"
}Results: {
"Output": "arch/arm/crypto/aes-neonbs-glue.c=234=static int aesbs_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,\n--\narch/arm/crypto/aes-neonbs-glue.c-244-\tkey_len /= 2;\narch/arm/crypto/aes-neonbs-glue.c:245:\terr = aes_preparekey(\u0026ctx-\u003efallback, in_key, key_len);\narch/arm/crypto/aes-neonbs-glue.c-246-\tif (err)\n--\ncrypto/aes.c=26=static int crypto_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,\n--\ncrypto/aes.c-30-\ncrypto/aes.c:31:\treturn aes_preparekey(key, in_key, key_len);\ncrypto/aes.c-32-}\n--\ncrypto/aes.c=213=crypto_aes_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *in_key,\n--\ncrypto/aes.c-217-\ncrypto/aes.c:218:\treturn aes_preparekey(key, in_key, key_len);\ncrypto/aes.c-219-}\n--\ndrivers/crypto/chelsio/chcr_algo.c=1025=static int chcr_update_tweak(struct skcipher_request *req, u8 *iv,\n--\ndrivers/crypto/chelsio/chcr_algo.c-1046-\t\t\t== CHCR_KEYCTX_CIPHER_KEY_SIZE_192)\ndrivers/crypto/chelsio/chcr_algo.c:1047:\t\tret = aes_preparekey(\u0026aes, key, keylen - 8);\ndrivers/crypto/chelsio/chcr_algo.c-1048-\telse\ndrivers/crypto/chelsio/chcr_algo.c:1049:\t\tret = aes_preparekey(\u0026aes, key, keylen);\ndrivers/crypto/chelsio/chcr_algo.c-1050-\tif (ret)\n--\ninclude/crypto/aes-cbc.h-19- *\tlast ciphertext block (or left unchanged if @len == 0).\ninclude/crypto/aes-cbc.h:20: * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()\ninclude/crypto/aes-cbc.h-21- *\n--\ninclude/crypto/aes-cbc.h=27=void aes_cbc_encrypt(u8 *dst, const u8 *src, size_t len,\n--\ninclude/crypto/aes-cbc.h-37- *\tlast ciphertext block (or left unchanged if @len == 0).\ninclude/crypto/aes-cbc.h:38: * @key: The key, already prepared using aes_preparekey()\ninclude/crypto/aes-cbc.h-39- *\n--\ninclude/crypto/aes-cbc.h=45=void aes_cbc_decrypt(u8 *dst, const u8 *src, size_t len,\n--\ninclude/crypto/aes-cbc.h-54- * @iv: The initialization vector, clobbered by this function\ninclude/crypto/aes-cbc.h:55: * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()\ninclude/crypto/aes-cbc.h-56- *\n--\ninclude/crypto/aes-cbc.h=59=void aes_cbc_cts_encrypt(u8 *dst, const u8 *src, size_t len,\n--\ninclude/crypto/aes-cbc.h-68- * @iv: The initialization vector, clobbered by this function\ninclude/crypto/aes-cbc.h:69: * @key: The key, already prepared using aes_preparekey()\ninclude/crypto/aes-cbc.h-70- *\n--\ninclude/crypto/aes-ctr.h-18- * @ctr: The counter. It will be incremented by ceil(@len / AES_BLOCK_SIZE).\ninclude/crypto/aes-ctr.h:19: * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()\ninclude/crypto/aes-ctr.h-20- *\n--\ninclude/crypto/aes-ctr.h=34=void aes_ctr(u8 *dst, const u8 *src, size_t len,\n--\ninclude/crypto/aes-ctr.h-45- * @iv: The initialization vector\ninclude/crypto/aes-ctr.h:46: * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()\ninclude/crypto/aes-ctr.h-47- *\n--\ninclude/crypto/aes-ecb.h-17- * @len: Number of bytes to encrypt. Must be a multiple of AES_BLOCK_SIZE.\ninclude/crypto/aes-ecb.h:18: * @key: The key, already prepared using aes_preparekey() or aes_prepareenckey()\ninclude/crypto/aes-ecb.h-19- *\n--\ninclude/crypto/aes-ecb.h=28=void aes_ecb_encrypt(u8 *dst, const u8 *src, size_t len, aes_encrypt_arg key);\n--\ninclude/crypto/aes-ecb.h-35- * @len: Number of bytes to decrypt. Must be a multiple of AES_BLOCK_SIZE.\ninclude/crypto/aes-ecb.h:36: * @key: The key, already prepared using aes_preparekey()\ninclude/crypto/aes-ecb.h-37- *\n--\ninclude/crypto/aes.h=308=void aes_sparc64_ctr_crypt_256(const u64 *key, const u64 *input, u64 *output,\n--\ninclude/crypto/aes.h-312-/**\ninclude/crypto/aes.h:313: * aes_preparekey() - Prepare an AES key for encryption and decryption\ninclude/crypto/aes.h-314- * @key: (output) The key structure to initialize\n--\ninclude/crypto/aes.h-334- */\ninclude/crypto/aes.h:335:int aes_preparekey(struct aes_key *key, const u8 *in_key, size_t key_len);\ninclude/crypto/aes.h-336-\n--\ninclude/crypto/aes.h=377=void aes_encrypt(aes_encrypt_arg key, u8 out[at_least AES_BLOCK_SIZE],\n--\ninclude/crypto/aes.h-381- * aes_decrypt() - Decrypt a single AES block\ninclude/crypto/aes.h:382: * @key: The AES key, previously initialized by aes_preparekey()\ninclude/crypto/aes.h-383- * @out: Buffer to store the plaintext block\n--\nkernel/bpf/crypto.c=99=bpf_crypto_ctx_create(const struct bpf_crypto_params *params, u32 params__sz,\n--\nkernel/bpf/crypto.c-133-\t\telse\nkernel/bpf/crypto.c:134:\t\t\terr = aes_preparekey(\u0026ctx-\u003ekey.aes, params-\u003ekey,\nkernel/bpf/crypto.c-135-\t\t\t\t\t params-\u003ekey_len);\n--\nlib/crypto/aes.c=411=static void __maybe_unused aes_decrypt_generic(const u32 inv_rndkeys[],\n--\nlib/crypto/aes.c-450- *\nlib/crypto/aes.c:451: * aes_preparekey_arch() is passed an optional pointer 'inv_k' which points to\nlib/crypto/aes.c-452- * the area to store the prepared decryption key. It will be NULL if the user\nlib/crypto/aes.c:453: * is requesting encryption-only. aes_preparekey_arch() is also passed a valid\nlib/crypto/aes.c-454- * 'key_len' and 'nrounds', corresponding to AES-128, AES-192, or AES-256.\n--\nlib/crypto/aes.c-461-\nlib/crypto/aes.c:462:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/aes.c-463-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/aes.c=477=static void aes_decrypt_arch(const struct aes_key *key,\n--\nlib/crypto/aes.c-484-\nlib/crypto/aes.c:485:static int __aes_preparekey(struct aes_enckey *enc_key,\nlib/crypto/aes.c-486-\t\t\t union aes_invkey_arch *inv_k,\n--\nlib/crypto/aes.c-492-\tenc_key-\u003enrounds = 6 + key_len / 4;\nlib/crypto/aes.c:493:\taes_preparekey_arch(\u0026enc_key-\u003ek, inv_k, in_key, key_len,\nlib/crypto/aes.c-494-\t\t\t enc_key-\u003enrounds);\n--\nlib/crypto/aes.c-497-\nlib/crypto/aes.c:498:int aes_preparekey(struct aes_key *key, const u8 *in_key, size_t key_len)\nlib/crypto/aes.c-499-{\nlib/crypto/aes.c:500:\treturn __aes_preparekey((struct aes_enckey *)key, \u0026key-\u003einv_k,\nlib/crypto/aes.c-501-\t\t\t\tin_key, key_len);\nlib/crypto/aes.c-502-}\nlib/crypto/aes.c:503:EXPORT_SYMBOL(aes_preparekey);\nlib/crypto/aes.c-504-\nlib/crypto/aes.c=505=int aes_prepareenckey(struct aes_enckey *key, const u8 *in_key, size_t key_len)\nlib/crypto/aes.c-506-{\nlib/crypto/aes.c:507:\treturn __aes_preparekey(key, NULL, in_key, key_len);\nlib/crypto/aes.c-508-}\n--\nlib/crypto/aes.c=526=static void __init aes_fips_test(void)\n--\nlib/crypto/aes.c-530-\nlib/crypto/aes.c:531:\tif (aes_preparekey(\u0026key, fips_test_key, sizeof(fips_test_key)) != 0)\nlib/crypto/aes.c-532-\t\tpanic(\"aes: FIPS self-test failed (preparekey)\\n\");\n--\nlib/crypto/aes.c=814=static void __init aes_ecb_fips_test(void)\n--\nlib/crypto/aes.c-818-\nlib/crypto/aes.c:819:\tif (aes_preparekey(\u0026key, fips_test_key, sizeof(fips_test_key)) != 0)\nlib/crypto/aes.c-820-\t\tpanic(\"aes: ECB FIPS self-test failed (preparekey)\\n\");\n--\nlib/crypto/aes.c=1024=static void __init aes_cbc_fips_test(void)\n--\nlib/crypto/aes.c-1029-\nlib/crypto/aes.c:1030:\tif (aes_preparekey(\u0026key, fips_test_key, sizeof(fips_test_key)) != 0)\nlib/crypto/aes.c-1031-\t\tpanic(\"aes: CBC FIPS self-test failed (preparekey)\\n\");\n--\nlib/crypto/aes.c=1047=static void __init aes_cbc_cts_fips_test(void)\n--\nlib/crypto/aes.c-1058-\nlib/crypto/aes.c:1059:\tif (aes_preparekey(\u0026key, fips_test_key, sizeof(fips_test_key)) != 0)\nlib/crypto/aes.c-1060-\t\tpanic(\"aes: CBC-CTS FIPS self-test failed (preparekey)\\n\");\n--\nlib/crypto/aes.c=1206=int aes_xts_preparekey(struct aes_xts_key *key, const u8 *in_key,\n--\nlib/crypto/aes.c-1214-\t/* First half of XTS key is the main key */\nlib/crypto/aes.c:1215:\terr = aes_preparekey(\u0026key-\u003emain_key, in_key, key_len / 2);\nlib/crypto/aes.c-1216-\tif (unlikely(err))\n--\nlib/crypto/arm/aes.h=12=asmlinkage void __aes_arm_decrypt(const u32 inv_rk[], int rounds,\n--\nlib/crypto/arm/aes.h-15-\nlib/crypto/arm/aes.h:16:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/arm/aes.h-17-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/arm64/aes.h=41=static void aes_expandkey_arm64(u32 rndkeys[], u32 *inv_rndkeys,\n--\nlib/crypto/arm64/aes.h-107-\nlib/crypto/arm64/aes.h:108:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/arm64/aes.h-109-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/powerpc/aes.h=38=static void spe_end(void)\n--\nlib/crypto/powerpc/aes.h-44-\nlib/crypto/powerpc/aes.h:45:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/powerpc/aes.h-46-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/powerpc/aes.h=109=static void rndkey_from_vsx(u32 out[4], const u32 in[4], bool apply_inv_mix)\n--\nlib/crypto/powerpc/aes.h-128-\nlib/crypto/powerpc/aes.h:129:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/powerpc/aes.h-130-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/riscv/aes.h=15=void aes_decrypt_zvkned(const u32 rndkeys[], int key_len,\n--\nlib/crypto/riscv/aes.h-17-\nlib/crypto/riscv/aes.h:18:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/riscv/aes.h-19-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/s390/aes.h=12=static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_cpacf_aes256);\n--\nlib/crypto/s390/aes.h-19- */\nlib/crypto/s390/aes.h:20:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/s390/aes.h-21-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/sparc/aes.h=45=void aes_sparc64_decrypt_256(const u64 *key, const u32 *input, u32 *output);\nlib/crypto/sparc/aes.h-46-\nlib/crypto/sparc/aes.h:47:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/sparc/aes.h-48-\t\t\t\tunion aes_invkey_arch *inv_k,\n--\nlib/crypto/x86/aes.h=18=void aes_decrypt_aesni(const u32 inv_rndkeys[], int nrounds,\n--\nlib/crypto/x86/aes.h-31- */\nlib/crypto/x86/aes.h:32:static void aes_preparekey_arch(union aes_enckey_arch *k,\nlib/crypto/x86/aes.h-33-\t\t\t\tunion aes_invkey_arch *inv_k,\n"
} |
| 25/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21100 output: 20 thoughts: 2788 Thoughts: **Analysis of BPF Crypto Context and Encryption/Decryption** Alright, let's break this down systematically. I'm focusing on potential vulnerabilities related to uninitialized memory access or leaks in this BPF crypto context implementation. First, the `bpf_crypto_ctx` structure itself. It appears straightforward; a union for the key (AES in this case), an algorithm ID, an RCU head, and a reference count. The crucial part here is the `kzalloc_obj` call during creation. This zeros the entire `ctx` structure. That's a good initial step, preventing any immediate uninitialized memory issues during allocation. The reference count is initialized, and an error code is returned via `err_ret`, which is always initialized before returning from `bpf_crypto_ctx_create`. This means there's no way to read uninitialized memory directly from the context creation. Now, looking at `bpf_crypto_crypt` and, specifically, the AES CBC/ECB implementations (`bpf_aes_cbc_crypt`, `bpf_aes_ecb_crypt`). The key thing is how these functions handle the source (`src`), destination (`dst`), and initialization vector (`iv`). The new code enforces strict size constraints: `iv_len` must be `AES_BLOCK_SIZE` for CBC, and it must be non-zero for ECB, and source length must be block size aligned. Both ECB and CBC check that the destination is at least as large as the source (`dst_len < src_len`). This part is important: it verifies the sizes correctly. I'm also ensuring the old code behaves the same way, and the old code rejects this scenario, also. The functions `aes_cbc_encrypt/decrypt` and `aes_ecb_encrypt/decrypt` are the core crypto functions. They are only writing the length of the source data into the destination. The `bpf_dynptr_kern` structure handles the source and destination buffers, and the length checks ensure that we don't try to write past the allocated destination buffer. Furthermore, with the old code, `crypto_lskcipher_encrypt` (or decrypt) also only wrote the length of the source into the destination buffer. The key question is whether any data is ever *leaked* to userspace. Since these are BPF kfuncs, they're called within kernel space. Nothing is explicitly copied to user space using `copy_to_user` or any similar functions. The `*err_ret` value is the only "output" that might be relevant, and it is checked and set to a value on all code paths. I'm checking for the four KMSAN conditions. I don't see any explicit copying to user space that would be vulnerable to uninitialized memory. I've traced through the error handling and allocation paths, and I'm confident that all variables, especially error codes, are initialized before use. Finally, the size checks and the memory zeroing at allocation and free time seem robust enough to prevent any bounds-related uninitialized memory issues. Therefore, given the zeroing of `bpf_crypto_ctx`, the consistent checks on buffer lengths, and the absence of data copying to user space, I'm fairly confident that this implementation is not vulnerable to any significant uninitialized memory read/leak issues. |
| 26/3 | 2026/09/27 00:16 | tool | grepper |
0mArgs:{
"Expression": "void aes_cbc_encrypt"
}Results: {
"Output": "arch/riscv/crypto/aes-riscv64-glue.c=27=asmlinkage void aes_ecb_decrypt_zvkned(const struct crypto_aes_ctx *key,\n--\narch/riscv/crypto/aes-riscv64-glue.c-29-\narch/riscv/crypto/aes-riscv64-glue.c:30:asmlinkage void aes_cbc_encrypt_zvkned(const struct crypto_aes_ctx *key,\narch/riscv/crypto/aes-riscv64-glue.c-31-\t\t\t\t const u8 *in, u8 *out, size_t len,\n--\narch/riscv/crypto/aes-riscv64-zvkned.S=96=SYM_FUNC_END(aes_ecb_decrypt_zvkned)\n--\narch/riscv/crypto/aes-riscv64-zvkned.S-137-\narch/riscv/crypto/aes-riscv64-zvkned.S:138:// void aes_cbc_encrypt_zvkned(const struct crypto_aes_ctx *key,\narch/riscv/crypto/aes-riscv64-zvkned.S-139-//\t\t\t const u8 *in, u8 *out, size_t len, u8 iv[16]);\n--\ninclude/crypto/aes-cbc.h-26- */\ninclude/crypto/aes-cbc.h:27:void aes_cbc_encrypt(u8 *dst, const u8 *src, size_t len,\ninclude/crypto/aes-cbc.h-28-\t\t u8 iv[at_least AES_BLOCK_SIZE], aes_encrypt_arg key);\n--\nlib/crypto/aes.c=853=static bool aes_cbc_decrypt_arch(u8 *dst, const u8 *src, size_t len,\n--\nlib/crypto/aes.c-860-\nlib/crypto/aes.c:861:void aes_cbc_encrypt(u8 *dst, const u8 *src, size_t len, u8 iv[AES_BLOCK_SIZE],\nlib/crypto/aes.c-862-\t\t aes_encrypt_arg key)\n"
} |
| 27/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25164 output: 35 thoughts: 44 Thoughts: Okay, here's my summary, taking the role of the expert: **Investigating AES CBC Encryption** Alright, let's dive into this. To really understand the heart of this AES CBC encryption process, my focus needs to be on how `aes_cbc_encrypt` handles the initialization vector (`iv`), the source data (`src`), and the destination buffer (`dst`). I'm going to jump straight to `lib/crypto/aes.c`, lines 861 and 870 are where the action likely is. I need to see precisely how the IV is incorporated at the beginning, how the encryption process iterates through the source data, and most importantly, how the output, the ciphertext, is written into that destination buffer. I'm looking for the details of the XOR operations, the block cipher calls, the buffer management – the whole shebang. It's the critical interplay of these three variables I need to comprehend to fully grasp the implementation. This will likely show me any potential vulnerabilities if there are any. |
| 28/3 | 2026/09/27 00:16 | tool | read-file |
0mArgs:{
"File": "lib/crypto/aes.c",
"FirstLine": 855,
"LineCount": 40
}Results: {
"Contents": " 855:\t\t\t\t\t const struct aes_key *key)\n 856:\t{\n 857:\t\treturn false;\n 858:\t}\n 859:\t#endif\n 860:\t\n 861:\tvoid aes_cbc_encrypt(u8 *dst, const u8 *src, size_t len, u8 iv[AES_BLOCK_SIZE],\n 862:\t\t\t aes_encrypt_arg key)\n 863:\t{\n 864:\t\tconst u8 *prev = iv;\n 865:\t\n 866:\t\tif (WARN_ON_ONCE(len % AES_BLOCK_SIZE))\n 867:\t\t\tlen = round_down(len, AES_BLOCK_SIZE);\n 868:\t\n 869:\t\tif (unlikely(len == 0))\n 870:\t\t\treturn;\n 871:\t\n 872:\t\tif (likely(aes_cbc_encrypt_arch(dst, src, len, iv, key.enc_key)))\n 873:\t\t\treturn;\n 874:\t\n 875:\t\tdo {\n 876:\t\t\tcrypto_xor_cpy(dst, src, prev, AES_BLOCK_SIZE);\n 877:\t\t\taes_encrypt(key, dst, dst);\n 878:\t\t\tprev = dst;\n 879:\t\t\tdst += AES_BLOCK_SIZE;\n 880:\t\t\tsrc += AES_BLOCK_SIZE;\n 881:\t\t\tlen -= AES_BLOCK_SIZE;\n 882:\t\t} while (len);\n 883:\t\tmemcpy(iv, prev, AES_BLOCK_SIZE);\n 884:\t}\n 885:\tEXPORT_SYMBOL_GPL(aes_cbc_encrypt);\n 886:\t\n 887:\tvoid aes_cbc_decrypt(u8 *dst, const u8 *src, size_t len, u8 iv[AES_BLOCK_SIZE],\n 888:\t\t\t const struct aes_key *key)\n 889:\t{\n 890:\t\tu8 next_iv[AES_BLOCK_SIZE];\n 891:\t\n 892:\t\tif (WARN_ON_ONCE(len % AES_BLOCK_SIZE))\n 893:\t\t\tlen = round_down(len, AES_BLOCK_SIZE);\n 894:\t\n"
} |
| 29/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26062 output: 35 thoughts: 600 Thoughts: **Analyzing the BPF Crypto Implementation** Okay, let's break this down. I see that `aes_cbc_encrypt` takes an `iv` of `AES_BLOCK_SIZE`, which is represented internally as `piv`. In the `bpf_crypto_crypt` function, the code retrieves `piv` using `__bpf_dynptr_data_rw` if `iv_len` is non-zero. Crucially, for CBC mode, `iv_len` *must* be `AES_BLOCK_SIZE`. The critical part is that `aes_cbc_encrypt` updates the IV in-place using `memcpy`. The code has checks for length and bounds. Specifically, it seems to ensure that: * If `iv_len != AES_BLOCK_SIZE`, it returns `-EINVAL`. * If `src_len % AES_BLOCK_SIZE || dst_len < src_len`, it also returns `-EINVAL`. For ECB mode, the check is different: * If `iv_len != 0`, it returns `-EINVAL`. * Similar to CBC, if `src_len % AES_BLOCK_SIZE || dst_len < src_len`, it returns `-EINVAL`. Now, I'm checking the `bpf_crypto_find_algo` function. This is where it gets interesting. I see a lookup table, `bpf_crypto_algos`, which maps algorithm names to enum IDs. The function compares the provided `params->type` and `params->algo` with entries in this table. The `params->type` and `params->algo` are fixed-size character arrays in the `bpf_crypto_params` struct. I need to understand how `bpf_crypto_find_algo` is called, and how it's used. Let me go back and look at the `struct bpf_crypto_params` definition to see how those fields are populated. That will tell me how well these fields are validated or sanitized. |
| 30/3 | 2026/09/27 00:16 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/crypto.c",
"FirstLine": 15,
"LineCount": 35
}Results: {
"Contents": " 15:\t * @type:\tThe string of crypto operation type.\n 16:\t * @reserved:\tReserved member, will be reused for more options in future\n 17:\t *\t\tValues:\n 18:\t *\t\t 0\n 19:\t * @algo:\tThe string of algorithm to initialize.\n 20:\t * @key:\tThe cipher key used to init crypto algorithm.\n 21:\t * @key_len:\tThe length of cipher key.\n 22:\t * @authsize:\tThe length of authentication tag used by algorithm.\n 23:\t */\n 24:\tstruct bpf_crypto_params {\n 25:\t\tchar type[14];\n 26:\t\tu8 reserved[2];\n 27:\t\tchar algo[128];\n 28:\t\tu8 key[256];\n 29:\t\tu32 key_len;\n 30:\t\tu32 authsize;\n 31:\t};\n 32:\t\n 33:\tenum bpf_crypto_algo_id {\n 34:\t\tBPF_ALGO_AES_CBC,\n 35:\t\tBPF_ALGO_AES_ECB,\n 36:\t};\n 37:\t\n 38:\tstatic const struct {\n 39:\t\tconst char *type_name;\n 40:\t\tconst char *algo_name;\n 41:\t\tenum bpf_crypto_algo_id algo;\n 42:\t} bpf_crypto_algos[] = {\n 43:\t\t{ \"skcipher\", \"cbc(aes)\", BPF_ALGO_AES_CBC },\n 44:\t\t{ \"skcipher\", \"ecb(aes)\", BPF_ALGO_AES_ECB },\n 45:\t};\n 46:\t\n 47:\tstatic bool bpf_crypto_find_algo(const struct bpf_crypto_params *params,\n 48:\t\t\t\t\t enum bpf_crypto_algo_id *id_ret)\n 49:\t{\n"
} |
| 31/3 | 2026/09/27 00:16 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27646 output: 23 thoughts: 61 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience: **Analyzing Parameter Size and String Comparison** Alright, I'm looking at this structure, specifically the `params` object. I see that the size of `params->type` is 14 bytes and `params->algo` is a much larger 128 bytes. The code then uses `strncmp` to compare something, and that function, by design, will compare a maximum of `sizeof(params->type)` bytes, which is 14 in this instance. That's immediately interesting and raises a flag. I need to understand what's being compared and why this specific size limit is in place. My next immediate thought is to check the version control history. I'll need to go to git, and find out whether there are commits that might provide additional context for this specific comparison, or maybe just look for a commit message relating to the key elements: `params`, `type` and `algo`. Often, a commit comment will tell me the story here. I want to see if this design choice – this `strncmp` with the limited size – was intentional, a potential bug, or perhaps part of a larger security consideration. This is going to be my first line of inquiry. |
| 32/3 | 2026/09/27 00:17 | tool | grepper |
0mError:no matches Args: {
"Expression": "bpf_crypto_lskcipher_type"
}Results: {
"error": "no matches"
} |
| 33/3 | 2026/09/27 00:17 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28014 output: 286 thoughts: 860 Thoughts: **Analyzing the BPF Crypto Simplification Commit**
Okay, so this commit's a pretty straightforward simplification, ditching the generic crypto API (`crypto_skcipher`) for direct AES routines (`CRYPTO_LIB_AES_CBC` and `CRYPTO_LIB_AES_ECB`) in the BPF crypto implementation. It's essentially eliminating module loading and dynamic registration, which is a good thing for performance and complexity. My immediate concern, as always, is potential memory safety issues, especially uninitialized memory reads or information leaks, since that's a common oversight in these sorts of refactors.
Let's break down the potential risks:
* **User-space exposure:** First, I checked for any kernel structures being passed to user space. Nope, the BPF kfuncs just work with BPF dynptrs, error codes, or context pointers. So that's good; no potential for uninitialized data leaking that way.
* **Conditional logic:** Next, I looked for conditional branches that might depend on uninitialized variables. Looks like everything is properly initialized. `err` gets initialized, and `ctx` is zeroed out via `kzalloc_obj`.
* **Data Structure Initialization:** I checked for complex structures where uninitialized fields could be a problem. The `ctx` is allocated using `kzalloc_obj` too, and later freed using `kfree_sensitive`, which is also good. This should handle allocation and deallocation safely.
* **Bounds Checks:** Regarding buffer overflows, `bpf_aes_cbc_crypt` and `bpf_aes_ecb_crypt` have checks for source and destination lengths, and even validate the IV length. Any buffer issues should be caught by KASAN.
I also considered KASAN vs KMSAN applicability:
* **KASAN vs KMSAN:** KASAN would catch the critical things, out-of-bounds access, use-after-free, etc. KMSAN would focus on uninitialized memory reads that might leak information.
* Since no data is copied to userspace and all variables are initialized, there's no risk of information leakage. `kzalloc_obj` takes care of all initialization. This looks like a KASAN-type issue, not a KMSAN problem.
* **Double-check requirements:** Double-checked the KMSAN rules and everything confirms this is a KASAN issue. The code changes seem primarily focused on the kinds of memory safety problems that KASAN is built for.
So, after this analysis, I'm confident in saying that `NeedsKMSAN` should be set to `false`. Time to set the results and move on.
|
| 34/3 | 2026/09/27 00:17 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch refactors BPF crypto support by replacing the dynamic skcipher crypto API registration with direct calls to kernel AES library routines (CRYPTO_LIB_AES_CBC and CRYPTO_LIB_AES_ECB). \n\nFrom a memory initialization perspective:\n- bpf_crypto_ctx is allocated using kzalloc_obj(), which zeroes all context fields prior to usage.\n- Error codes and local variables in bpf_crypto_ctx_create() and bpf_crypto_crypt() are initialized on all paths before evaluation.\n- No kernel data structures or padded structs are copied to userspace (no copy_to_user, put_user, netlink, or socket options involved).\n- Buffer and dynptr length validations are strictly checked (e.g. AES block size multiples, dst_len \u003e= src_len, exact IV size).\n- Any potential memory safety issues (such as buffer overruns during encryption/decryption or refcount/use-after-free issues with the crypto context) are squarely within the domain of KASAN rather than KMSAN.\n\nTherefore, the changes do not expose uninitialized memory risks or kernel-to-user info-leaks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch refactors BPF crypto support by replacing the dynamic skcipher crypto API registration with direct calls to kernel AES library routines (CRYPTO_LIB_AES_CBC and CRYPTO_LIB_AES_ECB). \n\nFrom a memory initialization perspective:\n- bpf_crypto_ctx is allocated using kzalloc_obj(), which zeroes all context fields prior to usage.\n- Error codes and local variables in bpf_crypto_ctx_create() and bpf_crypto_crypt() are initialized on all paths before evaluation.\n- No kernel data structures or padded structs are copied to userspace (no copy_to_user, put_user, netlink, or socket options involved).\n- Buffer and dynptr length validations are strictly checked (e.g. AES block size multiples, dst_len \u003e= src_len, exact IV size).\n- Any potential memory safety issues (such as buffer overruns during encryption/decryption or refcount/use-after-free issues with the crypto context) are squarely within the domain of KASAN rather than KMSAN.\n\nTherefore, the changes do not expose uninitialized memory risks or kernel-to-user info-leaks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|