| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/30 00:57 | flow | patch-triage |
4mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model",
"bpf_alloc_pages",
"bpf_alloc_page",
"bpf_free_pages",
"bpf_arena_alloc_pages",
"arena_alloc_pages"
],
"KMSANReasoning": "The patch series covers two main areas:\n1. BPF arena memory allocation refactoring: replacing temporary pointer arrays allocated with kmalloc_nolock() by an llist of struct pages linked via page-\u003epcp_llist (bpf_alloc_page/bpf_alloc_pages/bpf_free_pages).\n2. Kfunc descriptor table indexing for call specialization: expanding bpf_kfunc_desc_tab with krealloc to track specialized call targets alongside canonical descriptors, switching JIT lookup from sorting/bsearch to direct index-based lookups using insn-\u003eoff.\n\nKMSAN vs KASAN applicability:\n- Uninitialized memory / Info-leaks (KMSAN): All arena pages allocated through bpf_alloc_page() are explicitly zero-initialized at allocation time (alloc_pages_node uses __GFP_ZERO, and alloc_pages_nolock inherently enforces __GFP_ZERO via gfp_nolock). Stack and heap structures (such as apply_range_data and llist_head) are fully initialized before use. The new kfunc descriptors appended via krealloc in add_kfunc_desc_target() are directly copied from base descriptors that were previously zeroed via memset during bpf_add_kfunc_call(). No uninitialized data or padding is exposed or copied to user space.\n- Memory corruption / Bounds / Lifetime (KASAN): Potential bugs in this patch involve out-of-bounds indexing into tab-\u003edescs, krealloc resizing issues, linked-list corruption, or page refcount/freeing errors. These failure modes are comprehensively covered by KASAN, LOCKDEP, and page allocator debug checks.\n\nBecause there are no uninitialized memory risks or data leaks that escape KASAN detection, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies core BPF verifier, runtime fixups, and BPF arena page management. It refactors kfunc descriptor handling to support specialized kfunc call targets using direct descriptor indexing in insn-\u003eoff, and refactors arena page allocation and PTE application to use an llist instead of dynamic page arrays. It also introduces several new defensive WARN_ON_ONCE assertions in reachable code paths. These changes are in core kernel subsystems directly reachable via the bpf() syscall.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/30 00:57 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 694c679238a5443fef4587d4aa579196993b9217\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Sep 30 00:57:32 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf.h b/include/linux/bpf.h\nindex 4bae3796c42f6..eed7f8f1e4170 100644\n--- a/include/linux/bpf.h\n+++ b/include/linux/bpf.h\n@@ -2902,8 +2902,10 @@ struct bpf_map *bpf_map_get_curr_or_next(u32 *id);\n struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id);\n \n \n-int bpf_map_alloc_pages(const struct bpf_map *map, int nid,\n-\t\t\tunsigned long nr_pages, struct page **page_array);\n+struct page *bpf_alloc_page(int nid, bool sleepable);\n+int bpf_alloc_pages(int nid, unsigned long nr_pages,\n+\t\t struct llist_head *pages, bool sleepable);\n+void bpf_free_pages(struct llist_head *pages);\n #ifdef CONFIG_MEMCG\n void bpf_map_memcg_enter(const struct bpf_map *map, struct mem_cgroup **old_memcg,\n \t\t\t struct mem_cgroup **new_memcg);\n@@ -3299,7 +3301,7 @@ const struct btf_func_model *\n bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n \t\t\t const struct bpf_insn *insn);\n int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\n-\t\t u16 btf_fd_idx, u8 **func_addr);\n+\t\t u16 desc_idx, u8 **func_addr);\n \n struct bpf_core_ctx {\n \tstruct bpf_verifier_log *log;\n@@ -3642,7 +3644,7 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n \n static inline int\n bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\n-\t\t u16 btf_fd_idx, u8 **func_addr)\n+\t\t u16 desc_idx, u8 **func_addr)\n {\n \treturn -ENOTSUPP;\n }\ndiff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h\nindex c775bd7577063..7bdbda7764c77 100644\n--- a/include/linux/bpf_verifier.h\n+++ b/include/linux/bpf_verifier.h\n@@ -1784,24 +1784,29 @@ enum bpf_reg_arg_type {\n };\n \n #define MAX_KFUNC_DESCS 256\n+/* Each kfunc can have its canonical and one specialized call target. */\n+#define MAX_KFUNC_CALL_DESCS (MAX_KFUNC_DESCS * 2)\n+static_assert(MAX_KFUNC_CALL_DESCS \u003c= S16_MAX + 1);\n \n struct bpf_kfunc_desc {\n \tstruct btf_func_model func_model;\n \tstruct bpf_func_proto proto;\n \tu32 func_id;\n-\ts32 imm;\n \tu16 offset;\n \tunsigned long addr;\n };\n \n struct bpf_kfunc_desc_tab {\n \tu32 nr_descs;\n+\tu32 nr_base_descs;\n \t/* Sorted by func_id (BTF ID) and offset (fd_array offset) during\n-\t * verification. JITs do lookups by bpf_insn, where func_id may not be\n-\t * available, therefore at the end of verification do_misc_fixups()\n-\t * sorts this by imm and offset.\n+\t * verification. JITs use the descriptor index stored in the finalized\n+\t * call's off field. The first nr_base_descs entries are the canonical\n+\t * descriptors used for verifier lookups. Call specialization may append\n+\t * immutable descriptors for additional targets.\n \t *\n-\t * Grown one entry at a time by bpf_add_kfunc_call().\n+\t * Grown one entry at a time by bpf_add_kfunc_call() and during\n+\t * call specialization.\n \t */\n \tstruct bpf_kfunc_desc descs[];\n };\ndiff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c\nindex c6369ea5e2082..0ff707707da04 100644\n--- a/kernel/bpf/arena.c\n+++ b/kernel/bpf/arena.c\n@@ -146,7 +146,7 @@ static long compute_pgoff(struct bpf_arena *arena, long uaddr)\n \n struct apply_range_data {\n \tstruct bpf_arena *arena;\n-\tstruct page **pages;\n+\tstruct llist_head *pages;\n \tint i;\n };\n \n@@ -158,13 +158,17 @@ struct clear_range_data {\n static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)\n {\n \tstruct apply_range_data *d = data;\n+\tstruct llist_node *node;\n \tstruct page *page;\n \tpte_t pteval;\n \n \tif (!data)\n \t\treturn 0;\n \n-\tpage = d-\u003epages[d-\u003ei];\n+\tnode = READ_ONCE(d-\u003epages-\u003efirst);\n+\tif (WARN_ON_ONCE(!node))\n+\t\treturn -EINVAL;\n+\tpage = llist_entry(node, struct page, pcp_llist);\n \t/* paranoia, similar to vmap_pages_pte_range() */\n \tif (WARN_ON_ONCE(!pfn_valid(page_to_pfn(page))))\n \t\treturn -EINVAL;\n@@ -197,6 +201,7 @@ static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)\n \t\treturn -EBUSY;\n \tset_pte_at(\u0026init_mm, addr, pte, pteval);\n #endif\n+\tWARN_ON_ONCE(llist_del_first(d-\u003epages) != node);\n \td-\u003ei++;\n \tWRITE_ONCE(d-\u003earena-\u003enr_pages, d-\u003earena-\u003enr_pages + 1);\n \treturn 0;\n@@ -312,8 +317,8 @@ static struct bpf_map *arena_map_alloc(union bpf_attr *attr)\n \tINIT_WORK(\u0026arena-\u003efree_work, arena_free_worker);\n \tbpf_map_init_from_attr(\u0026arena-\u003emap, attr);\n \n-\terr = bpf_map_alloc_pages(\u0026arena-\u003emap, NUMA_NO_NODE, 1, \u0026arena-\u003escratch_page);\n-\tif (err)\n+\tarena-\u003escratch_page = bpf_alloc_page(NUMA_NO_NODE, true);\n+\tif (!arena-\u003escratch_page)\n \t\tgoto err_free_arena;\n \n \trange_tree_init(\u0026arena-\u003ert);\n@@ -481,7 +486,9 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)\n \tstruct bpf_map *map = vmf-\u003evma-\u003evm_file-\u003eprivate_data;\n \tstruct bpf_arena *arena = container_of(map, struct bpf_arena, map);\n \tstruct mem_cgroup *new_memcg, *old_memcg;\n+\tLLIST_HEAD(pages);\n \tstruct page *page, *new_page = NULL;\n+\tstruct apply_range_data data;\n \tvm_fault_t fault_ret;\n \tlong kbase, kaddr;\n \tunsigned long flags;\n@@ -543,8 +550,8 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)\n \t\t * The probed page was freed meanwhile or preallocation failed;\n \t\t * try the non-blocking allocator, we cannot sleep here.\n \t\t */\n-\t\tret = bpf_map_alloc_pages(map, map-\u003enuma_node, 1, \u0026new_page);\n-\t\tif (ret) {\n+\t\tnew_page = bpf_alloc_page(map-\u003enuma_node, false);\n+\t\tif (!new_page) {\n \t\t\tfault_ret = VM_FAULT_SIGBUS;\n \t\t\tgoto out_err_locked_memcg;\n \t\t}\n@@ -555,12 +562,14 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)\n \t\tfault_ret = VM_FAULT_SIGBUS;\n \t\tgoto out_err_locked_memcg;\n \t}\n-\tstruct apply_range_data data = {\n-\t\t.arena = arena, .pages = \u0026new_page, .i = 0\n-\t};\n+\tllist_add(\u0026new_page-\u003epcp_llist, \u0026pages);\n+\tdata.arena = arena;\n+\tdata.pages = \u0026pages;\n+\tdata.i = 0;\n \n \tret = apply_to_page_range(\u0026init_mm, kaddr, PAGE_SIZE, apply_range_set_cb, \u0026data);\n \tif (ret) {\n+\t\tllist_del_first(\u0026pages);\n \t\trange_tree_set(\u0026arena-\u003ert, vmf-\u003epgoff, 1);\n \t\tfault_ret = VM_FAULT_SIGBUS;\n \t\tgoto out_err_locked_memcg;\n@@ -704,6 +713,27 @@ static u64 clear_lo32(u64 val)\n \treturn val \u0026 ~(u64)~0U;\n }\n \n+static int arena_adjust_tree(struct bpf_arena *arena, long uaddr, long page_cnt, long *pgoff)\n+{\n+\tint ret;\n+\n+\t/* Special case where user is requesting specific range. */\n+\tif (uaddr) {\n+\t\tret = is_range_tree_set(\u0026arena-\u003ert, *pgoff, page_cnt);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\treturn range_tree_clear(\u0026arena-\u003ert, *pgoff, page_cnt);\n+\t}\n+\n+\tret = range_tree_find(\u0026arena-\u003ert, page_cnt);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\t*pgoff = ret;\n+\n+\treturn range_tree_clear(\u0026arena-\u003ert, *pgoff, page_cnt);\n+}\n+\n /*\n * Allocate pages and vmap them into kernel vmalloc area.\n * Later the pages will be mmaped into user space vma.\n@@ -716,13 +746,13 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt\n \tu64 kern_vm_start = bpf_arena_get_kern_vm_start(arena);\n \tstruct mem_cgroup *new_memcg, *old_memcg;\n \tstruct apply_range_data data;\n-\tstruct page **pages = NULL;\n-\tlong remaining, mapped = 0;\n-\tlong alloc_pages;\n+\tLLIST_HEAD(pages);\n+\tlong mapped = 0;\n \tunsigned long flags;\n \tlong pgoff = 0;\n \tu32 uaddr32;\n-\tint ret, i;\n+\tlong addr = 0;\n+\tint ret;\n \n \tif (node_id != NUMA_NO_NODE \u0026\u0026\n \t ((unsigned int)node_id \u003e= nr_node_ids || !node_online(node_id)))\n@@ -739,89 +769,63 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt\n \t\t\t/* requested address will be outside of user VMA */\n \t\t\treturn 0;\n \t}\n-\n \tbpf_map_memcg_enter(\u0026arena-\u003emap, \u0026old_memcg, \u0026new_memcg);\n-\t/* Cap allocation size to KMALLOC_MAX_CACHE_SIZE so kmalloc_nolock() can succeed. */\n-\talloc_pages = min(page_cnt, KMALLOC_MAX_CACHE_SIZE / sizeof(struct page *));\n-\tpages = kmalloc_nolock(alloc_pages * sizeof(struct page *), __GFP_ACCOUNT, NUMA_NO_NODE);\n-\tif (!pages) {\n-\t\tbpf_map_memcg_exit(old_memcg, new_memcg);\n-\t\treturn 0;\n-\t}\n+\n+\tret = bpf_alloc_pages(node_id, page_cnt, \u0026pages, sleepable);\n+\tif (ret)\n+\t\tgoto out_memcg;\n+\n \tdata.arena = arena;\n-\tdata.pages = pages;\n+\tdata.pages = \u0026pages;\n+\tdata.i = 0;\n \n \tif (raw_res_spin_lock_irqsave(\u0026arena-\u003espinlock, flags))\n \t\tgoto out_free_pages;\n \n-\tif (uaddr) {\n-\t\tret = is_range_tree_set(\u0026arena-\u003ert, pgoff, page_cnt);\n-\t\tif (ret)\n-\t\t\tgoto out_unlock_free_pages;\n-\t\tret = range_tree_clear(\u0026arena-\u003ert, pgoff, page_cnt);\n-\t} else {\n-\t\tret = pgoff = range_tree_find(\u0026arena-\u003ert, page_cnt);\n-\t\tif (pgoff \u003e= 0)\n-\t\t\tret = range_tree_clear(\u0026arena-\u003ert, pgoff, page_cnt);\n+\tret = arena_adjust_tree(arena, uaddr, page_cnt, \u0026pgoff);\n+\tif (ret) {\n+\t\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n+\t\tgoto out_free_pages;\n \t}\n-\tif (ret)\n-\t\tgoto out_unlock_free_pages;\n \n-\tremaining = page_cnt;\n \tuaddr32 = (u32)(arena-\u003euser_vm_start + pgoff * PAGE_SIZE);\n \n-\twhile (remaining) {\n-\t\tlong this_batch = min(remaining, alloc_pages);\n-\n-\t\t/* zeroing is needed, since alloc_pages_bulk() only fills in non-zero entries */\n-\t\tmemset(pages, 0, this_batch * sizeof(struct page *));\n+\t/*\n+\t * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1\n+\t * will not overflow 32-bit. Lower 32-bit need to represent\n+\t * contiguous user address range.\n+\t * Map these pages at kern_vm_start base.\n+\t * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow\n+\t * lower 32-bit and it's ok.\n+\t */\n+\tret = apply_to_page_range(\u0026init_mm, kern_vm_start + uaddr32,\n+\t\t\t\t page_cnt \u003c\u003c PAGE_SHIFT, apply_range_set_cb, \u0026data);\n+\tmapped = data.i;\n+\tif (ret)\n+\t\tgoto out_unmap;\n \n-\t\tret = bpf_map_alloc_pages(\u0026arena-\u003emap, node_id, this_batch, pages);\n-\t\tif (ret)\n-\t\t\tgoto out;\n+\tflush_vmap_cache(kern_vm_start + uaddr32, mapped \u003c\u003c PAGE_SHIFT);\n+\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n \n-\t\t/*\n-\t\t * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1\n-\t\t * will not overflow 32-bit. Lower 32-bit need to represent\n-\t\t * contiguous user address range.\n-\t\t * Map these pages at kern_vm_start base.\n-\t\t * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow\n-\t\t * lower 32-bit and it's ok.\n-\t\t */\n-\t\tdata.i = 0;\n-\t\tret = apply_to_page_range(\u0026init_mm,\n-\t\t\t\t\t kern_vm_start + uaddr32 + (mapped \u003c\u003c PAGE_SHIFT),\n-\t\t\t\t\t this_batch \u003c\u003c PAGE_SHIFT, apply_range_set_cb, \u0026data);\n-\t\tif (ret) {\n-\t\t\t/* data.i pages were mapped, account them and free the remaining */\n-\t\t\tmapped += data.i;\n-\t\t\tfor (i = data.i; i \u003c this_batch; i++)\n-\t\t\t\tfree_pages_nolock(pages[i], 0);\n-\t\t\tgoto out;\n-\t\t}\n+\taddr = clear_lo32(arena-\u003euser_vm_start) + uaddr32;\n+\tgoto out_memcg;\n \n-\t\tmapped += this_batch;\n-\t\tremaining -= this_batch;\n-\t}\n+out_unmap:\n+\t/* Error handling: Undo partial mappings. */\n \tflush_vmap_cache(kern_vm_start + uaddr32, mapped \u003c\u003c PAGE_SHIFT);\n-\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n-\tkfree_nolock(pages);\n-\tbpf_map_memcg_exit(old_memcg, new_memcg);\n-\treturn clear_lo32(arena-\u003euser_vm_start) + uaddr32;\n-out:\n \trange_tree_set(\u0026arena-\u003ert, pgoff + mapped, page_cnt - mapped);\n \traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n-\tif (mapped) {\n-\t\tflush_vmap_cache(kern_vm_start + uaddr32, mapped \u003c\u003c PAGE_SHIFT);\n+\tif (mapped)\n \t\tarena_free_pages(arena, uaddr32, mapped, sleepable);\n-\t}\n-\tgoto out_free_pages;\n-out_unlock_free_pages:\n-\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n+\n out_free_pages:\n-\tkfree_nolock(pages);\n+\t/* Error handling: Free back any unmapped pages. */\n+\tbpf_free_pages(\u0026pages);\n+\n+out_memcg:\n \tbpf_map_memcg_exit(old_memcg, new_memcg);\n-\treturn 0;\n+\n+\treturn addr;\n }\n \n /*\ndiff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c\nindex 37cf130ebb57b..cb7219ff68bd1 100644\n--- a/kernel/bpf/fixups.c\n+++ b/kernel/bpf/fixups.c\n@@ -5,8 +5,6 @@\n #include \u003clinux/bpf_verifier.h\u003e\n #include \u003clinux/filter.h\u003e\n #include \u003clinux/vmalloc.h\u003e\n-#include \u003clinux/bsearch.h\u003e\n-#include \u003clinux/sort.h\u003e\n #include \u003clinux/perf_event.h\u003e\n #include \u003clinux/sched/signal.h\u003e\n #include \u003cnet/xdp.h\u003e\n@@ -117,73 +115,26 @@ int bpf_insn_def32(struct bpf_prog *prog, struct bpf_insn *insn)\n \treturn dst_reg;\n }\n \n-static int kfunc_desc_cmp_by_imm_off(const void *a, const void *b)\n-{\n-\tconst struct bpf_kfunc_desc *d0 = a;\n-\tconst struct bpf_kfunc_desc *d1 = b;\n-\n-\tif (d0-\u003eimm != d1-\u003eimm)\n-\t\treturn d0-\u003eimm \u003c d1-\u003eimm ? -1 : 1;\n-\tif (d0-\u003eoffset != d1-\u003eoffset)\n-\t\treturn d0-\u003eoffset \u003c d1-\u003eoffset ? -1 : 1;\n-\treturn 0;\n-}\n-\n const struct btf_func_model *\n bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n \t\t\t const struct bpf_insn *insn)\n {\n-\tconst struct bpf_kfunc_desc desc = {\n-\t\t.imm = insn-\u003eimm,\n-\t\t.offset = insn-\u003eoff,\n-\t};\n \tconst struct bpf_kfunc_desc *res;\n \tstruct bpf_kfunc_desc_tab *tab;\n \n \ttab = prog-\u003eaux-\u003ekfunc_tab;\n-\tres = bsearch(\u0026desc, tab-\u003edescs, tab-\u003enr_descs,\n-\t\t sizeof(tab-\u003edescs[0]), kfunc_desc_cmp_by_imm_off);\n-\n-\treturn res ? \u0026res-\u003efunc_model : NULL;\n-}\n-\n-static int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)\n-{\n-\tunsigned long call_imm;\n+\tif (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs)\n+\t\treturn NULL;\n \n+\tres = \u0026tab-\u003edescs[insn-\u003eoff];\n \tif (bpf_jit_supports_far_kfunc_call()) {\n-\t\tcall_imm = desc-\u003efunc_id;\n-\t} else {\n-\t\tcall_imm = BPF_CALL_IMM(desc-\u003eaddr);\n-\t\t/* Check whether the relative offset overflows desc-\u003eimm */\n-\t\tif ((unsigned long)(s32)call_imm != call_imm) {\n-\t\t\tverbose(env, \"address of kernel func_id %u is out of range\\n\",\n-\t\t\t\tdesc-\u003efunc_id);\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\t}\n-\tdesc-\u003eimm = call_imm;\n-\treturn 0;\n-}\n-\n-static int sort_kfunc_descs_by_imm_off(struct bpf_verifier_env *env)\n-{\n-\tstruct bpf_kfunc_desc_tab *tab;\n-\tint i, err;\n-\n-\ttab = env-\u003eprog-\u003eaux-\u003ekfunc_tab;\n-\tif (!tab)\n-\t\treturn 0;\n-\n-\tfor (i = 0; i \u003c tab-\u003enr_descs; i++) {\n-\t\terr = set_kfunc_desc_imm(env, \u0026tab-\u003edescs[i]);\n-\t\tif (err)\n-\t\t\treturn err;\n+\t\tif (res-\u003efunc_id != insn-\u003eimm)\n+\t\t\treturn NULL;\n+\t} else if ((s32)BPF_CALL_IMM(res-\u003eaddr) != insn-\u003eimm) {\n+\t\treturn NULL;\n \t}\n \n-\tsort(tab-\u003edescs, tab-\u003enr_descs, sizeof(tab-\u003edescs[0]),\n-\t kfunc_desc_cmp_by_imm_off, NULL);\n-\treturn 0;\n+\treturn \u0026res-\u003efunc_model;\n }\n \n static int add_kfunc_in_insns(struct bpf_verifier_env *env,\n@@ -2720,10 +2671,6 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n \t\t}\n \t}\n \n-\tret = sort_kfunc_descs_by_imm_off(env);\n-\tif (ret)\n-\t\treturn ret;\n-\n \treturn 0;\n }\n \n@@ -2897,4 +2844,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)\n \n \treturn 0;\n }\n-\ndiff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c\nindex ac52f4ae414ce..ef8fb2f6e6e35 100644\n--- a/kernel/bpf/syscall.c\n+++ b/kernel/bpf/syscall.c\n@@ -602,38 +602,45 @@ static bool can_alloc_pages(void)\n \t\t!IS_ENABLED(CONFIG_PREEMPT_RT);\n }\n \n-static struct page *__bpf_alloc_page(int nid)\n+struct page *bpf_alloc_page(int nid, bool sleepable)\n {\n-\tif (!can_alloc_pages())\n+\tif (!sleepable || !can_alloc_pages())\n \t\treturn alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);\n \n \treturn alloc_pages_node(nid,\n \t\t\t\tGFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT\n-\t\t\t\t| __GFP_NOWARN,\n+\t\t\t\t| __GFP_NOWARN | __GFP_RETRY_MAYFAIL,\n \t\t\t\t0);\n }\n \n-int bpf_map_alloc_pages(const struct bpf_map *map, int nid,\n-\t\t\tunsigned long nr_pages, struct page **pages)\n+void bpf_free_pages(struct llist_head *pages)\n {\n-\tunsigned long i, j;\n+\tstruct llist_node *node;\n+\tstruct page *page, *tmp;\n+\n+\tnode = llist_del_all(pages);\n+\tllist_for_each_entry_safe(page, tmp, node, pcp_llist)\n+\t\tfree_pages_nolock(page, 0);\n+}\n+\n+int bpf_alloc_pages(int nid, unsigned long nr_pages,\n+\t\t struct llist_head *pages, bool sleepable)\n+{\n+\tunsigned long i;\n \tstruct page *pg;\n-\tint ret = 0;\n \n \tfor (i = 0; i \u003c nr_pages; i++) {\n-\t\tpg = __bpf_alloc_page(nid);\n-\n-\t\tif (pg) {\n-\t\t\tpages[i] = pg;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tfor (j = 0; j \u003c i; j++)\n-\t\t\tfree_pages_nolock(pages[j], 0);\n-\t\tret = -ENOMEM;\n-\t\tbreak;\n+\t\tpg = bpf_alloc_page(nid, sleepable);\n+\t\tif (!pg)\n+\t\t\tgoto free_pages;\n+\t\tllist_add(\u0026pg-\u003epcp_llist, pages);\n \t}\n \n-\treturn ret;\n+\treturn 0;\n+\n+free_pages:\n+\tbpf_free_pages(pages);\n+\treturn -ENOMEM;\n }\n \n static int btf_field_cmp(const void *a, const void *b)\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 03dbc0e003986..8ba831329ab7a 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -2579,17 +2579,21 @@ find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset)\n \tstruct bpf_kfunc_desc_tab *tab;\n \n \ttab = prog-\u003eaux-\u003ekfunc_tab;\n-\treturn bsearch(\u0026desc, tab-\u003edescs, tab-\u003enr_descs,\n+\treturn bsearch(\u0026desc, tab-\u003edescs, tab-\u003enr_base_descs,\n \t\t sizeof(tab-\u003edescs[0]), kfunc_desc_cmp_by_id_off);\n }\n \n int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\n-\t\t u16 btf_fd_idx, u8 **func_addr)\n+\t\t u16 desc_idx, u8 **func_addr)\n {\n+\tstruct bpf_kfunc_desc_tab *tab;\n \tconst struct bpf_kfunc_desc *desc;\n \n-\tdesc = find_kfunc_desc(prog, func_id, btf_fd_idx);\n-\tif (!desc)\n+\ttab = prog-\u003eaux-\u003ekfunc_tab;\n+\tif (desc_idx \u003e= tab-\u003enr_descs)\n+\t\treturn -EFAULT;\n+\tdesc = \u0026tab-\u003edescs[desc_idx];\n+\tif (desc-\u003efunc_id != func_id)\n \t\treturn -EFAULT;\n \n \t*func_addr = (u8 *)desc-\u003eaddr;\n@@ -2929,10 +2933,12 @@ int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n \tif (find_kfunc_desc(env-\u003eprog, func_id, offset))\n \t\treturn 0;\n \n-\tif (tab-\u003enr_descs == MAX_KFUNC_DESCS) {\n+\tif (tab-\u003enr_base_descs == MAX_KFUNC_DESCS) {\n \t\tverbose(env, \"too many different kernel function calls\\n\");\n \t\treturn -E2BIG;\n \t}\n+\tif (WARN_ON_ONCE(tab-\u003enr_descs != tab-\u003enr_base_descs))\n+\t\treturn -EFAULT;\n \n \terr = fetch_kfunc_meta(env, func_id, offset, \u0026kfunc);\n \tif (err)\n@@ -2990,7 +2996,8 @@ int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n \tdesc-\u003eaddr = addr;\n \tdesc-\u003efunc_model = func_model;\n \ttab-\u003enr_descs++;\n-\tsort(tab-\u003edescs, tab-\u003enr_descs, sizeof(tab-\u003edescs[0]),\n+\ttab-\u003enr_base_descs++;\n+\tsort(tab-\u003edescs, tab-\u003enr_base_descs, sizeof(tab-\u003edescs[0]),\n \t kfunc_desc_cmp_by_id_off, NULL);\n \treturn 0;\n }\n@@ -22058,6 +22065,56 @@ static int specialize_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_desc\n \treturn 0;\n }\n \n+static int add_kfunc_desc_target(struct bpf_verifier_env *env,\n+\t\t\t\t const struct bpf_kfunc_desc *target_desc,\n+\t\t\t\t u16 base_desc_idx, u16 *desc_idx)\n+{\n+\tstruct bpf_kfunc_desc desc = *target_desc;\n+\tstruct bpf_kfunc_desc_tab *new_tab;\n+\tstruct bpf_kfunc_desc_tab *tab;\n+\tstruct bpf_prog_aux *prog_aux;\n+\tu32 i;\n+\n+\tprog_aux = env-\u003eprog-\u003eaux;\n+\ttab = prog_aux-\u003ekfunc_tab;\n+\n+\tif (WARN_ON_ONCE(base_desc_idx \u003e= tab-\u003enr_base_descs))\n+\t\treturn -EFAULT;\n+\tif (WARN_ON_ONCE(tab-\u003edescs[base_desc_idx].func_id != desc.func_id ||\n+\t\t\t tab-\u003edescs[base_desc_idx].offset != desc.offset))\n+\t\treturn -EFAULT;\n+\n+\tif (tab-\u003edescs[base_desc_idx].addr == desc.addr) {\n+\t\t*desc_idx = base_desc_idx;\n+\t\treturn 0;\n+\t}\n+\n+\tfor (i = tab-\u003enr_base_descs; i \u003c tab-\u003enr_descs; i++) {\n+\t\tif (tab-\u003edescs[i].func_id == desc.func_id \u0026\u0026\n+\t\t tab-\u003edescs[i].offset == desc.offset \u0026\u0026\n+\t\t tab-\u003edescs[i].addr == desc.addr) {\n+\t\t\t*desc_idx = i;\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\tif (tab-\u003enr_descs == MAX_KFUNC_CALL_DESCS) {\n+\t\tverbose(env, \"too many different kernel function call targets\\n\");\n+\t\treturn -E2BIG;\n+\t}\n+\n+\tnew_tab = krealloc(tab, struct_size(tab, descs, tab-\u003enr_descs + 1),\n+\t\t\t GFP_KERNEL_ACCOUNT);\n+\tif (!new_tab)\n+\t\treturn -ENOMEM;\n+\ttab = new_tab;\n+\tprog_aux-\u003ekfunc_tab = tab;\n+\n+\t*desc_idx = tab-\u003enr_descs;\n+\ttab-\u003edescs[tab-\u003enr_descs++] = desc;\n+\treturn 0;\n+}\n+\n static void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,\n \t\t\t\t\t u16 struct_meta_reg,\n \t\t\t\t\t u16 node_offset_reg,\n@@ -22078,7 +22135,11 @@ static void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,\n int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n \t\t struct bpf_insn *insn_buf, int insn_idx, int *cnt)\n {\n+\tstruct bpf_kfunc_desc desc_copy;\n \tstruct bpf_kfunc_desc *desc;\n+\tunsigned long call_imm;\n+\tu16 base_desc_idx, desc_idx;\n+\tbool near_call;\n \tint err;\n \n \tif (!insn-\u003eimm) {\n@@ -22098,13 +22159,30 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n \t\t\t insn-\u003eimm);\n \t\treturn -EFAULT;\n \t}\n+\tbase_desc_idx = desc - env-\u003eprog-\u003eaux-\u003ekfunc_tab-\u003edescs;\n+\n+\tnear_call = !bpf_jit_supports_far_kfunc_call();\n+\tdesc_copy = *desc;\n+\tdesc = \u0026desc_copy;\n \n \terr = specialize_kfunc(env, desc, insn_idx);\n \tif (err)\n \t\treturn err;\n \n-\tif (!bpf_jit_supports_far_kfunc_call())\n-\t\tinsn-\u003eimm = BPF_CALL_IMM(desc-\u003eaddr);\n+\tif (near_call) {\n+\t\tcall_imm = BPF_CALL_IMM(desc-\u003eaddr);\n+\t\tif ((unsigned long)(s32)call_imm != call_imm) {\n+\t\t\tverbose(env, \"address of kernel func_id %u is out of range\\n\",\n+\t\t\t\tdesc-\u003efunc_id);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t\tinsn-\u003eimm = call_imm;\n+\t}\n+\n+\terr = add_kfunc_desc_target(env, desc, base_desc_idx, \u0026desc_idx);\n+\tif (err)\n+\t\treturn err;\n+\tinsn-\u003eoff = desc_idx;\n \n \tif (is_bpf_obj_new_kfunc(desc-\u003efunc_id) || is_bpf_percpu_obj_new_kfunc(desc-\u003efunc_id)) {\n \t\tstruct btf_struct_meta *kptr_struct_meta = env-\u003einsn_aux_data[insn_idx].kptr_struct_meta;\ndiff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c\nindex 48aae7ea0e4bb..e59c6c87e9d56 100644\n--- a/tools/testing/selftests/bpf/prog_tests/file_reader.c\n+++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c\n@@ -7,10 +7,12 @@\n #include \"file_reader_fail.skel.h\"\n #include \u003cdlfcn.h\u003e\n #include \u003csys/mman.h\u003e\n+#include \u003csys/stat.h\u003e\n \n const char *user_ptr = \"hello world\";\n char file_contents[256000];\n void *addr;\n+__u64 beyond_eof_offset;\n \n void *get_executable_base_addr(void)\n {\n@@ -26,12 +28,18 @@ void *get_executable_base_addr(void)\n \n static int initialize_file_contents(void)\n {\n+\tstruct stat st;\n \tint fd, page_sz = sysconf(_SC_PAGESIZE);\n \tssize_t n = 0, cur;\n \n \tfd = open(\"/proc/self/exe\", O_RDONLY);\n \tif (!ASSERT_OK_FD(fd, \"Open /proc/self/exe\\n\"))\n \t\treturn 1;\n+\tif (!ASSERT_OK(fstat(fd, \u0026st), \"fstat /proc/self/exe\")) {\n+\t\tclose(fd);\n+\t\treturn 1;\n+\t}\n+\tbeyond_eof_offset = st.st_size + (1ULL \u003c\u003c 30);\n \n \tdo {\n \t\tcur = read(fd, file_contents + n, sizeof(file_contents) - n);\n@@ -75,6 +83,7 @@ static void run_test(const char *prog_name)\n \n \tmemcpy(skel-\u003ebss-\u003euser_buf, file_contents, sizeof(file_contents));\n \tskel-\u003ebss-\u003epid = getpid();\n+\tskel-\u003ebss-\u003ebeyond_eof_offset = beyond_eof_offset;\n \n \terr = file_reader__load(skel);\n \tif (!ASSERT_OK(err, \"file_reader__load\"))\n@@ -110,6 +119,12 @@ void test_file_reader(void)\n \tif (test__start_subtest(\"on_open_validate_file_read\"))\n \t\trun_test(\"on_open_validate_file_read\");\n \n+\tif (test__start_subtest(\"on_open_non_sleepable_first\"))\n+\t\trun_test(\"on_open_non_sleepable_first\");\n+\n+\tif (test__start_subtest(\"on_open_sleepable_first\"))\n+\t\trun_test(\"on_open_sleepable_first\");\n+\n \tif (test__start_subtest(\"negative\"))\n \t\tRUN_TESTS(file_reader_fail);\n }\ndiff --git a/tools/testing/selftests/bpf/progs/file_reader.c b/tools/testing/selftests/bpf/progs/file_reader.c\nindex aa2c05cce2b30..8b972fd26d733 100644\n--- a/tools/testing/selftests/bpf/progs/file_reader.c\n+++ b/tools/testing/selftests/bpf/progs/file_reader.c\n@@ -27,9 +27,14 @@ char tmp_buf[256000];\n \n int pid = 0;\n int err, run_success = 0;\n+__u64 beyond_eof_offset;\n \n static int validate_file_read(struct file *file);\n static int task_work_callback(struct bpf_map *map, void *key, void *value);\n+static int sleepable_second_callback(struct bpf_map *map, void *key, void *value);\n+\n+void bpf_rcu_read_lock(void) __ksym;\n+void bpf_rcu_read_unlock(void) __ksym;\n \n SEC(\"lsm/file_open\")\n int on_open_expect_fault(void *c)\n@@ -81,6 +86,101 @@ int on_open_validate_file_read(void *c)\n \treturn 0;\n }\n \n+/*\n+ * Exercise bpf_dynptr_from_file() first from a non-sleepable LSM program and\n+ * then from its sleepable task-work callback. Reading beyond EOF makes the two\n+ * backing implementations return different errors.\n+ */\n+SEC(\"lsm/file_open\")\n+int on_open_non_sleepable_first(void *c)\n+{\n+\tstruct task_struct *task = bpf_get_current_task_btf();\n+\tstruct bpf_dynptr dynptr;\n+\tstruct elem *work;\n+\tstruct file *file;\n+\tint key = 0;\n+\tint ret;\n+\n+\tif (bpf_get_current_pid_tgid() \u003e\u003e 32 != pid)\n+\t\treturn 0;\n+\n+\tfile = bpf_get_task_exe_file(task);\n+\tif (!file) {\n+\t\terr = 1;\n+\t\treturn 0;\n+\t}\n+\n+\t/* The non-sleepable reader cannot fault in an uncached folio. */\n+\tret = bpf_dynptr_from_file(file, 0, \u0026dynptr);\n+\tif (!ret)\n+\t\tret = bpf_dynptr_read(tmp_buf, 1, \u0026dynptr, beyond_eof_offset, 0);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+\tbpf_put_file(file);\n+\tif (ret != -EFAULT) {\n+\t\terr = 2;\n+\t\treturn 0;\n+\t}\n+\n+\twork = bpf_map_lookup_elem(\u0026arrmap, \u0026key);\n+\tif (!work) {\n+\t\terr = 3;\n+\t\treturn 0;\n+\t}\n+\n+\tret = bpf_task_work_schedule_signal(task, \u0026work-\u003etw, \u0026arrmap,\n+\t\t\t\t\t sleepable_second_callback);\n+\tif (ret)\n+\t\terr = 4;\n+\treturn 0;\n+}\n+\n+/*\n+ * Exercise the opposite fixup order: the first call is made from a sleepable\n+ * LSM program, while the RCU read-side section makes the second non-sleepable.\n+ */\n+SEC(\"lsm.s/file_open\")\n+int on_open_sleepable_first(void *c)\n+{\n+\tstruct task_struct *task = bpf_get_current_task_btf();\n+\tstruct bpf_dynptr dynptr;\n+\tstruct file *file;\n+\tint ret;\n+\n+\tif (bpf_get_current_pid_tgid() \u003e\u003e 32 != pid)\n+\t\treturn 0;\n+\n+\tfile = bpf_get_task_exe_file(task);\n+\tif (!file) {\n+\t\terr = 7;\n+\t\treturn 0;\n+\t}\n+\n+\tret = bpf_dynptr_from_file(file, 0, \u0026dynptr);\n+\tif (!ret)\n+\t\tret = bpf_dynptr_read(tmp_buf, 1, \u0026dynptr, beyond_eof_offset, 0);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+\tif (ret != -EIO) {\n+\t\terr = 8;\n+\t\tgoto out;\n+\t}\n+\n+\tbpf_rcu_read_lock();\n+\tret = bpf_dynptr_from_file(file, 0, \u0026dynptr);\n+\tbpf_rcu_read_unlock();\n+\tif (!ret)\n+\t\tret = bpf_dynptr_read(tmp_buf, 1, \u0026dynptr, beyond_eof_offset, 0);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+\tif (ret != -EFAULT) {\n+\t\terr = 9;\n+\t\tgoto out;\n+\t}\n+\n+\trun_success = 1;\n+out:\n+\tbpf_put_file(file);\n+\treturn 0;\n+}\n+\n /* Called in a sleepable context, read 256K bytes, cross check with user space read data */\n static int task_work_callback(struct bpf_map *map, void *key, void *value)\n {\n@@ -97,6 +197,35 @@ static int task_work_callback(struct bpf_map *map, void *key, void *value)\n \treturn 0;\n }\n \n+/* Task-work callbacks are verified as sleepable. */\n+static int sleepable_second_callback(struct bpf_map *map, void *key, void *value)\n+{\n+\tstruct task_struct *task = bpf_get_current_task_btf();\n+\tstruct bpf_dynptr dynptr;\n+\tstruct file *file;\n+\tint ret;\n+\n+\tfile = bpf_get_task_exe_file(task);\n+\tif (!file) {\n+\t\terr = 5;\n+\t\treturn 0;\n+\t}\n+\n+\t/* freader_fetch() converts __kernel_read()'s short read at EOF to -EIO. */\n+\tret = bpf_dynptr_from_file(file, 0, \u0026dynptr);\n+\tif (!ret)\n+\t\tret = bpf_dynptr_read(tmp_buf, 1, \u0026dynptr, beyond_eof_offset, 0);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+\tbpf_put_file(file);\n+\tif (ret != -EIO) {\n+\t\terr = 6;\n+\t\treturn 0;\n+\t}\n+\n+\trun_success = 1;\n+\treturn 0;\n+}\n+\n static int verify_dynptr_read(struct bpf_dynptr *ptr, u32 off, char *user_buf, u32 len)\n {\n \tint i;\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_arena_large.c b/tools/testing/selftests/bpf/progs/verifier_arena_large.c\nindex 6ab8730d48782..dbdea14ca76f5 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_arena_large.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_arena_large.c\n@@ -10,6 +10,9 @@\n #include \u003cbpf_arena_common.h\u003e\n \n #define ARENA_SIZE (1ull \u003c\u003c 32)\n+#define LARGE_PAGE_CNT 1025\n+\n+volatile int zero = 0;\n \n struct {\n \t__uint(type, BPF_MAP_TYPE_ARENA);\n@@ -284,6 +287,7 @@ int big_alloc2(void *ctx)\n \treturn 0;\n }\n \n+/* Nonsleepable because it binds to a socket program. */\n SEC(\"socket\")\n __success __retval(0)\n int big_alloc3(void *ctx)\n@@ -291,24 +295,56 @@ int big_alloc3(void *ctx)\n #if defined(__BPF_FEATURE_ADDR_SPACE_CAST)\n \tchar __arena *pages;\n \tu64 i;\n+\tint err = 0;\n \n-\t/*\n-\t * Allocate 2051 pages in one go to check how kmalloc_nolock() handles large requests.\n-\t * Since kmalloc_nolock() can allocate up to 1024 struct page * at a time, this call should\n-\t * result in three batches: two batches of 1024 pages each, followed by a final batch of 3\n-\t * pages.\n-\t */\n-\tpages = bpf_arena_alloc_pages(\u0026arena, NULL, 2051, NUMA_NO_NODE, 0);\n+\t/* Verify that a nonsleepable allocation larger than 1024 pages succeeds. */\n+\tpages = bpf_arena_alloc_pages(\u0026arena, NULL, LARGE_PAGE_CNT, NUMA_NO_NODE, 0);\n \tif (!pages)\n-\t\treturn 0;\n+\t\treturn 1;\n+\n+\tfor (i = zero; i \u003c LARGE_PAGE_CNT \u0026\u0026 can_loop; i++)\n+\t\tpages[i * PAGE_SIZE] = 123;\n+\n+\tfor (i = zero; i \u003c LARGE_PAGE_CNT \u0026\u0026 can_loop; i++) {\n+\t\tif (pages[i * PAGE_SIZE] == 123)\n+\t\t\tcontinue;\n+\t\terr = 2;\n+\t\tbreak;\n+\t}\n+\n+\tbpf_arena_free_pages(\u0026arena, pages, LARGE_PAGE_CNT);\n+\treturn err;\n+#endif\n+\treturn 0;\n+}\n \n-\tbpf_for(i, 0, 2051)\n-\t\t\tpages[i * PAGE_SIZE] = 123;\n-\tbpf_for(i, 0, 2051)\n-\t\t\tif (pages[i * PAGE_SIZE] != 123)\n-\t\t\t\treturn i;\n+/* SYSCALL programs are always sleepable. */\n+SEC(\"syscall\")\n+__success __retval(0)\n+int big_alloc4(void *ctx)\n+{\n+#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)\n+\tchar __arena *pages;\n+\tu64 i;\n+\tint err = 0;\n+\n+\t/* Verify that a sleepable allocation larger than 1024 pages succeeds. */\n+\tpages = bpf_arena_alloc_pages(\u0026arena, NULL, LARGE_PAGE_CNT, NUMA_NO_NODE, 0);\n+\tif (!pages)\n+\t\treturn 1;\n+\n+\tfor (i = zero; i \u003c LARGE_PAGE_CNT \u0026\u0026 can_loop; i++)\n+\t\tpages[i * PAGE_SIZE] = 123;\n+\n+\tfor (i = zero; i \u003c LARGE_PAGE_CNT \u0026\u0026 can_loop; i++) {\n+\t\tif (pages[i * PAGE_SIZE] == 123)\n+\t\t\tcontinue;\n+\t\terr = 2;\n+\t\tbreak;\n+\t}\n \n-\tbpf_arena_free_pages(\u0026arena, pages, 2051);\n+\tbpf_arena_free_pages(\u0026arena, pages, LARGE_PAGE_CNT);\n+\treturn err;\n #endif\n \treturn 0;\n }\n"
} |
| 2/1 | 2026/09/30 00:57 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model",
"bpf_alloc_pages",
"bpf_alloc_page",
"bpf_free_pages",
"bpf_arena_alloc_pages",
"arena_alloc_pages"
],
"Reasoning": "The patch modifies core BPF verifier, runtime fixups, and BPF arena page management. It refactors kfunc descriptor handling to support specialized kfunc call targets using direct descriptor indexing in insn-\u003eoff, and refactors arena page allocation and PTE application to use an llist instead of dynamic page arrays. It also introduces several new defensive WARN_ON_ONCE assertions in reachable code paths. These changes are in core kernel subsystems directly reachable via the bpf() syscall.",
"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 694c679238a5443fef4587d4aa579196993b9217
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Sep 30 00:57:32 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 4bae3796c42f6..eed7f8f1e4170 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2902,8 +2902,10 @@ struct bpf_map *bpf_map_get_curr_or_next(u32 *id);
struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id);
-int bpf_map_alloc_pages(const struct bpf_map *map, int nid,
- unsigned long nr_pages, struct page **page_array);
+struct page *bpf_alloc_page(int nid, bool sleepable);
+int bpf_alloc_pages(int nid, unsigned long nr_pages,
+ struct llist_head *pages, bool sleepable);
+void bpf_free_pages(struct llist_head *pages);
#ifdef CONFIG_MEMCG
void bpf_map_memcg_enter(const struct bpf_map *map, struct mem_cgroup **old_memcg,
struct mem_cgroup **new_memcg);
@@ -3299,7 +3301,7 @@ const struct btf_func_model *
bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
const struct bpf_insn *insn);
int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,
- u16 btf_fd_idx, u8 **func_addr);
+ u16 desc_idx, u8 **func_addr);
struct bpf_core_ctx {
struct bpf_verifier_log *log;
@@ -3642,7 +3644,7 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
static inline int
bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,
- u16 btf_fd_idx, u8 **func_addr)
+ u16 desc_idx, u8 **func_addr)
{
return -ENOTSUPP;
}
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index c775bd7577063..7bdbda7764c77 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1784,24 +1784,29 @@ enum bpf_reg_arg_type {
};
#define MAX_KFUNC_DESCS 256
+/* Each kfunc can have its canonical and one specialized call target. */
+#define MAX_KFUNC_CALL_DESCS (MAX_KFUNC_DESCS * 2)
+static_assert(MAX_KFUNC_CALL_DESCS <= S16_MAX + 1);
struct bpf_kfunc_desc {
struct btf_func_model func_model;
struct bpf_func_proto proto;
u32 func_id;
- s32 imm;
u16 offset;
unsigned long addr;
};
struct bpf_kfunc_desc_tab {
u32 nr_descs;
+ u32 nr_base_descs;
/* Sorted by func_id (BTF ID) and offset (fd_array offset) during
- * verification. JITs do lookups by bpf_insn, where func_id may not be
- * available, therefore at the end of verification do_misc_fixups()
- * sorts this by imm and offset.
+ * verification. JITs use the descriptor index stored in the finalized
+ * call's off field. The first nr_base_descs entries are the canonical
+ * descriptors used for verifier lookups. Call specialization may append
+ * immutable descriptors for additional targets.
*
- * Grown one entry at a time by bpf_add_kfunc_call().
+ * Grown one entry at a time by bpf_add_kfunc_call() and during
+ * call specialization.
*/
struct bpf_kfunc_desc descs[];
};
diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
index c6369ea5e2082..0ff707707da04 100644
--- a/kernel/bpf/arena.c
+++ b/kernel/bpf/arena.c
@@ -146,7 +146,7 @@ static long compute_pgoff(struct bpf_arena *arena, long uaddr)
struct apply_range_data {
struct bpf_arena *arena;
- struct page **pages;
+ struct llist_head *pages;
int i;
};
@@ -158,13 +158,17 @@ struct clear_range_data {
static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)
{
struct apply_range_data *d = data;
+ struct llist_node *node;
struct page *page;
pte_t pteval;
if (!data)
return 0;
- page = d->pages[d->i];
+ node = READ_ONCE(d->pages->first);
+ if (WARN_ON_ONCE(!node))
+ return -EINVAL;
+ page = llist_entry(node, struct page, pcp_llist);
/* paranoia, similar to vmap_pages_pte_range() */
if (WARN_ON_ONCE(!pfn_valid(page_to_pfn(page))))
return -EINVAL;
@@ -197,6 +201,7 @@ static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)
return -EBUSY;
set_pte_at(&init_mm, addr, pte, pteval);
#endif
+ WARN_ON_ONCE(llist_del_first(d->pages) != node);
d->i++;
WRITE_ONCE(d->arena->nr_pages, d->arena->nr_pages + 1);
return 0;
@@ -312,8 +317,8 @@ static struct bpf_map *arena_map_alloc(union bpf_attr *attr)
INIT_WORK(&arena->free_work, arena_free_worker);
bpf_map_init_from_attr(&arena->map, attr);
- err = bpf_map_alloc_pages(&arena->map, NUMA_NO_NODE, 1, &arena->scratch_page);
- if (err)
+ arena->scratch_page = bpf_alloc_page(NUMA_NO_NODE, true);
+ if (!arena->scratch_page)
goto err_free_arena;
range_tree_init(&arena->rt);
@@ -481,7 +486,9 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
struct bpf_map *map = vmf->vma->vm_file->private_data;
struct bpf_arena *arena = container_of(map, struct bpf_arena, map);
struct mem_cgroup *new_memcg, *old_memcg;
+ LLIST_HEAD(pages);
struct page *page, *new_page = NULL;
+ struct apply_range_data data;
vm_fault_t fault_ret;
long kbase, kaddr;
unsigned long flags;
@@ -543,8 +550,8 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
* The probed page was freed meanwhile or preallocation failed;
* try the non-blocking allocator, we cannot sleep here.
*/
- ret = bpf_map_alloc_pages(map, map->numa_node, 1, &new_page);
- if (ret) {
+ new_page = bpf_alloc_page(map->numa_node, false);
+ if (!new_page) {
fault_ret = VM_FAULT_SIGBUS;
goto out_err_locked_memcg;
}
@@ -555,12 +562,14 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
fault_ret = VM_FAULT_SIGBUS;
goto out_err_locked_memcg;
}
- struct apply_range_data data = {
- .arena = arena, .pages = &new_page, .i = 0
- };
+ llist_add(&new_page->pcp_llist, &pages);
+ data.arena = arena;
+ data.pages = &pages;
+ data.i = 0;
ret = apply_to_page_range(&init_mm, kaddr, PAGE_SIZE, apply_range_set_cb, &data);
if (ret) {
+ llist_del_first(&pages);
range_tree_set(&arena->rt, vmf->pgoff, 1);
fault_ret = VM_FAULT_SIGBUS;
goto out_err_locked_memcg;
@@ -704,6 +713,27 @@ static u64 clear_lo32(u64 val)
return val & ~(u64)~0U;
}
+static int arena_adjust_tree(struct bpf_arena *arena, long uaddr, long page_cnt, long *pgoff)
+{
+ int ret;
+
+ /* Special case where user is requesting specific range. */
+ if (uaddr) {
+ ret = is_range_tree_set(&arena->rt, *pgoff, page_cnt);
+ if (ret)
+ return ret;
+ return range_tree_clear(&arena->rt, *pgoff, page_cnt);
+ }
+
+ ret = range_tree_find(&arena->rt, page_cnt);
+ if (ret < 0)
+ return ret;
+
+ *pgoff = ret;
+
+ return range_tree_clear(&arena->rt, *pgoff, page_cnt);
+}
+
/*
* Allocate pages and vmap them into kernel vmalloc area.
* Later the pages will be mmaped into user space vma.
@@ -716,13 +746,13 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt
u64 kern_vm_start = bpf_arena_get_kern_vm_start(arena);
struct mem_cgroup *new_memcg, *old_memcg;
struct apply_range_data data;
- struct page **pages = NULL;
- long remaining, mapped = 0;
- long alloc_pages;
+ LLIST_HEAD(pages);
+ long mapped = 0;
unsigned long flags;
long pgoff = 0;
u32 uaddr32;
- int ret, i;
+ long addr = 0;
+ int ret;
if (node_id != NUMA_NO_NODE &&
((unsigned int)node_id >= nr_node_ids || !node_online(node_id)))
@@ -739,89 +769,63 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt
/* requested address will be outside of user VMA */
return 0;
}
-
bpf_map_memcg_enter(&arena->map, &old_memcg, &new_memcg);
- /* Cap allocation size to KMALLOC_MAX_CACHE_SIZE so kmalloc_nolock() can succeed. */
- alloc_pages = min(page_cnt, KMALLOC_MAX_CACHE_SIZE / sizeof(struct page *));
- pages = kmalloc_nolock(alloc_pages * sizeof(struct page *), __GFP_ACCOUNT, NUMA_NO_NODE);
- if (!pages) {
- bpf_map_memcg_exit(old_memcg, new_memcg);
- return 0;
- }
+
+ ret = bpf_alloc_pages(node_id, page_cnt, &pages, sleepable);
+ if (ret)
+ goto out_memcg;
+
data.arena = arena;
- data.pages = pages;
+ data.pages = &pages;
+ data.i = 0;
if (raw_res_spin_lock_irqsave(&arena->spinlock, flags))
goto out_free_pages;
- if (uaddr) {
- ret = is_range_tree_set(&arena->rt, pgoff, page_cnt);
- if (ret)
- goto out_unlock_free_pages;
- ret = range_tree_clear(&arena->rt, pgoff, page_cnt);
- } else {
- ret = pgoff = range_tree_find(&arena->rt, page_cnt);
- if (pgoff >= 0)
- ret = range_tree_clear(&arena->rt, pgoff, page_cnt);
+ ret = arena_adjust_tree(arena, uaddr, page_cnt, &pgoff);
+ if (ret) {
+ raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
+ goto out_free_pages;
}
- if (ret)
- goto out_unlock_free_pages;
- remaining = page_cnt;
uaddr32 = (u32)(arena->user_vm_start + pgoff * PAGE_SIZE);
- while (remaining) {
- long this_batch = min(remaining, alloc_pages);
-
- /* zeroing is needed, since alloc_pages_bulk() only fills in non-zero entries */
- memset(pages, 0, this_batch * sizeof(struct page *));
+ /*
+ * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1
+ * will not overflow 32-bit. Lower 32-bit need to represent
+ * contiguous user address range.
+ * Map these pages at kern_vm_start base.
+ * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow
+ * lower 32-bit and it's ok.
+ */
+ ret = apply_to_page_range(&init_mm, kern_vm_start + uaddr32,
+ page_cnt << PAGE_SHIFT, apply_range_set_cb, &data);
+ mapped = data.i;
+ if (ret)
+ goto out_unmap;
- ret = bpf_map_alloc_pages(&arena->map, node_id, this_batch, pages);
- if (ret)
- goto out;
+ flush_vmap_cache(kern_vm_start + uaddr32, mapped << PAGE_SHIFT);
+ raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
- /*
- * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1
- * will not overflow 32-bit. Lower 32-bit need to represent
- * contiguous user address range.
- * Map these pages at kern_vm_start base.
- * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow
- * lower 32-bit and it's ok.
- */
- data.i = 0;
- ret = apply_to_page_range(&init_mm,
- kern_vm_start + uaddr32 + (mapped << PAGE_SHIFT),
- this_batch << PAGE_SHIFT, apply_range_set_cb, &data);
- if (ret) {
- /* data.i pages were mapped, account them and free the remaining */
- mapped += data.i;
- for (i = data.i; i < this_batch; i++)
- free_pages_nolock(pages[i], 0);
- goto out;
- }
+ addr = clear_lo32(arena->user_vm_start) + uaddr32;
+ goto out_memcg;
- mapped += this_batch;
- remaining -= this_batch;
- }
+out_unmap:
+ /* Error handling: Undo partial mappings. */
flush_vmap_cache(kern_vm_start + uaddr32, mapped << PAGE_SHIFT);
- raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
- kfree_nolock(pages);
- bpf_map_memcg_exit(old_memcg, new_memcg);
- return clear_lo32(arena->user_vm_start) + uaddr32;
-out:
range_tree_set(&arena->rt, pgoff + mapped, page_cnt - mapped);
raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
- if (mapped) {
- flush_vmap_cache(kern_vm_start + uaddr32, mapped << PAGE_SHIFT);
+ if (mapped)
arena_free_pages(arena, uaddr32, mapped, sleepable);
- }
- goto out_free_pages;
-out_unlock_free_pages:
- raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
+
out_free_pages:
- kfree_nolock(pages);
+ /* Error handling: Free back any unmapped pages. */
+ bpf_free_pages(&pages);
+
+out_memcg:
bpf_map_memcg_exit(old_memcg, new_memcg);
- return 0;
+
+ return addr;
}
/*
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 37cf130ebb57b..cb7219ff68bd1 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -5,8 +5,6 @@
#include <linux/bpf_verifier.h>
#include <linux/filter.h>
#include <linux/vmalloc.h>
-#include <linux/bsearch.h>
-#include <linux/sort.h>
#include <linux/perf_event.h>
#include <linux/sched/signal.h>
#include <net/xdp.h>
@@ -117,73 +115,26 @@ int bpf_insn_def32(struct bpf_prog *prog, struct bpf_insn *insn)
return dst_reg;
}
-static int kfunc_desc_cmp_by_imm_off(const void *a, const void *b)
-{
- const struct bpf_kfunc_desc *d0 = a;
- const struct bpf_kfunc_desc *d1 = b;
-
- if (d0->imm != d1->imm)
- return d0->imm < d1->imm ? -1 : 1;
- if (d0->offset != d1->offset)
- return d0->offset < d1->offset ? -1 : 1;
- return 0;
-}
-
const struct btf_func_model *
bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
const struct bpf_insn *insn)
{
- const struct bpf_kfunc_desc desc = {
- .imm = insn->imm,
- .offset = insn->off,
- };
const struct bpf_kfunc_desc *res;
struct bpf_kfunc_desc_tab *tab;
tab = prog->aux->kfunc_tab;
- res = bsearch(&desc, tab->descs, tab->nr_descs,
- sizeof(tab->descs[0]), kfunc_desc_cmp_by_imm_off);
-
- return res ? &res->func_model : NULL;
-}
-
-static int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)
-{
- unsigned long call_imm;
+ if (insn->off < 0 || insn->off >= tab->nr_descs)
+ return NULL;
+ res = &tab->descs[insn->off];
if (bpf_jit_supports_far_kfunc_call()) {
- call_imm = desc->func_id;
- } else {
- call_imm = BPF_CALL_IMM(desc->addr);
- /* Check whether the relative offset overflows desc->imm */
- if ((unsigned long)(s32)call_imm != call_imm) {
- verbose(env, "address of kernel func_id %u is out of range\n",
- desc->func_id);
- return -EINVAL;
- }
- }
- desc->imm = call_imm;
- return 0;
-}
-
-static int sort_kfunc_descs_by_imm_off(struct bpf_verifier_env *env)
-{
- struct bpf_kfunc_desc_tab *tab;
- int i, err;
-
- tab = env->prog->aux->kfunc_tab;
- if (!tab)
- return 0;
-
- for (i = 0; i < tab->nr_descs; i++) {
- err = set_kfunc_desc_imm(env, &tab->descs[i]);
- if (err)
- return err;
+ if (res->func_id != insn->imm)
+ return NULL;
+ } else if ((s32)BPF_CALL_IMM(res->addr) != insn->imm) {
+ return NULL;
}
- sort(tab->descs, tab->nr_descs, sizeof(tab->descs[0]),
- kfunc_desc_cmp_by_imm_off, NULL);
- return 0;
+ return &res->func_model;
}
static int add_kfunc_in_insns(struct bpf_verifier_env *env,
@@ -2720,10 +2671,6 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
}
}
- ret = sort_kfunc_descs_by_imm_off(env);
- if (ret)
- return ret;
-
return 0;
}
@@ -2897,4 +2844,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)
return 0;
}
-
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index ac52f4ae414ce..ef8fb2f6e6e35 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -602,38 +602,45 @@ static bool can_alloc_pages(void)
!IS_ENABLED(CONFIG_PREEMPT_RT);
}
-static struct page *__bpf_alloc_page(int nid)
+struct page *bpf_alloc_page(int nid, bool sleepable)
{
- if (!can_alloc_pages())
+ if (!sleepable || !can_alloc_pages())
return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);
return alloc_pages_node(nid,
GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT
- | __GFP_NOWARN,
+ | __GFP_NOWARN | __GFP_RETRY_MAYFAIL,
0);
}
-int bpf_map_alloc_pages(const struct bpf_map *map, int nid,
- unsigned long nr_pages, struct page **pages)
+void bpf_free_pages(struct llist_head *pages)
{
- unsigned long i, j;
+ struct llist_node *node;
+ struct page *page, *tmp;
+
+ node = llist_del_all(pages);
+ llist_for_each_entry_safe(page, tmp, node, pcp_llist)
+ free_pages_nolock(page, 0);
+}
+
+int bpf_alloc_pages(int nid, unsigned long nr_pages,
+ struct llist_head *pages, bool sleepable)
+{
+ unsigned long i;
struct page *pg;
- int ret = 0;
for (i = 0; i < nr_pages; i++) {
- pg = __bpf_alloc_page(nid);
-
- if (pg) {
- pages[i] = pg;
- continue;
- }
- for (j = 0; j < i; j++)
- free_pages_nolock(pages[j], 0);
- ret = -ENOMEM;
- break;
+ pg = bpf_alloc_page(nid, sleepable);
+ if (!pg)
+ goto free_pages;
+ llist_add(&pg->pcp_llist, pages);
}
- return ret;
+ return 0;
+
+free_pages:
+ bpf_free_pages(pages);
+ return -ENOMEM;
}
static int btf_field_cmp(const void *a, const void *b)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 03dbc0e003986..8ba831329ab7a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2579,17 +2579,21 @@ find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset)
struct bpf_kfunc_desc_tab *tab;
tab = prog->aux->kfunc_tab;
- return bsearch(&desc, tab->descs, tab->nr_descs,
+ return bsearch(&desc, tab->descs, tab->nr_base_descs,
sizeof(tab->descs[0]), kfunc_desc_cmp_by_id_off);
}
int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,
- u16 btf_fd_idx, u8 **func_addr)
+ u16 desc_idx, u8 **func_addr)
{
+ struct bpf_kfunc_desc_tab *tab;
const struct bpf_kfunc_desc *desc;
- desc = find_kfunc_desc(prog, func_id, btf_fd_idx);
- if (!desc)
+ tab = prog->aux->kfunc_tab;
+ if (desc_idx >= tab->nr_descs)
+ return -EFAULT;
+ desc = &tab->descs[desc_idx];
+ if (desc->func_id != func_id)
return -EFAULT;
*func_addr = (u8 *)desc->addr;
@@ -2929,10 +2933,12 @@ int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)
if (find_kfunc_desc(env->prog, func_id, offset))
return 0;
- if (tab->nr_descs == MAX_KFUNC_DESCS) {
+ if (tab->nr_base_descs == MAX_KFUNC_DESCS) {
verbose(env, "too many different kernel function calls\n");
return -E2BIG;
}
+ if (WARN_ON_ONCE(tab->nr_descs != tab->nr_base_descs))
+ return -EFAULT;
err = fetch_kfunc_meta(env, func_id, offset, &kfunc);
if (err)
@@ -2990,7 +2996,8 @@ int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)
desc->addr = addr;
desc->func_model = func_model;
tab->nr_descs++;
- sort(tab->descs, tab->nr_descs, sizeof(tab->descs[0]),
+ tab->nr_base_descs++;
+ sort(tab->descs, tab->nr_base_descs, sizeof(tab->descs[0]),
kfunc_desc_cmp_by_id_off, NULL);
return 0;
}
@@ -22058,6 +22065,56 @@ static int specialize_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_desc
return 0;
}
+static int add_kfunc_desc_target(struct bpf_verifier_env *env,
+ const struct bpf_kfunc_desc *target_desc,
+ u16 base_desc_idx, u16 *desc_idx)
+{
+ struct bpf_kfunc_desc desc = *target_desc;
+ struct bpf_kfunc_desc_tab *new_tab;
+ struct bpf_kfunc_desc_tab *tab;
+ struct bpf_prog_aux *prog_aux;
+ u32 i;
+
+ prog_aux = env->prog->aux;
+ tab = prog_aux->kfunc_tab;
+
+ if (WARN_ON_ONCE(base_desc_idx >= tab->nr_base_descs))
+ return -EFAULT;
+ if (WARN_ON_ONCE(tab->descs[base_desc_idx].func_id != desc.func_id ||
+ tab->descs[base_desc_idx].offset != desc.offset))
+ return -EFAULT;
+
+ if (tab->descs[base_desc_idx].addr == desc.addr) {
+ *desc_idx = base_desc_idx;
+ return 0;
+ }
+
+ for (i = tab->nr_base_descs; i < tab->nr_descs; i++) {
+ if (tab->descs[i].func_id == desc.func_id &&
+ tab->descs[i].offset == desc.offset &&
+ tab->descs[i].addr == desc.addr) {
+ *desc_idx = i;
+ return 0;
+ }
+ }
+
+ if (tab->nr_descs == MAX_KFUNC_CALL_DESCS) {
+ verbose(env, "too many different kernel function call targets\n");
+ return -E2BIG;
+ }
+
+ new_tab = krealloc(tab, struct_size(tab, descs, tab->nr_descs + 1),
+ GFP_KERNEL_ACCOUNT);
+ if (!new_tab)
+ return -ENOMEM;
+ tab = new_tab;
+ prog_aux->kfunc_tab = tab;
+
+ *desc_idx = tab->nr_descs;
+ tab->descs[tab->nr_descs++] = desc;
+ return 0;
+}
+
static void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,
u16 struct_meta_reg,
u16 node_offset_reg,
@@ -22078,7 +22135,11 @@ static void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,
int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
struct bpf_insn *insn_buf, int insn_idx, int *cnt)
{
+ struct bpf_kfunc_desc desc_copy;
struct bpf_kfunc_desc *desc;
+ unsigned long call_imm;
+ u16 base_desc_idx, desc_idx;
+ bool near_call;
int err;
if (!insn->imm) {
@@ -22098,13 +22159,30 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
insn->imm);
return -EFAULT;
}
+ base_desc_idx = desc - env->prog->aux->kfunc_tab->descs;
+
+ near_call = !bpf_jit_supports_far_kfunc_call();
+ desc_copy = *desc;
+ desc = &desc_copy;
err = specialize_kfunc(env, desc, insn_idx);
if (err)
return err;
- if (!bpf_jit_supports_far_kfunc_call())
- insn->imm = BPF_CALL_IMM(desc->addr);
+ if (near_call) {
+ call_imm = BPF_CALL_IMM(desc->addr);
+ if ((unsigned long)(s32)call_imm != call_imm) {
+ verbose(env, "address of kernel func_id %u is out of range\n",
+ desc->func_id);
+ return -EINVAL;
+ }
+ insn->imm = call_imm;
+ }
+
+ err = add_kfunc_desc_target(env, desc, base_desc_idx, &desc_idx);
+ if (err)
+ return err;
+ insn->off = desc_idx;
if (is_bpf_obj_new_kfunc(desc->func_id) || is_bpf_percpu_obj_new_kfunc(desc->func_id)) {
struct btf_struct_meta *kptr_struct_meta = env->insn_aux_data[insn_idx].kptr_struct_meta;
diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
index 48aae7ea0e4bb..e59c6c87e9d56 100644
--- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
+++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
@@ -7,10 +7,12 @@
#include "file_reader_fail.skel.h"
#include <dlfcn.h>
#include <sys/mman.h>
+#include <sys/stat.h>
const char *user_ptr = "hello world";
char file_contents[256000];
void *addr;
+__u64 beyond_eof_offset;
void *get_executable_base_addr(void)
{
@@ -26,12 +28,18 @@ void *get_executable_base_addr(void)
static int initialize_file_contents(void)
{
+ struct stat st;
int fd, page_sz = sysconf(_SC_PAGESIZE);
ssize_t n = 0, cur;
fd = open("/proc/self/exe", O_RDONLY);
if (!ASSERT_OK_FD(fd, "Open /proc/self/exe\n"))
return 1;
+ if (!ASSERT_OK(fstat(fd, &st), "fstat /proc/self/exe")) {
+ close(fd);
+ return 1;
+ }
+ beyond_eof_offset = st.st_size + (1ULL << 30);
do {
cur = read(fd, file_contents + n, sizeof(file_contents) - n);
@@ -75,6 +83,7 @@ static void run_test(const char *prog_name)
memcpy(skel->bss->user_buf, file_contents, sizeof(file_contents));
skel->bss->pid = getpid();
+ skel->bss->beyond_eof_offset = beyond_eof_offset;
err = file_reader__load(skel);
if (!ASSERT_OK(err, "file_reader__load"))
@@ -110,6 +119,12 @@ void test_file_reader(void)
if (test__start_subtest("on_open_validate_file_read"))
run_test("on_open_validate_file_read");
+ if (test__start_subtest("on_open_non_sleepable_first"))
+ run_test("on_open_non_sleepable_first");
+
+ if (test__start_subtest("on_open_sleepable_first"))
+ run_test("on_open_sleepable_first");
+
if (test__start_subtest("negative"))
RUN_TESTS(file_reader_fail);
}
diff --git a/tools/testing/selftests/bpf/progs/file_reader.c b/tools/testing/selftests/bpf/progs/file_reader.c
index aa2c05cce2b30..8b972fd26d733 100644
--- a/tools/testing/selftests/bpf/progs/file_reader.c
+++ b/tools/testing/selftests/bpf/progs/file_reader.c
@@ -27,9 +27,14 @@ char tmp_buf[256000];
int pid = 0;
int err, run_success = 0;
+__u64 beyond_eof_offset;
static int validate_file_read(struct file *file);
static int task_work_callback(struct bpf_map *map, void *key, void *value);
+static int sleepable_second_callback(struct bpf_map *map, void *key, void *value);
+
+void bpf_rcu_read_lock(void) __ksym;
+void bpf_rcu_read_unlock(void) __ksym;
SEC("lsm/file_open")
int on_open_expect_fault(void *c)
@@ -81,6 +86,101 @@ int on_open_validate_file_read(void *c)
return 0;
}
+/*
+ * Exercise bpf_dynptr_from_file() first from a non-sleepable LSM program and
+ * then from its sleepable task-work callback. Reading beyond EOF makes the two
+ * backing implementations return different errors.
+ */
+SEC("lsm/file_open")
+int on_open_non_sleepable_first(void *c)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct bpf_dynptr dynptr;
+ struct elem *work;
+ struct file *file;
+ int key = 0;
+ int ret;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ file = bpf_get_task_exe_file(task);
+ if (!file) {
+ err = 1;
+ return 0;
+ }
+
+ /* The non-sleepable reader cannot fault in an uncached folio. */
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ bpf_put_file(file);
+ if (ret != -EFAULT) {
+ err = 2;
+ return 0;
+ }
+
+ work = bpf_map_lookup_elem(&arrmap, &key);
+ if (!work) {
+ err = 3;
+ return 0;
+ }
+
+ ret = bpf_task_work_schedule_signal(task, &work->tw, &arrmap,
+ sleepable_second_callback);
+ if (ret)
+ err = 4;
+ return 0;
+}
+
+/*
+ * Exercise the opposite fixup order: the first call is made from a sleepable
+ * LSM program, while the RCU read-side section makes the second non-sleepable.
+ */
+SEC("lsm.s/file_open")
+int on_open_sleepable_first(void *c)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct bpf_dynptr dynptr;
+ struct file *file;
+ int ret;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ file = bpf_get_task_exe_file(task);
+ if (!file) {
+ err = 7;
+ return 0;
+ }
+
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ if (ret != -EIO) {
+ err = 8;
+ goto out;
+ }
+
+ bpf_rcu_read_lock();
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ bpf_rcu_read_unlock();
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ if (ret != -EFAULT) {
+ err = 9;
+ goto out;
+ }
+
+ run_success = 1;
+out:
+ bpf_put_file(file);
+ return 0;
+}
+
/* Called in a sleepable context, read 256K bytes, cross check with user space read data */
static int task_work_callback(struct bpf_map *map, void *key, void *value)
{
@@ -97,6 +197,35 @@ static int task_work_callback(struct bpf_map *map, void *key, void *value)
return 0;
}
+/* Task-work callbacks are verified as sleepable. */
+static int sleepable_second_callback(struct bpf_map *map, void *key, void *value)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct bpf_dynptr dynptr;
+ struct file *file;
+ int ret;
+
+ file = bpf_get_task_exe_file(task);
+ if (!file) {
+ err = 5;
+ return 0;
+ }
+
+ /* freader_fetch() converts __kernel_read()'s short read at EOF to -EIO. */
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ bpf_put_file(file);
+ if (ret != -EIO) {
+ err = 6;
+ return 0;
+ }
+
+ run_success = 1;
+ return 0;
+}
+
static int verify_dynptr_read(struct bpf_dynptr *ptr, u32 off, char *user_buf, u32 len)
{
int i;
diff --git a/tools/testing/selftests/bpf/progs/verifier_arena_large.c b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
index 6ab8730d48782..dbdea14ca76f5 100644
--- a/tools/testing/selftests/bpf/progs/verifier_arena_large.c
+++ b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
@@ -10,6 +10,9 @@
#include <bpf_arena_common.h>
#define ARENA_SIZE (1ull << 32)
+#define LARGE_PAGE_CNT 1025
+
+volatile int zero = 0;
struct {
__uint(type, BPF_MAP_TYPE_ARENA);
@@ -284,6 +287,7 @@ int big_alloc2(void *ctx)
return 0;
}
+/* Nonsleepable because it binds to a socket program. */
SEC("socket")
__success __retval(0)
int big_alloc3(void *ctx)
@@ -291,24 +295,56 @@ int big_alloc3(void *ctx)
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
char __arena *pages;
u64 i;
+ int err = 0;
- /*
- * Allocate 2051 pages in one go to check how kmalloc_nolock() handles large requests.
- * Since kmalloc_nolock() can allocate up to 1024 struct page * at a time, this call should
- * result in three batches: two batches of 1024 pages each, followed by a final batch of 3
- * pages.
- */
- pages = bpf_arena_alloc_pages(&arena, NULL, 2051, NUMA_NO_NODE, 0);
+ /* Verify that a nonsleepable allocation larger than 1024 pages succeeds. */
+ pages = bpf_arena_alloc_pages(&arena, NULL, LARGE_PAGE_CNT, NUMA_NO_NODE, 0);
if (!pages)
- return 0;
+ return 1;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++)
+ pages[i * PAGE_SIZE] = 123;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++) {
+ if (pages[i * PAGE_SIZE] == 123)
+ continue;
+ err = 2;
+ break;
+ }
+
+ bpf_arena_free_pages(&arena, pages, LARGE_PAGE_CNT);
+ return err;
+#endif
+ return 0;
+}
- bpf_for(i, 0, 2051)
- pages[i * PAGE_SIZE] = 123;
- bpf_for(i, 0, 2051)
- if (pages[i * PAGE_SIZE] != 123)
- return i;
+/* SYSCALL programs are always sleepable. */
+SEC("syscall")
+__success __retval(0)
+int big_alloc4(void *ctx)
+{
+#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
+ char __arena *pages;
+ u64 i;
+ int err = 0;
+
+ /* Verify that a sleepable allocation larger than 1024 pages succeeds. */
+ pages = bpf_arena_alloc_pages(&arena, NULL, LARGE_PAGE_CNT, NUMA_NO_NODE, 0);
+ if (!pages)
+ return 1;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++)
+ pages[i * PAGE_SIZE] = 123;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++) {
+ if (pages[i * PAGE_SIZE] == 123)
+ continue;
+ err = 2;
+ break;
+ }
- bpf_arena_free_pages(&arena, pages, 2051);
+ bpf_arena_free_pages(&arena, pages, LARGE_PAGE_CNT);
+ return err;
#endif
return 0;
}
|
| 3/2 | 2026/09/30 00:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15339 output: 33 thoughts: 1349 Thoughts: **Fuzzing Worthiness Evaluation: BPF Commit** Okay, let's dive into this. The task is to determine if this git commit is a good candidate for syzkaller fuzzing. First, I need to understand what's actually changed. It appears to be a squashed series of patches, so I'll focus on the complete diff provided. I see changes across several key BPF files: `bpf.h`, `bpf_verifier.h`, `arena.c`, `fixups.c`, `syscall.c`, `verifier.c`, and the BPF self-tests. This immediately screams "high-value target". Looking at the changes specifically, it's clear these are fundamental changes within the BPF subsystem. The core of my interest lies in the BPF arena allocation, now using `llist_head`, and the kfunc call descriptor refactoring and specialization. The arena changes refactor allocation and free logic with an `llist`, particularly in `arena.c`, with important calls in `syscall.c`. The verifier changes are touching critical pieces of the kfunc descriptor indexing logic, along with changes to how calls are added and fixed up. These are foundational changes in the BPF verifier, including calls within `fixups.c`. BPF, as a core Linux subsystem, is accessed via the `bpf()` syscall. This means that these changes are directly accessible from both unprivileged and privileged BPF programs and calls. That makes it a strong target for fuzzing. I also see several new runtime assertions (`WARN_ON_ONCE`) introduced, which are always good indicators of fuzzing opportunities because they introduce new and potentially uncovered states. For instance, the changes in `apply_range_set_cb` and the checks added in `bpf_add_kfunc_call` and `add_kfunc_desc_target` are worth checking. The guidelines for fuzzing targets seem to align perfectly with this commit: "Core Subsystems", "Refactorings and Code Cleanups", and "Runtime Assertions". The arena changes touch memory management and restructuring of data structures, and the kfunc changes alter runtime execution, all accessible via syscalls. These are exactly the types of changes that syzkaller excels at uncovering issues in. Therefore, this commit is **definitely worth fuzzing**. Now, to make this actionable, I need to flesh out the details. What configurations are needed to compile and run the code? What specific focus symbols should be targeted? Time to use `grepper` to find the BPF arena and verifier configs. I'll need to figure out which Kconfig options are required to enable these new features and then determine the most relevant functions (the WARN_ON_ONCE locations are a good starting point) to include in the focus symbols. |
| 4/2 | 2026/09/30 00:57 | tool | grepper |
0mArgs:{
"Expression": "BPF_MAP_TYPE_ARENA",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/arena.c=86=u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena)\n--\nkernel/bpf/arena.c-92- * bpf_arena_map_kern_vm_start - kern_vm_start lookup by struct bpf_map *\nkernel/bpf/arena.c:93: * @map: a BPF_MAP_TYPE_ARENA map\nkernel/bpf/arena.c-94- *\n--\nkernel/bpf/arena.c=1096=__bpf_kfunc void *bpf_arena_alloc_pages(void *p__map, void *addr__ign, u32 page_cnt,\n--\nkernel/bpf/arena.c-1101-\nkernel/bpf/arena.c:1102:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || flags || !page_cnt)\nkernel/bpf/arena.c-1103-\t\treturn NULL;\n--\nkernel/bpf/arena.c=1108=void *bpf_arena_alloc_pages_non_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\n--\nkernel/bpf/arena.c-1113-\nkernel/bpf/arena.c:1114:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || flags || !page_cnt)\nkernel/bpf/arena.c-1115-\t\treturn NULL;\n--\nkernel/bpf/arena.c=1120=void *bpf_arena_alloc_pages_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\n--\nkernel/bpf/arena.c-1125-\nkernel/bpf/arena.c:1126:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || flags || !page_cnt)\nkernel/bpf/arena.c-1127-\t\treturn NULL;\n--\nkernel/bpf/arena.c=1132=__bpf_kfunc void bpf_arena_free_pages(void *p__map, void *ptr__ign, u32 page_cnt)\n--\nkernel/bpf/arena.c-1136-\nkernel/bpf/arena.c:1137:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign)\nkernel/bpf/arena.c-1138-\t\treturn;\n--\nkernel/bpf/arena.c=1142=void bpf_arena_free_pages_non_sleepable(void *p__map, void *ptr__ign, u32 page_cnt)\n--\nkernel/bpf/arena.c-1146-\nkernel/bpf/arena.c:1147:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA || !page_cnt || !ptr__ign)\nkernel/bpf/arena.c-1148-\t\treturn;\n--\nkernel/bpf/arena.c=1152=__bpf_kfunc int bpf_arena_reserve_pages(void *p__map, void *ptr__ign, u32 page_cnt)\n--\nkernel/bpf/arena.c-1156-\nkernel/bpf/arena.c:1157:\tif (map-\u003emap_type != BPF_MAP_TYPE_ARENA)\nkernel/bpf/arena.c-1158-\t\treturn -EINVAL;\n--\nkernel/bpf/syscall.c=250=static int bpf_map_update_value(struct bpf_map *map, struct file *map_file,\n--\nkernel/bpf/syscall.c-258-\t} else if (map-\u003emap_type == BPF_MAP_TYPE_CPUMAP ||\nkernel/bpf/syscall.c:259:\t\t map-\u003emap_type == BPF_MAP_TYPE_ARENA ||\nkernel/bpf/syscall.c-260-\t\t map-\u003emap_type == BPF_MAP_TYPE_STRUCT_OPS) {\n--\nkernel/bpf/syscall.c=1401=static int map_create_alloc(union bpf_attr *attr, bpfptr_t uattr, struct bpf_verifier_log *log,\n--\nkernel/bpf/syscall.c-1438-\tif (attr-\u003emap_type != BPF_MAP_TYPE_BLOOM_FILTER \u0026\u0026\nkernel/bpf/syscall.c:1439:\t attr-\u003emap_type != BPF_MAP_TYPE_ARENA \u0026\u0026\nkernel/bpf/syscall.c-1440-\t attr-\u003emap_type != BPF_MAP_TYPE_RHASH \u0026\u0026\n--\nkernel/bpf/syscall.c-1534-\tcase BPF_MAP_TYPE_CPUMAP:\nkernel/bpf/syscall.c:1535:\tcase BPF_MAP_TYPE_ARENA:\nkernel/bpf/syscall.c-1536-\tcase BPF_MAP_TYPE_INSN_ARRAY:\n--\nkernel/bpf/verifier.c=18235=static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-18319-\t insn-\u003esrc_reg == BPF_PSEUDO_MAP_IDX_VALUE) {\nkernel/bpf/verifier.c:18320:\t\tif (map-\u003emap_type == BPF_MAP_TYPE_ARENA) {\nkernel/bpf/verifier.c-18321-\t\t\t__mark_reg_unknown(env, dst_reg);\n--\nkernel/bpf/verifier.c=19900=static int check_map_prog_compatibility(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19965-\t\tcase BPF_MAP_TYPE_STACK:\nkernel/bpf/verifier.c:19966:\t\tcase BPF_MAP_TYPE_ARENA:\nkernel/bpf/verifier.c-19967-\t\tcase BPF_MAP_TYPE_INSN_ARRAY:\n--\nkernel/bpf/verifier.c-19981-\nkernel/bpf/verifier.c:19982:\tif (map-\u003emap_type == BPF_MAP_TYPE_ARENA) {\nkernel/bpf/verifier.c-19983-\t\tif (env-\u003eprog-\u003eaux-\u003earena) {\n"
} |
| 5/2 | 2026/09/30 00:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18967 output: 27 thoughts: 25 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Investigating the BPF Compilation Process** Alright, let's dive into the kernel's BPF infrastructure. My immediate goal is to understand precisely how `arena.c` and `verifier.c` within the `kernel/bpf/` directory are getting compiled. I need to trace the build process, so the `Makefile` in that directory is the logical starting point. I want to see the specific flags and dependencies involved in generating the object files and, ultimately, integrating them into the kernel's BPF subsystem. This level of detail is crucial for debugging potential issues, optimizing build times, or even exploring custom build scenarios down the line. It's time to parse the Makefile and see what kind of compilation voodoo is happening. |
| 6/2 | 2026/09/30 00:57 | tool | grepper |
0mArgs:{
"Expression": "arena\\.o",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/Makefile=19=ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\nkernel/bpf/Makefile:20:obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o\nkernel/bpf/Makefile-21-endif\n"
} |
| 7/2 | 2026/09/30 00:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19282 output: 36 thoughts: 92 Thoughts: Okay, here's my take on those thoughts, framed from my expert perspective: **Debugging the `arena.o` Dependency** Right, so `arena.o` is acting up, and I know it's a kernel module. My first instinct is to check its dependencies. The text mentions `CONFIG_BPF_SYSCALL`, and correctly notes that it also depends on `CONFIG_MMU` (which is a given on amd64) and `CONFIG_64BIT` – essential for my work. My real focus here is the BPF angle. I'm immediately thinking about JIT (Just-In-Time compilation) and how kfunc calls might be involved. My thoughts immediately drift toward the intricacies of `bpf_jit_find_kfunc_model` and the related functions like `bpf_jit_supports_far_kfunc_call`. I need to figure out how these are interacting within the module's build process or runtime behavior. Is the JIT enabled and behaving as expected? Or is there something specific about the kfunc calls that's causing problems? Of course, `CONFIG_BPF_JIT` is right there on the surface. |
| 8/2 | 2026/09/30 00:57 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_find_kfunc_model",
"PathPrefix": "arch/x86"
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=2002=static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n--\narch/x86/net/bpf_jit_comp.c-2953-\t\t\tif (src_reg == BPF_PSEUDO_KFUNC_CALL) {\narch/x86/net/bpf_jit_comp.c:2954:\t\t\t\tfm = bpf_jit_find_kfunc_model(bpf_prog, insn);\narch/x86/net/bpf_jit_comp.c-2955-\t\t\t\tif (!fm)\n--\narch/x86/net/bpf_jit_comp32.c=1422=static u8 get_cond_jmp_opcode(const u8 op, bool is_cmp_lo)\n--\narch/x86/net/bpf_jit_comp32.c-1543- * emit_kfunc_call() finds out the btf_func_model by calling\narch/x86/net/bpf_jit_comp32.c:1544: * bpf_jit_find_kfunc_model(). A btf_func_model\narch/x86/net/bpf_jit_comp32.c-1545- * has the details about the number of args, size of each arg,\n--\narch/x86/net/bpf_jit_comp32.c=1569=static int emit_kfunc_call(const struct bpf_prog *bpf_prog, u8 *end_addr,\n--\narch/x86/net/bpf_jit_comp32.c-1580-\narch/x86/net/bpf_jit_comp32.c:1581:\tfm = bpf_jit_find_kfunc_model(bpf_prog, insn);\narch/x86/net/bpf_jit_comp32.c-1582-\tif (!fm)\n"
} |
| 9/2 | 2026/09/30 00:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20201 output: 23 thoughts: 19 Thoughts: Here's my summary, as though I'm thinking through this process: **Investigating `bpf_get_kfunc_addr` Callsites** Okay, so I need to understand where `bpf_get_kfunc_addr` is actually used within the kernel's BPF infrastructure. To get a handle on its role, the immediate next step is to pinpoint all the places where this function is being called. Essentially, I need to trace its call graph and understand the context in which it's invoked. This will give me crucial insights into its purpose and how its behavior impacts the broader system. I'll need to use my usual tools and familiarity with the source code to accomplish this. |
| 10/2 | 2026/09/30 00:57 | tool | grepper |
0mArgs:{
"Expression": "bpf_get_kfunc_addr"
}Results: {
"Output": "include/linux/bpf.h=3301=bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\ninclude/linux/bpf.h-3302-\t\t\t const struct bpf_insn *insn);\ninclude/linux/bpf.h:3303:int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\ninclude/linux/bpf.h-3304-\t\t u16 desc_idx, u8 **func_addr);\n--\ninclude/linux/bpf.h=3645=static inline int\ninclude/linux/bpf.h:3646:bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\ninclude/linux/bpf.h-3647-\t\t u16 desc_idx, u8 **func_addr)\n--\nkernel/bpf/core.c=1310=int bpf_jit_get_func_addr(const struct bpf_prog *prog,\n--\nkernel/bpf/core.c-1333-\t\t bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/core.c:1334:\t\terr = bpf_get_kfunc_addr(prog, insn-\u003eimm, insn-\u003eoff, \u0026addr);\nkernel/bpf/core.c-1335-\t\tif (err)\n--\nkernel/bpf/verifier.c=2573=find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2585-\nkernel/bpf/verifier.c:2586:int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\nkernel/bpf/verifier.c-2587-\t\t u16 desc_idx, u8 **func_addr)\n"
} |
| 11/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20902 output: 37 thoughts: 37 Thoughts: Here's my summary, as if I were thinking these thoughts: **Investigating `bpf_jit_get_func_addr`** Okay, time to dig into this. I'm going to jump straight into `kernel/bpf/core.c`, specifically around line 1330. I need to understand exactly how `bpf_jit_get_func_addr` functions. I'm assuming there's some interesting JIT magic happening in there, and I want to see how the kernel manages to translate BPF instructions to executable code and then retrieve the corresponding address. This is the crucial link between the BPF bytecode and its execution. Understanding this piece is foundational to grasping the overall BPF JIT process, and hopefully will give me a better understanding of how the function addresses are handled. Let's see what's what. |
| 12/2 | 2026/09/30 00:58 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/core.c",
"FirstLine": 1320,
"LineCount": 30
}Results: {
"Contents": "1320:\t\tif (!*func_addr_fixed) {\n1321:\t\t\t/* Place-holder address till the last pass has collected\n1322:\t\t\t * all addresses for JITed subprograms in which case we\n1323:\t\t\t * can pick them up from prog-\u003eaux.\n1324:\t\t\t */\n1325:\t\t\tif (!extra_pass)\n1326:\t\t\t\taddr = NULL;\n1327:\t\t\telse if (prog-\u003eaux-\u003efunc \u0026\u0026\n1328:\t\t\t\t off \u003e= 0 \u0026\u0026 off \u003c prog-\u003eaux-\u003ereal_func_cnt)\n1329:\t\t\t\taddr = (u8 *)prog-\u003eaux-\u003efunc[off]-\u003ebpf_func;\n1330:\t\t\telse\n1331:\t\t\t\treturn -EINVAL;\n1332:\t\t} else if (insn-\u003esrc_reg == BPF_PSEUDO_KFUNC_CALL \u0026\u0026\n1333:\t\t\t bpf_jit_supports_far_kfunc_call()) {\n1334:\t\t\terr = bpf_get_kfunc_addr(prog, insn-\u003eimm, insn-\u003eoff, \u0026addr);\n1335:\t\t\tif (err)\n1336:\t\t\t\treturn err;\n1337:\t\t} else {\n1338:\t\t\t/* Address of a BPF helper call. Since part of the core\n1339:\t\t\t * kernel, it's always at a fixed location. __bpf_call_base\n1340:\t\t\t * and the helper with imm relative to it are both in core\n1341:\t\t\t * kernel.\n1342:\t\t\t */\n1343:\t\t\taddr = (u8 *)__bpf_call_base + imm;\n1344:\t\t}\n1345:\t\n1346:\t\t*func_addr = (unsigned long)addr;\n1347:\t\treturn 0;\n1348:\t}\n1349:\t\n"
} |
| 13/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21646 output: 27 thoughts: 22 Thoughts: Okay, let's dive into this. Here's my take on understanding this `bpf_jit_supports_far_kfunc_call()` function, from an expert's perspective: **Deep Dive into `bpf_jit_supports_far_kfunc_call()`** Alright, so the first thing I'm doing is trying to figure out what `bpf_jit_supports_far_kfunc_call()` actually *does*. Given my knowledge of BPF and JIT compilation, I'm already anticipating this probably relates to the hardware's capabilities regarding indirect calls in the BPF world, specifically when calling kernel functions that might be located "far" away. 'Far' likely implies an address that might not be easily represented with a simple relative offset, or maybe even requires a different instruction encoding or addressing mode. My immediate assumptions are: 1. This function is a capability check. It will determine if the current hardware and/or BPF JIT engine can handle indirect calls to kernel functions that exist outside of a certain radius, maybe requiring a different instruction sequence. 2. "Far" is a relative term that likely depends on the specific architecture of the processor and its instruction set. It might relate to addressing limits or calling conventions. 3. The BPF JIT compiler needs to know if this capability exists to correctly optimize the BPF code. If supported, it can generate efficient indirect calls. If not, it needs to use some form of workaround, potentially impacting performance. I'm thinking this likely ties into how the JIT compiler handles relocation information, the size of addresses supported by the current architecture, and maybe specific instructions or extensions like eBPF. The function's implementation will then be key to understanding the underlying mechanism. I'm guessing that behind the scenes, it'll perform some checks on the current CPU, maybe even trying to assemble a quick test instruction to see if it works or fails. From here, I'm expecting to delve into the JIT code itself to understand the ramifications, the optimization strategies, and the potential performance trade-offs. |
| 14/2 | 2026/09/30 00:58 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_supports_far_kfunc_call"
}Results: {
"Output": "arch/loongarch/net/bpf_jit.c=263=bool bpf_jit_supports_kfunc_call(void)\n--\narch/loongarch/net/bpf_jit.c-267-\narch/loongarch/net/bpf_jit.c:268:bool bpf_jit_supports_far_kfunc_call(void)\narch/loongarch/net/bpf_jit.c-269-{\n--\narch/powerpc/net/bpf_jit_comp.c=546=bool bpf_jit_supports_arena(void)\n--\narch/powerpc/net/bpf_jit_comp.c-550-\narch/powerpc/net/bpf_jit_comp.c:551:bool bpf_jit_supports_far_kfunc_call(void)\narch/powerpc/net/bpf_jit_comp.c-552-{\n--\narch/s390/net/bpf_jit_comp.c=2475=bool bpf_jit_supports_kfunc_call(void)\n--\narch/s390/net/bpf_jit_comp.c-2479-\narch/s390/net/bpf_jit_comp.c:2480:bool bpf_jit_supports_far_kfunc_call(void)\narch/s390/net/bpf_jit_comp.c-2481-{\n--\ninclude/linux/filter.h=1248=bool bpf_jit_supports_arena_args(void);\ninclude/linux/filter.h:1249:bool bpf_jit_supports_far_kfunc_call(void);\ninclude/linux/filter.h-1250-bool bpf_jit_supports_exceptions(void);\n--\nkernel/bpf/core.c=1310=int bpf_jit_get_func_addr(const struct bpf_prog *prog,\n--\nkernel/bpf/core.c-1332-\t} else if (insn-\u003esrc_reg == BPF_PSEUDO_KFUNC_CALL \u0026\u0026\nkernel/bpf/core.c:1333:\t\t bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/core.c-1334-\t\terr = bpf_get_kfunc_addr(prog, insn-\u003eimm, insn-\u003eoff, \u0026addr);\n--\nkernel/bpf/core.c=3417=bool __weak bpf_jit_supports_arena_args(void)\n--\nkernel/bpf/core.c-3421-\nkernel/bpf/core.c:3422:bool __weak bpf_jit_supports_far_kfunc_call(void)\nkernel/bpf/core.c-3423-{\n--\nkernel/bpf/fixups.c=119=bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n--\nkernel/bpf/fixups.c-129-\tres = \u0026tab-\u003edescs[insn-\u003eoff];\nkernel/bpf/fixups.c:130:\tif (bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/fixups.c-131-\t\tif (res-\u003efunc_id != insn-\u003eimm)\n--\nkernel/bpf/verifier.c=22135=int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-22153-\t * __bpf_call_base, unless the JIT needs to call functions that are\nkernel/bpf/verifier.c:22154:\t * further than 32 bits away (bpf_jit_supports_far_kfunc_call()).\nkernel/bpf/verifier.c-22155-\t */\n--\nkernel/bpf/verifier.c-22163-\nkernel/bpf/verifier.c:22164:\tnear_call = !bpf_jit_supports_far_kfunc_call();\nkernel/bpf/verifier.c-22165-\tdesc_copy = *desc;\n"
} |
| 15/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23207 output: 36 thoughts: 644 Thoughts: **Analyzing Kfunc Call Fixups and Arena Memory Management in BPF** Okay, so I'm looking at how kfunc calls are handled in the BPF JIT, specifically on x86_64 where `bpf_jit_supports_far_kfunc_call()` is weak false, implying we're dealing with `near_call` semantics. I see that the code calls `bpf_jit_find_kfunc_model()` to locate the function model, which is interesting. Previously, I understand we were using `bsearch` on `imm` and `off`, but now `insn->off` *directly* acts as the descriptor index into `kfunc_tab`. This is a pretty significant optimization; it removes the search step and makes lookups much faster. The function model retrieval process is now a direct array access! Then I see the `bpf_fixup_kfunc_call` function. It seems to utilize `add_kfunc_desc_target` to figure out the descriptor index, assigning this calculated index to `insn->off` so subsequent calls to `bpf_jit_find_kfunc_model` will be able to efficiently find the function model. I'm also seeing significant changes in how arena memory is managed, which is likely related to this kfunc call change. In `arena.c`, `apply_range_set_cb` now operates on `struct llist_head *pages` instead of `struct page **pages`. This is crucial. I think I know where this is going... The code now leverages linked lists to manage pages within the arena. `arena_vm_fault` uses `llist_add` and calls `apply_to_page_range`. `arena_alloc_pages` calls `bpf_alloc_pages` passing a linked list, which is then used by the `apply_range_set_cb` function and uses linked list operations such as `llist_add`, `bpf_free_pages`, `llist_entry`, and `llist_del_first`. I need to understand what's happening. I need to dive deeper into how `apply_range_set_cb` uses the linked list. I see that it uses `READ_ONCE` on `d->pages->first` to obtain the first node, and uses it to obtain a page. It's clearly dealing with a linked list of pages. And the `WARN_ON_ONCE` checks are critical for detecting concurrency issues related to the linked list operations. The introduction of `arena_adjust_tree()` also piques my interest. I need to investigate that to see how memory layout is further adjusted. It seems to be a significant rework of the arena management system. Essentially, I think the goal here is to optimize kfunc call lookup by leveraging a direct index into a function descriptor table, and concurrently manage the pages used to store the code. And I need to understand what the performance impact is, of this new change. I'll read around those functions. |
| 16/2 | 2026/09/30 00:58 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/arena.c",
"FirstLine": 150,
"LineCount": 60
}Results: {
"Contents": " 150:\t\tint i;\n 151:\t};\n 152:\t\n 153:\tstruct clear_range_data {\n 154:\t\tstruct bpf_arena *arena;\n 155:\t\tstruct llist_head *free_pages;\n 156:\t};\n 157:\t\n 158:\tstatic int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)\n 159:\t{\n 160:\t\tstruct apply_range_data *d = data;\n 161:\t\tstruct llist_node *node;\n 162:\t\tstruct page *page;\n 163:\t\tpte_t pteval;\n 164:\t\n 165:\t\tif (!data)\n 166:\t\t\treturn 0;\n 167:\t\n 168:\t\tnode = READ_ONCE(d-\u003epages-\u003efirst);\n 169:\t\tif (WARN_ON_ONCE(!node))\n 170:\t\t\treturn -EINVAL;\n 171:\t\tpage = llist_entry(node, struct page, pcp_llist);\n 172:\t\t/* paranoia, similar to vmap_pages_pte_range() */\n 173:\t\tif (WARN_ON_ONCE(!pfn_valid(page_to_pfn(page))))\n 174:\t\t\treturn -EINVAL;\n 175:\t\n 176:\t\tpteval = mk_pte(page, PAGE_KERNEL);\n 177:\t#ifdef ptep_try_set\n 178:\t\t/*\n 179:\t\t * Kernel-fault recovery may have installed the scratch page here, and\n 180:\t\t * some architectures (arm64) prohibit valid-\u003evalid PTE transitions.\n 181:\t\t * Install atomically into a none slot. If scratch is present, clear it\n 182:\t\t * and flush_tlb_before_set() (break-before-make) before retrying.\n 183:\t\t */\n 184:\t\twhile (!ptep_try_set(pte, pteval)) {\n 185:\t\t\tpte_t old = ptep_get(pte);\n 186:\t\n 187:\t\t\tif (pte_none(old))\n 188:\t\t\t\tcontinue;\n 189:\t\t\tif (WARN_ON_ONCE(pte_page(old) != d-\u003earena-\u003escratch_page))\n 190:\t\t\t\treturn -EBUSY;\n 191:\t\t\tptep_get_and_clear(\u0026init_mm, addr, pte);\n 192:\t\t\tflush_tlb_before_set(addr);\n 193:\t\t}\n 194:\t#else\n 195:\t\t/*\n 196:\t\t * Without ptep_try_set() there is no atomic installer, but such arches\n 197:\t\t * also do not wire up bpf_arena_handle_page_fault(), so no scratch page\n 198:\t\t * is ever installed and the slot is always none here.\n 199:\t\t */\n 200:\t\tif (unlikely(!pte_none(ptep_get(pte))))\n 201:\t\t\treturn -EBUSY;\n 202:\t\tset_pte_at(\u0026init_mm, addr, pte, pteval);\n 203:\t#endif\n 204:\t\tWARN_ON_ONCE(llist_del_first(d-\u003epages) != node);\n 205:\t\td-\u003ei++;\n 206:\t\tWRITE_ONCE(d-\u003earena-\u003enr_pages, d-\u003earena-\u003enr_pages + 1);\n 207:\t\treturn 0;\n 208:\t}\n 209:\t\n"
} |
| 17/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25496 output: 36 thoughts: 23 Thoughts: Okay, here's my interpretation of that thought as a summary, delivered as if it's my own internal monologue: **Investigating Arena Allocation in the BPF Subsystem** Alright, I'm already deep in the BPF code, and I've got a specific issue I'm chasing. My next step is to drill down into the arena allocation mechanisms. I need to take a look at `arena_alloc_pages`, and I know it's defined within `kernel/bpf/arena.c`. That's where the core page allocation and management logic for the BPF arena resides, so that's where I need to focus my attention right now. Let's see what's going on in there. |
| 18/2 | 2026/09/30 00:58 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/arena.c",
"FirstLine": 760,
"LineCount": 80
}Results: {
"Contents": " 760:\t\n 761:\t\tif (page_cnt \u003e page_cnt_max)\n 762:\t\t\treturn 0;\n 763:\t\n 764:\t\tif (uaddr) {\n 765:\t\t\tif (uaddr \u0026 ~PAGE_MASK)\n 766:\t\t\t\treturn 0;\n 767:\t\t\tpgoff = compute_pgoff(arena, uaddr);\n 768:\t\t\tif (pgoff \u003e page_cnt_max - page_cnt)\n 769:\t\t\t\t/* requested address will be outside of user VMA */\n 770:\t\t\t\treturn 0;\n 771:\t\t}\n 772:\t\tbpf_map_memcg_enter(\u0026arena-\u003emap, \u0026old_memcg, \u0026new_memcg);\n 773:\t\n 774:\t\tret = bpf_alloc_pages(node_id, page_cnt, \u0026pages, sleepable);\n 775:\t\tif (ret)\n 776:\t\t\tgoto out_memcg;\n 777:\t\n 778:\t\tdata.arena = arena;\n 779:\t\tdata.pages = \u0026pages;\n 780:\t\tdata.i = 0;\n 781:\t\n 782:\t\tif (raw_res_spin_lock_irqsave(\u0026arena-\u003espinlock, flags))\n 783:\t\t\tgoto out_free_pages;\n 784:\t\n 785:\t\tret = arena_adjust_tree(arena, uaddr, page_cnt, \u0026pgoff);\n 786:\t\tif (ret) {\n 787:\t\t\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n 788:\t\t\tgoto out_free_pages;\n 789:\t\t}\n 790:\t\n 791:\t\tuaddr32 = (u32)(arena-\u003euser_vm_start + pgoff * PAGE_SIZE);\n 792:\t\n 793:\t\t/*\n 794:\t\t * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1\n 795:\t\t * will not overflow 32-bit. Lower 32-bit need to represent\n 796:\t\t * contiguous user address range.\n 797:\t\t * Map these pages at kern_vm_start base.\n 798:\t\t * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow\n 799:\t\t * lower 32-bit and it's ok.\n 800:\t\t */\n 801:\t\tret = apply_to_page_range(\u0026init_mm, kern_vm_start + uaddr32,\n 802:\t\t\t\t\t page_cnt \u003c\u003c PAGE_SHIFT, apply_range_set_cb, \u0026data);\n 803:\t\tmapped = data.i;\n 804:\t\tif (ret)\n 805:\t\t\tgoto out_unmap;\n 806:\t\n 807:\t\tflush_vmap_cache(kern_vm_start + uaddr32, mapped \u003c\u003c PAGE_SHIFT);\n 808:\t\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n 809:\t\n 810:\t\taddr = clear_lo32(arena-\u003euser_vm_start) + uaddr32;\n 811:\t\tgoto out_memcg;\n 812:\t\n 813:\tout_unmap:\n 814:\t\t/* Error handling: Undo partial mappings. */\n 815:\t\tflush_vmap_cache(kern_vm_start + uaddr32, mapped \u003c\u003c PAGE_SHIFT);\n 816:\t\trange_tree_set(\u0026arena-\u003ert, pgoff + mapped, page_cnt - mapped);\n 817:\t\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n 818:\t\tif (mapped)\n 819:\t\t\tarena_free_pages(arena, uaddr32, mapped, sleepable);\n 820:\t\n 821:\tout_free_pages:\n 822:\t\t/* Error handling: Free back any unmapped pages. */\n 823:\t\tbpf_free_pages(\u0026pages);\n 824:\t\n 825:\tout_memcg:\n 826:\t\tbpf_map_memcg_exit(old_memcg, new_memcg);\n 827:\t\n 828:\t\treturn addr;\n 829:\t}\n 830:\t\n 831:\t/*\n 832:\t * If page is present in vmalloc area, unmap it from vmalloc area,\n 833:\t * unmap it from all user space vma-s,\n 834:\t * and free it.\n 835:\t */\n 836:\tstatic void zap_pages(struct bpf_arena *arena, long uaddr, long page_cnt)\n 837:\t{\n 838:\t\tunsigned long size = (unsigned long)page_cnt \u003c\u003c PAGE_SHIFT;\n 839:\t\tstruct vm_area_struct *vma;\n"
} |
| 19/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27023 output: 38 thoughts: 38 Thoughts: Here's a summary of my thought process: **Diving into the BPF Verifier for KFunc Analysis** Okay, so I need to understand how kernel functions (kfuncs) are handled in the BPF verifier. Let's start by looking at the code. I'm going to focus on `kernel/bpf/verifier.c`, specifically around the functions that are responsible for adding and handling the descriptions of kfunc targets and the fixup process. I'm thinking I need to understand how the verifier *learns* about these kfuncs, and how it then ensures they're called correctly. So, `add_kfunc_desc_target` has to be a critical piece, and then, naturally, `bpf_fixup_kfunc_call` is going to be the function that corrects things during the load process, so I'll be sure to dig into both. Hopefully, those two functions together give me the answers I need about the whole control flow, how the kfunc addresses are handled at run time, and how the safety guarantees work with these calls. |
| 20/2 | 2026/09/30 00:58 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 22060,
"LineCount": 80
}Results: {
"Contents": "22060:\t\t} else if (func_id == special_kfunc_list[KF_bpf_arena_free_pages]) {\n22061:\t\t\tif (env-\u003einsn_aux_data[insn_idx].non_sleepable)\n22062:\t\t\t\taddr = (unsigned long)bpf_arena_free_pages_non_sleepable;\n22063:\t\t}\n22064:\t\tdesc-\u003eaddr = addr;\n22065:\t\treturn 0;\n22066:\t}\n22067:\t\n22068:\tstatic int add_kfunc_desc_target(struct bpf_verifier_env *env,\n22069:\t\t\t\t\t const struct bpf_kfunc_desc *target_desc,\n22070:\t\t\t\t\t u16 base_desc_idx, u16 *desc_idx)\n22071:\t{\n22072:\t\tstruct bpf_kfunc_desc desc = *target_desc;\n22073:\t\tstruct bpf_kfunc_desc_tab *new_tab;\n22074:\t\tstruct bpf_kfunc_desc_tab *tab;\n22075:\t\tstruct bpf_prog_aux *prog_aux;\n22076:\t\tu32 i;\n22077:\t\n22078:\t\tprog_aux = env-\u003eprog-\u003eaux;\n22079:\t\ttab = prog_aux-\u003ekfunc_tab;\n22080:\t\n22081:\t\tif (WARN_ON_ONCE(base_desc_idx \u003e= tab-\u003enr_base_descs))\n22082:\t\t\treturn -EFAULT;\n22083:\t\tif (WARN_ON_ONCE(tab-\u003edescs[base_desc_idx].func_id != desc.func_id ||\n22084:\t\t\t\t tab-\u003edescs[base_desc_idx].offset != desc.offset))\n22085:\t\t\treturn -EFAULT;\n22086:\t\n22087:\t\tif (tab-\u003edescs[base_desc_idx].addr == desc.addr) {\n22088:\t\t\t*desc_idx = base_desc_idx;\n22089:\t\t\treturn 0;\n22090:\t\t}\n22091:\t\n22092:\t\tfor (i = tab-\u003enr_base_descs; i \u003c tab-\u003enr_descs; i++) {\n22093:\t\t\tif (tab-\u003edescs[i].func_id == desc.func_id \u0026\u0026\n22094:\t\t\t tab-\u003edescs[i].offset == desc.offset \u0026\u0026\n22095:\t\t\t tab-\u003edescs[i].addr == desc.addr) {\n22096:\t\t\t\t*desc_idx = i;\n22097:\t\t\t\treturn 0;\n22098:\t\t\t}\n22099:\t\t}\n22100:\t\n22101:\t\tif (tab-\u003enr_descs == MAX_KFUNC_CALL_DESCS) {\n22102:\t\t\tverbose(env, \"too many different kernel function call targets\\n\");\n22103:\t\t\treturn -E2BIG;\n22104:\t\t}\n22105:\t\n22106:\t\tnew_tab = krealloc(tab, struct_size(tab, descs, tab-\u003enr_descs + 1),\n22107:\t\t\t\t GFP_KERNEL_ACCOUNT);\n22108:\t\tif (!new_tab)\n22109:\t\t\treturn -ENOMEM;\n22110:\t\ttab = new_tab;\n22111:\t\tprog_aux-\u003ekfunc_tab = tab;\n22112:\t\n22113:\t\t*desc_idx = tab-\u003enr_descs;\n22114:\t\ttab-\u003edescs[tab-\u003enr_descs++] = desc;\n22115:\t\treturn 0;\n22116:\t}\n22117:\t\n22118:\tstatic void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,\n22119:\t\t\t\t\t\t u16 struct_meta_reg,\n22120:\t\t\t\t\t\t u16 node_offset_reg,\n22121:\t\t\t\t\t\t struct bpf_insn *insn,\n22122:\t\t\t\t\t\t struct bpf_insn *insn_buf,\n22123:\t\t\t\t\t\t int *cnt)\n22124:\t{\n22125:\t\tstruct btf_struct_meta *kptr_struct_meta = insn_aux-\u003ekptr_struct_meta;\n22126:\t\tstruct bpf_insn addr[2] = { BPF_LD_IMM64(struct_meta_reg, (long)kptr_struct_meta) };\n22127:\t\n22128:\t\tinsn_buf[0] = addr[0];\n22129:\t\tinsn_buf[1] = addr[1];\n22130:\t\tinsn_buf[2] = BPF_MOV64_IMM(node_offset_reg, insn_aux-\u003einsert_off);\n22131:\t\tinsn_buf[3] = *insn;\n22132:\t\t*cnt = 4;\n22133:\t}\n22134:\t\n22135:\tint bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n22136:\t\t\t struct bpf_insn *insn_buf, int insn_idx, int *cnt)\n22137:\t{\n22138:\t\tstruct bpf_kfunc_desc desc_copy;\n22139:\t\tstruct bpf_kfunc_desc *desc;\n"
} |
| 21/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28837 output: 31 thoughts: 350 Thoughts: **Analyzing BPF Kfunc Calls and Memory Management** Okay, let's break this down. My initial scan has highlighted several key functions. `bpf_fixup_kfunc_call` and `add_kfunc_desc_target` are triggered during the verification phase – those are important for understanding how kfunc calls are handled during the misc fixups process. Then we've got the memory allocation functions: `bpf_alloc_pages`, `bpf_free_pages`, and `bpf_alloc_page` residing in `syscall.c` and the arena allocator implementations: `arena_alloc_pages`, `arena_vm_fault`, `apply_range_set_cb`, and `arena_adjust_tree` in `arena.c`. We also have `bpf_jit_find_kfunc_model` which deals with the JIT side in `fixups.c`. Finally `bpf_get_kfunc_addr` is called in the verifier. Now, let's pivot to the configuration side. I need to nail down the dependencies for the verifier, arena allocator, and kfunc functionality. First, `BPF_SYSCALL` is a good starting point. I can see in `init/Kconfig` that it depends on `BPF`, which is expected. But the arena seems to have additional requirements. The `Makefile` in `kernel/bpf/` has a conditional for the arena based on `CONFIG_MMU` and `CONFIG_64BIT` being enabled. That makes sense from a memory management perspective. If we want JIT kfunc calls, we'll need `CONFIG_BPF_JIT`. I need to quickly scan to see if there are any other configuration dependencies. |
| 22/2 | 2026/09/30 00:58 | tool | grepper |
0mArgs:{
"Expression": "config BPF_",
"PathPrefix": "kernel/bpf/Kconfig"
}Results: {
"Output": "kernel/bpf/Kconfig=29=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-30-\nkernel/bpf/Kconfig:31:config BPF_SYSCALL\nkernel/bpf/Kconfig-32-\tbool \"Enable bpf() system call\"\n--\nkernel/bpf/Kconfig-45-\nkernel/bpf/Kconfig:46:config BPF_JIT\nkernel/bpf/Kconfig-47-\tbool \"Enable BPF Just In Time compiler\"\n--\nkernel/bpf/Kconfig-61-\nkernel/bpf/Kconfig:62:config BPF_JIT_ALWAYS_ON\nkernel/bpf/Kconfig-63-\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n--\nkernel/bpf/Kconfig-72-\nkernel/bpf/Kconfig:73:config BPF_JIT_DEFAULT_ON\nkernel/bpf/Kconfig-74-\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n--\nkernel/bpf/Kconfig-76-\nkernel/bpf/Kconfig:77:config BPF_UNPRIV_DEFAULT_OFF\nkernel/bpf/Kconfig-78-\tbool \"Disable unprivileged BPF by default\"\n--\nkernel/bpf/Kconfig-93-\nkernel/bpf/Kconfig:94:config BPF_CRYPTO\nkernel/bpf/Kconfig-95-\tdef_bool y\n--\nkernel/bpf/Kconfig=103=source \"kernel/bpf/preload/Kconfig\"\nkernel/bpf/Kconfig-104-\nkernel/bpf/Kconfig:105:config BPF_LSM\nkernel/bpf/Kconfig-106-\tbool \"Enable BPF LSM Instrumentation\"\n--\nkernel/bpf/Kconfig-116-\nkernel/bpf/Kconfig:117:config BPF_JIT_KASAN\nkernel/bpf/Kconfig-118-\tbool\n"
} |
| 23/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30112 output: 32 thoughts: 39 Thoughts: Okay, here's my interpretation of those thoughts, summarized from an expert's perspective: **Investigating BTF and Kfuncs** Alright, let's circle back to this `DEBUG_INFO_BTF` concept. We're talking about kfuncs here, and I seem to recall something about them needing BTF support. Just to be absolutely sure, I need to confirm that my understanding is correct. Specifically, I'm thinking, "Do kfuncs actually *require* BTF (and therefore `CONFIG_DEBUG_INFO_BTF`) to function correctly?" It's a key dependency, and I need to solidify this link in my mind, and perhaps document it so it's fresh in my memory. |
| 24/2 | 2026/09/30 00:58 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_DEBUG_INFO_BTF",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/Makefile=43=ifeq ($(CONFIG_SYSFS),y)\nkernel/bpf/Makefile:44:obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\nkernel/bpf/Makefile-45-endif\n--\nkernel/bpf/btf.c=6776=static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name,\n--\nkernel/bpf/btf.c-6781-\nkernel/bpf/btf.c:6782:\tif (!IS_ENABLED(CONFIG_DEBUG_INFO_BTF))\nkernel/bpf/btf.c-6783-\t\treturn ERR_PTR(-ENOENT);\n--\nkernel/bpf/btf.c=6862=__u32 btf_relocate_id(const struct btf *btf, __u32 id)\n--\nkernel/bpf/btf.c-6868-\nkernel/bpf/btf.c:6869:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-6870-\nkernel/bpf/btf.c=6871=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-6966-\nkernel/bpf/btf.c:6967:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-6968-\n--\nkernel/bpf/btf.c=8947=enum {\n--\nkernel/bpf/btf.c-8950-\nkernel/bpf/btf.c:8951:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8952-struct btf_module {\n--\nkernel/bpf/btf.c=9089=fs_initcall(btf_module_init);\nkernel/bpf/btf.c:9090:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-9091-\nkernel/bpf/btf.c=9092=struct module *btf_try_get_module(const struct btf *btf)\n--\nkernel/bpf/btf.c-9094-\tstruct module *res = NULL;\nkernel/bpf/btf.c:9095:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9096-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c=9122=struct btf *btf_get_module_btf(const struct module *module)\nkernel/bpf/btf.c-9123-{\nkernel/bpf/btf.c:9124:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9125-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-9135-\nkernel/bpf/btf.c:9136:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9137-\tmutex_lock(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9152=static int check_btf_kconfigs(const struct module *module, const char *feature)\nkernel/bpf/btf.c-9153-{\nkernel/bpf/btf.c:9154:\tif (!module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/btf.c-9155-\t\tpr_err(\"missing vmlinux BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c-9157-\t}\nkernel/bpf/btf.c:9158:\tif (module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))\nkernel/bpf/btf.c-9159-\t\tpr_warn(\"missing module BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c=9300=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\nkernel/bpf/btf.c-9301-{\nkernel/bpf/btf.c:9302:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9303-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-9316-\nkernel/bpf/btf.c:9317:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9318-\tguard(mutex)(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9965=static struct bpf_cand_cache *populate_cand_cache(struct bpf_cand_cache *cands,\n--\nkernel/bpf/btf.c-9992-\nkernel/bpf/btf.c:9993:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9994-static void __purge_cand_cache(struct btf *btf, struct bpf_cand_cache **cache,\n--\nkernel/bpf/verifier.c=2873=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2889-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:2890:\t\t\tverbose(env, \"calling kernel function is not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-2891-\t\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=6508=static int check_ptr_to_map_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6522-\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:6523:\t\tverbose(env, \"map_ptr access not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-6524-\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=19847=static int check_pseudo_btf_id(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19863-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:19864:\t\t\tverbose(env, \"kernel is missing BTF, make sure CONFIG_DEBUG_INFO_BTF=y is specified in Kconfig.\\n\");\nkernel/bpf/verifier.c-19865-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c=21899=struct btf *bpf_get_btf_vmlinux(void)\n--\nkernel/bpf/verifier.c-21903-\nkernel/bpf/verifier.c:21904:\tif (!btf \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/verifier.c-21905-\t\tmutex_lock(\u0026btf_vmlinux_lock);\n"
} |
| 25/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32290 output: 33 thoughts: 144 Thoughts: **My Immediate Thoughts on This Code Snippet** Okay, so I see a warning: `"calling kernel function is not supported without CONFIG_DEBUG_INFO_BTF"`. Right, so this confirms what I suspected about `kfuncs`: they *absolutely* require `CONFIG_DEBUG_INFO_BTF`. And the same applies to `BPF_SYSCALL` and `BPF_JIT`, I'll keep that in mind. Now, my next step is to get the lay of the land, understand what's changed and figure out the impact. I need to identify the `FocusSymbols` within this patch. Essentially, which symbols are being modified or introduced? Let's see… scanning the code. Ah, from `kernel/bpf/arena.c`: I see `arena_alloc_pages`. Wait... Is that symbol declared static? I'll need to check the declaration of `arena_alloc_pages` carefully because if it's static it will impact how it's used. I need to know *who* calls `arena_alloc_pages`. |
| 26/2 | 2026/09/30 00:58 | tool | grepper |
0mArgs:{
"Expression": "arena_alloc_pages",
"PathPrefix": "kernel/bpf/arena.c"
}Results: {
"Output": "kernel/bpf/arena.c-39- * into kernel and user vma.\nkernel/bpf/arena.c:40: * bpf program can allocate a page via bpf_arena_alloc_pages() kfunc\nkernel/bpf/arena.c-41- * which will insert it into kernel vm_area.\n--\nkernel/bpf/arena.c=716=static int arena_adjust_tree(struct bpf_arena *arena, long uaddr, long page_cnt, long *pgoff)\n--\nkernel/bpf/arena.c-740- */\nkernel/bpf/arena.c:741:static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt, int node_id,\nkernel/bpf/arena.c-742-\t\t\t bool sleepable)\n--\nkernel/bpf/arena.c=894=static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt, bool sleepable)\n--\nkernel/bpf/arena.c-983- * Reserve an arena virtual address range without populating it. This call stops\nkernel/bpf/arena.c:984: * bpf_arena_alloc_pages from adding pages to this range.\nkernel/bpf/arena.c-985- */\n--\nkernel/bpf/arena.c=1094=__bpf_kfunc_start_defs();\nkernel/bpf/arena.c-1095-\nkernel/bpf/arena.c:1096:__bpf_kfunc void *bpf_arena_alloc_pages(void *p__map, void *addr__ign, u32 page_cnt,\nkernel/bpf/arena.c-1097-\t\t\t\t\tint node_id, u64 flags)\n--\nkernel/bpf/arena.c-1104-\nkernel/bpf/arena.c:1105:\treturn (void *)arena_alloc_pages(arena, (long)addr__ign, page_cnt, node_id, true);\nkernel/bpf/arena.c-1106-}\nkernel/bpf/arena.c-1107-\nkernel/bpf/arena.c:1108:void *bpf_arena_alloc_pages_non_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\nkernel/bpf/arena.c-1109-\t\t\t\t\t int node_id, u64 flags)\n--\nkernel/bpf/arena.c-1116-\nkernel/bpf/arena.c:1117:\treturn (void *)arena_alloc_pages(arena, (long)addr__ign, page_cnt, node_id, false);\nkernel/bpf/arena.c-1118-}\nkernel/bpf/arena.c-1119-\nkernel/bpf/arena.c:1120:void *bpf_arena_alloc_pages_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\nkernel/bpf/arena.c-1121-\t\t\t\t int node_id, u64 flags)\n--\nkernel/bpf/arena.c-1128-\nkernel/bpf/arena.c:1129:\treturn (void *)arena_alloc_pages(arena, (long)addr__ign, page_cnt, node_id, true);\nkernel/bpf/arena.c-1130-}\n--\nkernel/bpf/arena.c=1167=BTF_KFUNCS_START(arena_kfuncs)\nkernel/bpf/arena.c:1168:BTF_ID_FLAGS(func, bpf_arena_alloc_pages, KF_ARENA_RET | KF_ARENA_ARG2 | KF_SPINLOCK_SAFE)\nkernel/bpf/arena.c-1169-BTF_ID_FLAGS(func, bpf_arena_free_pages, KF_ARENA_ARG2 | KF_SPINLOCK_SAFE)\n"
} |
| 27/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33706 output: 28 thoughts: 1426 Thoughts: **Focusing on BPF Functionality for Fuzzing** Alright, let's break this down. My goal is to identify the most suitable functions within the BPF subsystem to target with a fuzzer, keeping in mind the need to avoid "ubiquitous lifecycle hot-paths" and instead pinpoint specific feature logic and entrypoints, as per the established guidelines. First, I see several potentially interesting functions scattered across `kernel/bpf/arena.c`, `kernel/bpf/syscall.c`, `kernel/bpf/fixups.c`, and `kernel/bpf/verifier.c`. Specifically, I've noted down: `bpf_arena_alloc_pages`, `bpf_arena_alloc_pages_non_sleepable`, `bpf_arena_alloc_pages_sleepable`, `arena_vm_fault`, `arena_map_alloc`, `apply_range_set_cb`, `arena_adjust_tree`, `bpf_alloc_page`, `bpf_alloc_pages`, `bpf_free_pages`, `bpf_jit_find_kfunc_model`, `bpf_do_misc_fixups`, `bpf_get_kfunc_addr`, `bpf_add_kfunc_call`, `bpf_fixup_kfunc_call`, and `add_kfunc_desc_target`. My initial thought is to filter this list. I need to be careful not to include generic allocators, deallocators, or page fault handlers. I recall that I am looking for functions that are *specific* to this subsystem. Let's look at the static functions. Can static functions be used in the fuzzing? I need to remember that compiler-inlined static functions lack distinct symbol addresses and cannot be targeted directly. Therefore, I need to identify non-static callers that exercise them. So, I'm going to start by listing direct, non-ubiquitous functions. From my initial list, after checking the section on extraction guidelines, I think I have: `bpf_fixup_kfunc_call`, `bpf_add_kfunc_call`, `bpf_get_kfunc_addr`, `bpf_jit_find_kfunc_model`, `bpf_alloc_pages`, `bpf_alloc_page`, `bpf_free_pages`, `arena_alloc_pages`, `arena_vm_fault`, `bpf_arena_alloc_pages`. I'm questioning `bpf_alloc_pages`. It seems like a new BPF-specific function (`bpf_alloc_pages`, `bpf_free_pages`) introduced in `kernel/bpf/syscall.c`. Okay, that's not ubiquitous. Is `arena_vm_fault` a page fault handler? It's specific to BPF arena VMAs. Still, `arena_map_alloc` or `bpf_arena_alloc_pages` are very specific. I'll double-check all the modified functions in those files, just to be thorough: `apply_range_set_cb`, `arena_map_alloc`, `arena_vm_fault`, `arena_adjust_tree`, and `arena_alloc_pages` from `kernel/bpf/arena.c`; `bpf_jit_find_kfunc_model` from `kernel/bpf/fixups.c`; `bpf_alloc_page`, `bpf_free_pages`, and `bpf_alloc_pages` from `kernel/bpf/syscall.c`; and `bpf_get_kfunc_addr`, `bpf_add_kfunc_call`, `add_kfunc_desc_target`, and `bpf_fixup_kfunc_call` from `kernel/bpf/verifier.c`. I'll confirm if any of those functions are inlined. It looks like `bpf_fixup_kfunc_call`, `bpf_add_kfunc_call`, `bpf_get_kfunc_addr`, `bpf_jit_find_kfunc_model`, `bpf_alloc_pages`, `bpf_alloc_page`, `bpf_free_pages` and `bpf_arena_alloc_pages` are all non-static. `arena_alloc_pages` and `arena_map_alloc` are static. Finally, I'll review relevant configurations, remembering I have to include `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF`. I think I also need to check `BPF_ARENA`. Okay, time to check with grepper. |
| 28/2 | 2026/09/30 00:58 | tool | grepper |
0mError:no matches Args: {
"Expression": "config.*ARENA",
"PathPrefix": "kernel/bpf"
}Results: {
"error": "no matches"
} |
| 29/2 | 2026/09/30 00:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36189 output: 26 thoughts: 14 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Investigating Arena Configuration** Alright, I need to make sure I've got a comprehensive view of the configuration landscape related to this arena setup. Before I proceed any further, my immediate thought is to perform a sanity check. Let me verify if there are any other configuration files, variables, or settings – beyond what I've already examined – that pertain to the arena itself. It's too easy to miss something crucial, and a single overlooked setting can completely throw off an otherwise robust system. So, I need to make sure I haven't missed any edge cases and perform a deeper investigation. Let's make sure I didn't gloss over anything. |
| 30/2 | 2026/09/30 00:59 | tool | grepper |
0mError:no matches Args: {
"Expression": "ARENA",
"PathPrefix": "init/Kconfig"
}Results: {
"error": "no matches"
} |
| 31/2 | 2026/09/30 00:59 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36406 output: 22 thoughts: 189 Thoughts: **Investigating arena.o Compilation and BPF Configuration** Okay, let's circle back to that `arena.o` object file. Time to re-examine `kernel/bpf/Makefile` to confirm its compilation. Ah, there it is: `ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)` followed by `obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o`. Right, so `arena.o` *is* indeed built when `CONFIG_BPF_SYSCALL` is enabled, but only on 64-bit MMU architectures. That makes perfect sense; arena-based allocation would be much more impactful on a 64-bit system. Now, let's connect the dots. I need to understand what's required to trigger the `BPF_SYSCALL` and, while I'm at it, `DEBUG_INFO_BTF` options. Let's delve into `kernel/bpf/Kconfig`. Ah, the dependencies are right there: `config BPF_SYSCALL`, `config BPF_JIT`, and `config DEBUG_INFO_BTF`. Pretty straightforward. I want to check to be certain that `CONFIG_DEBUG_INFO_BTF` does not depend on anything special. |
| 32/2 | 2026/09/30 00:59 | tool | grepper |
0mArgs:{
"Expression": "config DEBUG_INFO_BTF$"
}Results: {
"Output": "lib/Kconfig.debug=378=config DEBUG_INFO_SPLIT\n--\nlib/Kconfig.debug-397-\nlib/Kconfig.debug:398:config DEBUG_INFO_BTF\nlib/Kconfig.debug-399-\tbool \"Generate BTF type information\"\n"
} |
| 33/2 | 2026/09/30 00:59 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36987 output: 34 thoughts: 19 Thoughts: Here's my thought process, as if I were considering that code: **Diving into `Kconfig.debug`** Okay, I need to investigate something related to debugging, and the `Kconfig` files are usually the first place I'd look for configuration options and dependencies. Let's see...I'm going to start with `lib/Kconfig.debug`. Line 398 seems like a good starting point. I know these files can get long, so pinpointing a line number is helpful to narrow down the relevant context. I'm expecting to find a conditional definition, a help message, or possibly a dependency declaration related to a debug feature. Let's see what's there... |
| 34/2 | 2026/09/30 00:59 | tool | read-file |
0mArgs:{
"File": "lib/Kconfig.debug",
"FirstLine": 395,
"LineCount": 20
}Results: {
"Contents": " 395:\t\t to know about the .dwo files and include them.\n 396:\t\t Incompatible with older versions of ccache.\n 397:\t\n 398:\tconfig DEBUG_INFO_BTF\n 399:\t\tbool \"Generate BTF type information\"\n 400:\t\tdepends on !DEBUG_INFO_SPLIT \u0026\u0026 !DEBUG_INFO_REDUCED\n 401:\t\tdepends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST\n 402:\t\tdepends on BPF_SYSCALL\n 403:\t\tdepends on PAHOLE_VERSION \u003e= 122\n 404:\t\t# pahole uses elfutils, which does not have support for Hexagon relocations\n 405:\t\tdepends on !HEXAGON\n 406:\t\thelp\n 407:\t\t Generate deduplicated BTF type information from DWARF debug info.\n 408:\t\t Turning this on requires pahole v1.22 or later, which will convert\n 409:\t\t DWARF type info into equivalent deduplicated BTF type info.\n 410:\t\n 411:\tconfig PAHOLE_HAS_BTF_TAG\n 412:\t\tdef_bool PAHOLE_VERSION \u003e= 123\n 413:\t\tdepends on CC_IS_CLANG\n 414:\t\thelp\n"
} |
| 35/2 | 2026/09/30 00:59 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37534 output: 251 thoughts: 377 Thoughts: **My Assessment of the WorthFuzzing Evaluation** Okay, let's break this down. I'm seeing a clear thread here focusing on BPF, specifically around kernel function (kfunc) calls and arena memory management. The key symbols jumping out at me are `bpf_fixup_kfunc_call`, `bpf_add_kfunc_call`, `bpf_get_kfunc_addr`, `bpf_jit_find_kfunc_model`, along with the suite of arena allocation and deallocation functions: `bpf_alloc_pages`, `bpf_alloc_page`, `bpf_free_pages`, `bpf_arena_alloc_pages`, and `arena_alloc_pages`. These are the nerve centers of the changes being introduced by this patch series. They're clearly the entry points. Now, the reasoning seems sound. The patch series is touching critical areas. We're talking about refactoring how BPF uses arena page allocation, moving from a dynamic array to a lockless linked list and, most importantly, directly impacting kfunc descriptor management within the verifier and JIT fixups. The change to using direct descriptor indexing rather than lookup by imm/offset with `insn->off` in kfunc call targets is intriguing. We also see assertions being added, which are always good from a fuzzing perspective, especially `WARN_ON_ONCE` consistency assertions. This logic is definitely reachable via the `bpf()` syscall and arena operations, which puts it squarely in the line of fire for fuzzing. The fact that the changes impact core subsystems like BPF and memory mapping for arenas makes it even more appealing. Therefore, given the scope and reach of these changes, the "WorthFuzzing" flag seems justified. Enabling configurations for `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF` feels appropriate. I'm confident in the assessment. Time to call `set-results`. |
| 36/2 | 2026/09/30 00:59 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model",
"bpf_alloc_pages",
"bpf_alloc_page",
"bpf_free_pages",
"bpf_arena_alloc_pages",
"arena_alloc_pages"
],
"Reasoning": "The patch modifies core BPF verifier, runtime fixups, and BPF arena page management. It refactors kfunc descriptor handling to support specialized kfunc call targets using direct descriptor indexing in insn-\u003eoff, and refactors arena page allocation and PTE application to use an llist instead of dynamic page arrays. It also introduces several new defensive WARN_ON_ONCE assertions in reachable code paths. These changes are in core kernel subsystems directly reachable via the bpf() syscall.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model",
"bpf_alloc_pages",
"bpf_alloc_page",
"bpf_free_pages",
"bpf_arena_alloc_pages",
"arena_alloc_pages"
],
"Reasoning": "The patch modifies core BPF verifier, runtime fixups, and BPF arena page management. It refactors kfunc descriptor handling to support specialized kfunc call targets using direct descriptor indexing in insn-\u003eoff, and refactors arena page allocation and PTE application to use an llist instead of dynamic page arrays. It also introduces several new defensive WARN_ON_ONCE assertions in reachable code paths. These changes are in core kernel subsystems directly reachable via the bpf() syscall.",
"WorthFuzzing": true
} |
| 37/1 | 2026/09/30 00:59 | action | If |
2mArgs:{
"WorthFuzzing": true
}Results: null |
| 38/2 | 2026/09/30 00:59 | agent | kmsan-evaluator |
2mModel:core Args: null Results: {
"KMSANReasoning": "The patch series covers two main areas:\n1. BPF arena memory allocation refactoring: replacing temporary pointer arrays allocated with kmalloc_nolock() by an llist of struct pages linked via page-\u003epcp_llist (bpf_alloc_page/bpf_alloc_pages/bpf_free_pages).\n2. Kfunc descriptor table indexing for call specialization: expanding bpf_kfunc_desc_tab with krealloc to track specialized call targets alongside canonical descriptors, switching JIT lookup from sorting/bsearch to direct index-based lookups using insn-\u003eoff.\n\nKMSAN vs KASAN applicability:\n- Uninitialized memory / Info-leaks (KMSAN): All arena pages allocated through bpf_alloc_page() are explicitly zero-initialized at allocation time (alloc_pages_node uses __GFP_ZERO, and alloc_pages_nolock inherently enforces __GFP_ZERO via gfp_nolock). Stack and heap structures (such as apply_range_data and llist_head) are fully initialized before use. The new kfunc descriptors appended via krealloc in add_kfunc_desc_target() are directly copied from base descriptors that were previously zeroed via memset during bpf_add_kfunc_call(). No uninitialized data or padding is exposed or copied to user space.\n- Memory corruption / Bounds / Lifetime (KASAN): Potential bugs in this patch involve out-of-bounds indexing into tab-\u003edescs, krealloc resizing issues, linked-list corruption, or page refcount/freeing errors. These failure modes are comprehensively covered by KASAN, LOCKDEP, and page allocator debug checks.\n\nBecause there are no uninitialized memory risks or data leaks that escape KASAN detection, 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 694c679238a5443fef4587d4aa579196993b9217
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Sep 30 00:57:32 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 4bae3796c42f6..eed7f8f1e4170 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2902,8 +2902,10 @@ struct bpf_map *bpf_map_get_curr_or_next(u32 *id);
struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id);
-int bpf_map_alloc_pages(const struct bpf_map *map, int nid,
- unsigned long nr_pages, struct page **page_array);
+struct page *bpf_alloc_page(int nid, bool sleepable);
+int bpf_alloc_pages(int nid, unsigned long nr_pages,
+ struct llist_head *pages, bool sleepable);
+void bpf_free_pages(struct llist_head *pages);
#ifdef CONFIG_MEMCG
void bpf_map_memcg_enter(const struct bpf_map *map, struct mem_cgroup **old_memcg,
struct mem_cgroup **new_memcg);
@@ -3299,7 +3301,7 @@ const struct btf_func_model *
bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
const struct bpf_insn *insn);
int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,
- u16 btf_fd_idx, u8 **func_addr);
+ u16 desc_idx, u8 **func_addr);
struct bpf_core_ctx {
struct bpf_verifier_log *log;
@@ -3642,7 +3644,7 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
static inline int
bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,
- u16 btf_fd_idx, u8 **func_addr)
+ u16 desc_idx, u8 **func_addr)
{
return -ENOTSUPP;
}
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index c775bd7577063..7bdbda7764c77 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1784,24 +1784,29 @@ enum bpf_reg_arg_type {
};
#define MAX_KFUNC_DESCS 256
+/* Each kfunc can have its canonical and one specialized call target. */
+#define MAX_KFUNC_CALL_DESCS (MAX_KFUNC_DESCS * 2)
+static_assert(MAX_KFUNC_CALL_DESCS <= S16_MAX + 1);
struct bpf_kfunc_desc {
struct btf_func_model func_model;
struct bpf_func_proto proto;
u32 func_id;
- s32 imm;
u16 offset;
unsigned long addr;
};
struct bpf_kfunc_desc_tab {
u32 nr_descs;
+ u32 nr_base_descs;
/* Sorted by func_id (BTF ID) and offset (fd_array offset) during
- * verification. JITs do lookups by bpf_insn, where func_id may not be
- * available, therefore at the end of verification do_misc_fixups()
- * sorts this by imm and offset.
+ * verification. JITs use the descriptor index stored in the finalized
+ * call's off field. The first nr_base_descs entries are the canonical
+ * descriptors used for verifier lookups. Call specialization may append
+ * immutable descriptors for additional targets.
*
- * Grown one entry at a time by bpf_add_kfunc_call().
+ * Grown one entry at a time by bpf_add_kfunc_call() and during
+ * call specialization.
*/
struct bpf_kfunc_desc descs[];
};
diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
index c6369ea5e2082..0ff707707da04 100644
--- a/kernel/bpf/arena.c
+++ b/kernel/bpf/arena.c
@@ -146,7 +146,7 @@ static long compute_pgoff(struct bpf_arena *arena, long uaddr)
struct apply_range_data {
struct bpf_arena *arena;
- struct page **pages;
+ struct llist_head *pages;
int i;
};
@@ -158,13 +158,17 @@ struct clear_range_data {
static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)
{
struct apply_range_data *d = data;
+ struct llist_node *node;
struct page *page;
pte_t pteval;
if (!data)
return 0;
- page = d->pages[d->i];
+ node = READ_ONCE(d->pages->first);
+ if (WARN_ON_ONCE(!node))
+ return -EINVAL;
+ page = llist_entry(node, struct page, pcp_llist);
/* paranoia, similar to vmap_pages_pte_range() */
if (WARN_ON_ONCE(!pfn_valid(page_to_pfn(page))))
return -EINVAL;
@@ -197,6 +201,7 @@ static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)
return -EBUSY;
set_pte_at(&init_mm, addr, pte, pteval);
#endif
+ WARN_ON_ONCE(llist_del_first(d->pages) != node);
d->i++;
WRITE_ONCE(d->arena->nr_pages, d->arena->nr_pages + 1);
return 0;
@@ -312,8 +317,8 @@ static struct bpf_map *arena_map_alloc(union bpf_attr *attr)
INIT_WORK(&arena->free_work, arena_free_worker);
bpf_map_init_from_attr(&arena->map, attr);
- err = bpf_map_alloc_pages(&arena->map, NUMA_NO_NODE, 1, &arena->scratch_page);
- if (err)
+ arena->scratch_page = bpf_alloc_page(NUMA_NO_NODE, true);
+ if (!arena->scratch_page)
goto err_free_arena;
range_tree_init(&arena->rt);
@@ -481,7 +486,9 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
struct bpf_map *map = vmf->vma->vm_file->private_data;
struct bpf_arena *arena = container_of(map, struct bpf_arena, map);
struct mem_cgroup *new_memcg, *old_memcg;
+ LLIST_HEAD(pages);
struct page *page, *new_page = NULL;
+ struct apply_range_data data;
vm_fault_t fault_ret;
long kbase, kaddr;
unsigned long flags;
@@ -543,8 +550,8 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
* The probed page was freed meanwhile or preallocation failed;
* try the non-blocking allocator, we cannot sleep here.
*/
- ret = bpf_map_alloc_pages(map, map->numa_node, 1, &new_page);
- if (ret) {
+ new_page = bpf_alloc_page(map->numa_node, false);
+ if (!new_page) {
fault_ret = VM_FAULT_SIGBUS;
goto out_err_locked_memcg;
}
@@ -555,12 +562,14 @@ static vm_fault_t arena_vm_fault(struct vm_fault *vmf)
fault_ret = VM_FAULT_SIGBUS;
goto out_err_locked_memcg;
}
- struct apply_range_data data = {
- .arena = arena, .pages = &new_page, .i = 0
- };
+ llist_add(&new_page->pcp_llist, &pages);
+ data.arena = arena;
+ data.pages = &pages;
+ data.i = 0;
ret = apply_to_page_range(&init_mm, kaddr, PAGE_SIZE, apply_range_set_cb, &data);
if (ret) {
+ llist_del_first(&pages);
range_tree_set(&arena->rt, vmf->pgoff, 1);
fault_ret = VM_FAULT_SIGBUS;
goto out_err_locked_memcg;
@@ -704,6 +713,27 @@ static u64 clear_lo32(u64 val)
return val & ~(u64)~0U;
}
+static int arena_adjust_tree(struct bpf_arena *arena, long uaddr, long page_cnt, long *pgoff)
+{
+ int ret;
+
+ /* Special case where user is requesting specific range. */
+ if (uaddr) {
+ ret = is_range_tree_set(&arena->rt, *pgoff, page_cnt);
+ if (ret)
+ return ret;
+ return range_tree_clear(&arena->rt, *pgoff, page_cnt);
+ }
+
+ ret = range_tree_find(&arena->rt, page_cnt);
+ if (ret < 0)
+ return ret;
+
+ *pgoff = ret;
+
+ return range_tree_clear(&arena->rt, *pgoff, page_cnt);
+}
+
/*
* Allocate pages and vmap them into kernel vmalloc area.
* Later the pages will be mmaped into user space vma.
@@ -716,13 +746,13 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt
u64 kern_vm_start = bpf_arena_get_kern_vm_start(arena);
struct mem_cgroup *new_memcg, *old_memcg;
struct apply_range_data data;
- struct page **pages = NULL;
- long remaining, mapped = 0;
- long alloc_pages;
+ LLIST_HEAD(pages);
+ long mapped = 0;
unsigned long flags;
long pgoff = 0;
u32 uaddr32;
- int ret, i;
+ long addr = 0;
+ int ret;
if (node_id != NUMA_NO_NODE &&
((unsigned int)node_id >= nr_node_ids || !node_online(node_id)))
@@ -739,89 +769,63 @@ static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt
/* requested address will be outside of user VMA */
return 0;
}
-
bpf_map_memcg_enter(&arena->map, &old_memcg, &new_memcg);
- /* Cap allocation size to KMALLOC_MAX_CACHE_SIZE so kmalloc_nolock() can succeed. */
- alloc_pages = min(page_cnt, KMALLOC_MAX_CACHE_SIZE / sizeof(struct page *));
- pages = kmalloc_nolock(alloc_pages * sizeof(struct page *), __GFP_ACCOUNT, NUMA_NO_NODE);
- if (!pages) {
- bpf_map_memcg_exit(old_memcg, new_memcg);
- return 0;
- }
+
+ ret = bpf_alloc_pages(node_id, page_cnt, &pages, sleepable);
+ if (ret)
+ goto out_memcg;
+
data.arena = arena;
- data.pages = pages;
+ data.pages = &pages;
+ data.i = 0;
if (raw_res_spin_lock_irqsave(&arena->spinlock, flags))
goto out_free_pages;
- if (uaddr) {
- ret = is_range_tree_set(&arena->rt, pgoff, page_cnt);
- if (ret)
- goto out_unlock_free_pages;
- ret = range_tree_clear(&arena->rt, pgoff, page_cnt);
- } else {
- ret = pgoff = range_tree_find(&arena->rt, page_cnt);
- if (pgoff >= 0)
- ret = range_tree_clear(&arena->rt, pgoff, page_cnt);
+ ret = arena_adjust_tree(arena, uaddr, page_cnt, &pgoff);
+ if (ret) {
+ raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
+ goto out_free_pages;
}
- if (ret)
- goto out_unlock_free_pages;
- remaining = page_cnt;
uaddr32 = (u32)(arena->user_vm_start + pgoff * PAGE_SIZE);
- while (remaining) {
- long this_batch = min(remaining, alloc_pages);
-
- /* zeroing is needed, since alloc_pages_bulk() only fills in non-zero entries */
- memset(pages, 0, this_batch * sizeof(struct page *));
+ /*
+ * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1
+ * will not overflow 32-bit. Lower 32-bit need to represent
+ * contiguous user address range.
+ * Map these pages at kern_vm_start base.
+ * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow
+ * lower 32-bit and it's ok.
+ */
+ ret = apply_to_page_range(&init_mm, kern_vm_start + uaddr32,
+ page_cnt << PAGE_SHIFT, apply_range_set_cb, &data);
+ mapped = data.i;
+ if (ret)
+ goto out_unmap;
- ret = bpf_map_alloc_pages(&arena->map, node_id, this_batch, pages);
- if (ret)
- goto out;
+ flush_vmap_cache(kern_vm_start + uaddr32, mapped << PAGE_SHIFT);
+ raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
- /*
- * Earlier checks made sure that uaddr32 + page_cnt * PAGE_SIZE - 1
- * will not overflow 32-bit. Lower 32-bit need to represent
- * contiguous user address range.
- * Map these pages at kern_vm_start base.
- * kern_vm_start + uaddr32 + page_cnt * PAGE_SIZE - 1 can overflow
- * lower 32-bit and it's ok.
- */
- data.i = 0;
- ret = apply_to_page_range(&init_mm,
- kern_vm_start + uaddr32 + (mapped << PAGE_SHIFT),
- this_batch << PAGE_SHIFT, apply_range_set_cb, &data);
- if (ret) {
- /* data.i pages were mapped, account them and free the remaining */
- mapped += data.i;
- for (i = data.i; i < this_batch; i++)
- free_pages_nolock(pages[i], 0);
- goto out;
- }
+ addr = clear_lo32(arena->user_vm_start) + uaddr32;
+ goto out_memcg;
- mapped += this_batch;
- remaining -= this_batch;
- }
+out_unmap:
+ /* Error handling: Undo partial mappings. */
flush_vmap_cache(kern_vm_start + uaddr32, mapped << PAGE_SHIFT);
- raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
- kfree_nolock(pages);
- bpf_map_memcg_exit(old_memcg, new_memcg);
- return clear_lo32(arena->user_vm_start) + uaddr32;
-out:
range_tree_set(&arena->rt, pgoff + mapped, page_cnt - mapped);
raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
- if (mapped) {
- flush_vmap_cache(kern_vm_start + uaddr32, mapped << PAGE_SHIFT);
+ if (mapped)
arena_free_pages(arena, uaddr32, mapped, sleepable);
- }
- goto out_free_pages;
-out_unlock_free_pages:
- raw_res_spin_unlock_irqrestore(&arena->spinlock, flags);
+
out_free_pages:
- kfree_nolock(pages);
+ /* Error handling: Free back any unmapped pages. */
+ bpf_free_pages(&pages);
+
+out_memcg:
bpf_map_memcg_exit(old_memcg, new_memcg);
- return 0;
+
+ return addr;
}
/*
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 37cf130ebb57b..cb7219ff68bd1 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -5,8 +5,6 @@
#include <linux/bpf_verifier.h>
#include <linux/filter.h>
#include <linux/vmalloc.h>
-#include <linux/bsearch.h>
-#include <linux/sort.h>
#include <linux/perf_event.h>
#include <linux/sched/signal.h>
#include <net/xdp.h>
@@ -117,73 +115,26 @@ int bpf_insn_def32(struct bpf_prog *prog, struct bpf_insn *insn)
return dst_reg;
}
-static int kfunc_desc_cmp_by_imm_off(const void *a, const void *b)
-{
- const struct bpf_kfunc_desc *d0 = a;
- const struct bpf_kfunc_desc *d1 = b;
-
- if (d0->imm != d1->imm)
- return d0->imm < d1->imm ? -1 : 1;
- if (d0->offset != d1->offset)
- return d0->offset < d1->offset ? -1 : 1;
- return 0;
-}
-
const struct btf_func_model *
bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
const struct bpf_insn *insn)
{
- const struct bpf_kfunc_desc desc = {
- .imm = insn->imm,
- .offset = insn->off,
- };
const struct bpf_kfunc_desc *res;
struct bpf_kfunc_desc_tab *tab;
tab = prog->aux->kfunc_tab;
- res = bsearch(&desc, tab->descs, tab->nr_descs,
- sizeof(tab->descs[0]), kfunc_desc_cmp_by_imm_off);
-
- return res ? &res->func_model : NULL;
-}
-
-static int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)
-{
- unsigned long call_imm;
+ if (insn->off < 0 || insn->off >= tab->nr_descs)
+ return NULL;
+ res = &tab->descs[insn->off];
if (bpf_jit_supports_far_kfunc_call()) {
- call_imm = desc->func_id;
- } else {
- call_imm = BPF_CALL_IMM(desc->addr);
- /* Check whether the relative offset overflows desc->imm */
- if ((unsigned long)(s32)call_imm != call_imm) {
- verbose(env, "address of kernel func_id %u is out of range\n",
- desc->func_id);
- return -EINVAL;
- }
- }
- desc->imm = call_imm;
- return 0;
-}
-
-static int sort_kfunc_descs_by_imm_off(struct bpf_verifier_env *env)
-{
- struct bpf_kfunc_desc_tab *tab;
- int i, err;
-
- tab = env->prog->aux->kfunc_tab;
- if (!tab)
- return 0;
-
- for (i = 0; i < tab->nr_descs; i++) {
- err = set_kfunc_desc_imm(env, &tab->descs[i]);
- if (err)
- return err;
+ if (res->func_id != insn->imm)
+ return NULL;
+ } else if ((s32)BPF_CALL_IMM(res->addr) != insn->imm) {
+ return NULL;
}
- sort(tab->descs, tab->nr_descs, sizeof(tab->descs[0]),
- kfunc_desc_cmp_by_imm_off, NULL);
- return 0;
+ return &res->func_model;
}
static int add_kfunc_in_insns(struct bpf_verifier_env *env,
@@ -2720,10 +2671,6 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
}
}
- ret = sort_kfunc_descs_by_imm_off(env);
- if (ret)
- return ret;
-
return 0;
}
@@ -2897,4 +2844,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)
return 0;
}
-
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index ac52f4ae414ce..ef8fb2f6e6e35 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -602,38 +602,45 @@ static bool can_alloc_pages(void)
!IS_ENABLED(CONFIG_PREEMPT_RT);
}
-static struct page *__bpf_alloc_page(int nid)
+struct page *bpf_alloc_page(int nid, bool sleepable)
{
- if (!can_alloc_pages())
+ if (!sleepable || !can_alloc_pages())
return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);
return alloc_pages_node(nid,
GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT
- | __GFP_NOWARN,
+ | __GFP_NOWARN | __GFP_RETRY_MAYFAIL,
0);
}
-int bpf_map_alloc_pages(const struct bpf_map *map, int nid,
- unsigned long nr_pages, struct page **pages)
+void bpf_free_pages(struct llist_head *pages)
{
- unsigned long i, j;
+ struct llist_node *node;
+ struct page *page, *tmp;
+
+ node = llist_del_all(pages);
+ llist_for_each_entry_safe(page, tmp, node, pcp_llist)
+ free_pages_nolock(page, 0);
+}
+
+int bpf_alloc_pages(int nid, unsigned long nr_pages,
+ struct llist_head *pages, bool sleepable)
+{
+ unsigned long i;
struct page *pg;
- int ret = 0;
for (i = 0; i < nr_pages; i++) {
- pg = __bpf_alloc_page(nid);
-
- if (pg) {
- pages[i] = pg;
- continue;
- }
- for (j = 0; j < i; j++)
- free_pages_nolock(pages[j], 0);
- ret = -ENOMEM;
- break;
+ pg = bpf_alloc_page(nid, sleepable);
+ if (!pg)
+ goto free_pages;
+ llist_add(&pg->pcp_llist, pages);
}
- return ret;
+ return 0;
+
+free_pages:
+ bpf_free_pages(pages);
+ return -ENOMEM;
}
static int btf_field_cmp(const void *a, const void *b)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 03dbc0e003986..8ba831329ab7a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2579,17 +2579,21 @@ find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset)
struct bpf_kfunc_desc_tab *tab;
tab = prog->aux->kfunc_tab;
- return bsearch(&desc, tab->descs, tab->nr_descs,
+ return bsearch(&desc, tab->descs, tab->nr_base_descs,
sizeof(tab->descs[0]), kfunc_desc_cmp_by_id_off);
}
int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,
- u16 btf_fd_idx, u8 **func_addr)
+ u16 desc_idx, u8 **func_addr)
{
+ struct bpf_kfunc_desc_tab *tab;
const struct bpf_kfunc_desc *desc;
- desc = find_kfunc_desc(prog, func_id, btf_fd_idx);
- if (!desc)
+ tab = prog->aux->kfunc_tab;
+ if (desc_idx >= tab->nr_descs)
+ return -EFAULT;
+ desc = &tab->descs[desc_idx];
+ if (desc->func_id != func_id)
return -EFAULT;
*func_addr = (u8 *)desc->addr;
@@ -2929,10 +2933,12 @@ int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)
if (find_kfunc_desc(env->prog, func_id, offset))
return 0;
- if (tab->nr_descs == MAX_KFUNC_DESCS) {
+ if (tab->nr_base_descs == MAX_KFUNC_DESCS) {
verbose(env, "too many different kernel function calls\n");
return -E2BIG;
}
+ if (WARN_ON_ONCE(tab->nr_descs != tab->nr_base_descs))
+ return -EFAULT;
err = fetch_kfunc_meta(env, func_id, offset, &kfunc);
if (err)
@@ -2990,7 +2996,8 @@ int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)
desc->addr = addr;
desc->func_model = func_model;
tab->nr_descs++;
- sort(tab->descs, tab->nr_descs, sizeof(tab->descs[0]),
+ tab->nr_base_descs++;
+ sort(tab->descs, tab->nr_base_descs, sizeof(tab->descs[0]),
kfunc_desc_cmp_by_id_off, NULL);
return 0;
}
@@ -22058,6 +22065,56 @@ static int specialize_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_desc
return 0;
}
+static int add_kfunc_desc_target(struct bpf_verifier_env *env,
+ const struct bpf_kfunc_desc *target_desc,
+ u16 base_desc_idx, u16 *desc_idx)
+{
+ struct bpf_kfunc_desc desc = *target_desc;
+ struct bpf_kfunc_desc_tab *new_tab;
+ struct bpf_kfunc_desc_tab *tab;
+ struct bpf_prog_aux *prog_aux;
+ u32 i;
+
+ prog_aux = env->prog->aux;
+ tab = prog_aux->kfunc_tab;
+
+ if (WARN_ON_ONCE(base_desc_idx >= tab->nr_base_descs))
+ return -EFAULT;
+ if (WARN_ON_ONCE(tab->descs[base_desc_idx].func_id != desc.func_id ||
+ tab->descs[base_desc_idx].offset != desc.offset))
+ return -EFAULT;
+
+ if (tab->descs[base_desc_idx].addr == desc.addr) {
+ *desc_idx = base_desc_idx;
+ return 0;
+ }
+
+ for (i = tab->nr_base_descs; i < tab->nr_descs; i++) {
+ if (tab->descs[i].func_id == desc.func_id &&
+ tab->descs[i].offset == desc.offset &&
+ tab->descs[i].addr == desc.addr) {
+ *desc_idx = i;
+ return 0;
+ }
+ }
+
+ if (tab->nr_descs == MAX_KFUNC_CALL_DESCS) {
+ verbose(env, "too many different kernel function call targets\n");
+ return -E2BIG;
+ }
+
+ new_tab = krealloc(tab, struct_size(tab, descs, tab->nr_descs + 1),
+ GFP_KERNEL_ACCOUNT);
+ if (!new_tab)
+ return -ENOMEM;
+ tab = new_tab;
+ prog_aux->kfunc_tab = tab;
+
+ *desc_idx = tab->nr_descs;
+ tab->descs[tab->nr_descs++] = desc;
+ return 0;
+}
+
static void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,
u16 struct_meta_reg,
u16 node_offset_reg,
@@ -22078,7 +22135,11 @@ static void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,
int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
struct bpf_insn *insn_buf, int insn_idx, int *cnt)
{
+ struct bpf_kfunc_desc desc_copy;
struct bpf_kfunc_desc *desc;
+ unsigned long call_imm;
+ u16 base_desc_idx, desc_idx;
+ bool near_call;
int err;
if (!insn->imm) {
@@ -22098,13 +22159,30 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
insn->imm);
return -EFAULT;
}
+ base_desc_idx = desc - env->prog->aux->kfunc_tab->descs;
+
+ near_call = !bpf_jit_supports_far_kfunc_call();
+ desc_copy = *desc;
+ desc = &desc_copy;
err = specialize_kfunc(env, desc, insn_idx);
if (err)
return err;
- if (!bpf_jit_supports_far_kfunc_call())
- insn->imm = BPF_CALL_IMM(desc->addr);
+ if (near_call) {
+ call_imm = BPF_CALL_IMM(desc->addr);
+ if ((unsigned long)(s32)call_imm != call_imm) {
+ verbose(env, "address of kernel func_id %u is out of range\n",
+ desc->func_id);
+ return -EINVAL;
+ }
+ insn->imm = call_imm;
+ }
+
+ err = add_kfunc_desc_target(env, desc, base_desc_idx, &desc_idx);
+ if (err)
+ return err;
+ insn->off = desc_idx;
if (is_bpf_obj_new_kfunc(desc->func_id) || is_bpf_percpu_obj_new_kfunc(desc->func_id)) {
struct btf_struct_meta *kptr_struct_meta = env->insn_aux_data[insn_idx].kptr_struct_meta;
diff --git a/tools/testing/selftests/bpf/prog_tests/file_reader.c b/tools/testing/selftests/bpf/prog_tests/file_reader.c
index 48aae7ea0e4bb..e59c6c87e9d56 100644
--- a/tools/testing/selftests/bpf/prog_tests/file_reader.c
+++ b/tools/testing/selftests/bpf/prog_tests/file_reader.c
@@ -7,10 +7,12 @@
#include "file_reader_fail.skel.h"
#include <dlfcn.h>
#include <sys/mman.h>
+#include <sys/stat.h>
const char *user_ptr = "hello world";
char file_contents[256000];
void *addr;
+__u64 beyond_eof_offset;
void *get_executable_base_addr(void)
{
@@ -26,12 +28,18 @@ void *get_executable_base_addr(void)
static int initialize_file_contents(void)
{
+ struct stat st;
int fd, page_sz = sysconf(_SC_PAGESIZE);
ssize_t n = 0, cur;
fd = open("/proc/self/exe", O_RDONLY);
if (!ASSERT_OK_FD(fd, "Open /proc/self/exe\n"))
return 1;
+ if (!ASSERT_OK(fstat(fd, &st), "fstat /proc/self/exe")) {
+ close(fd);
+ return 1;
+ }
+ beyond_eof_offset = st.st_size + (1ULL << 30);
do {
cur = read(fd, file_contents + n, sizeof(file_contents) - n);
@@ -75,6 +83,7 @@ static void run_test(const char *prog_name)
memcpy(skel->bss->user_buf, file_contents, sizeof(file_contents));
skel->bss->pid = getpid();
+ skel->bss->beyond_eof_offset = beyond_eof_offset;
err = file_reader__load(skel);
if (!ASSERT_OK(err, "file_reader__load"))
@@ -110,6 +119,12 @@ void test_file_reader(void)
if (test__start_subtest("on_open_validate_file_read"))
run_test("on_open_validate_file_read");
+ if (test__start_subtest("on_open_non_sleepable_first"))
+ run_test("on_open_non_sleepable_first");
+
+ if (test__start_subtest("on_open_sleepable_first"))
+ run_test("on_open_sleepable_first");
+
if (test__start_subtest("negative"))
RUN_TESTS(file_reader_fail);
}
diff --git a/tools/testing/selftests/bpf/progs/file_reader.c b/tools/testing/selftests/bpf/progs/file_reader.c
index aa2c05cce2b30..8b972fd26d733 100644
--- a/tools/testing/selftests/bpf/progs/file_reader.c
+++ b/tools/testing/selftests/bpf/progs/file_reader.c
@@ -27,9 +27,14 @@ char tmp_buf[256000];
int pid = 0;
int err, run_success = 0;
+__u64 beyond_eof_offset;
static int validate_file_read(struct file *file);
static int task_work_callback(struct bpf_map *map, void *key, void *value);
+static int sleepable_second_callback(struct bpf_map *map, void *key, void *value);
+
+void bpf_rcu_read_lock(void) __ksym;
+void bpf_rcu_read_unlock(void) __ksym;
SEC("lsm/file_open")
int on_open_expect_fault(void *c)
@@ -81,6 +86,101 @@ int on_open_validate_file_read(void *c)
return 0;
}
+/*
+ * Exercise bpf_dynptr_from_file() first from a non-sleepable LSM program and
+ * then from its sleepable task-work callback. Reading beyond EOF makes the two
+ * backing implementations return different errors.
+ */
+SEC("lsm/file_open")
+int on_open_non_sleepable_first(void *c)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct bpf_dynptr dynptr;
+ struct elem *work;
+ struct file *file;
+ int key = 0;
+ int ret;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ file = bpf_get_task_exe_file(task);
+ if (!file) {
+ err = 1;
+ return 0;
+ }
+
+ /* The non-sleepable reader cannot fault in an uncached folio. */
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ bpf_put_file(file);
+ if (ret != -EFAULT) {
+ err = 2;
+ return 0;
+ }
+
+ work = bpf_map_lookup_elem(&arrmap, &key);
+ if (!work) {
+ err = 3;
+ return 0;
+ }
+
+ ret = bpf_task_work_schedule_signal(task, &work->tw, &arrmap,
+ sleepable_second_callback);
+ if (ret)
+ err = 4;
+ return 0;
+}
+
+/*
+ * Exercise the opposite fixup order: the first call is made from a sleepable
+ * LSM program, while the RCU read-side section makes the second non-sleepable.
+ */
+SEC("lsm.s/file_open")
+int on_open_sleepable_first(void *c)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct bpf_dynptr dynptr;
+ struct file *file;
+ int ret;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ file = bpf_get_task_exe_file(task);
+ if (!file) {
+ err = 7;
+ return 0;
+ }
+
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ if (ret != -EIO) {
+ err = 8;
+ goto out;
+ }
+
+ bpf_rcu_read_lock();
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ bpf_rcu_read_unlock();
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ if (ret != -EFAULT) {
+ err = 9;
+ goto out;
+ }
+
+ run_success = 1;
+out:
+ bpf_put_file(file);
+ return 0;
+}
+
/* Called in a sleepable context, read 256K bytes, cross check with user space read data */
static int task_work_callback(struct bpf_map *map, void *key, void *value)
{
@@ -97,6 +197,35 @@ static int task_work_callback(struct bpf_map *map, void *key, void *value)
return 0;
}
+/* Task-work callbacks are verified as sleepable. */
+static int sleepable_second_callback(struct bpf_map *map, void *key, void *value)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct bpf_dynptr dynptr;
+ struct file *file;
+ int ret;
+
+ file = bpf_get_task_exe_file(task);
+ if (!file) {
+ err = 5;
+ return 0;
+ }
+
+ /* freader_fetch() converts __kernel_read()'s short read at EOF to -EIO. */
+ ret = bpf_dynptr_from_file(file, 0, &dynptr);
+ if (!ret)
+ ret = bpf_dynptr_read(tmp_buf, 1, &dynptr, beyond_eof_offset, 0);
+ bpf_dynptr_file_discard(&dynptr);
+ bpf_put_file(file);
+ if (ret != -EIO) {
+ err = 6;
+ return 0;
+ }
+
+ run_success = 1;
+ return 0;
+}
+
static int verify_dynptr_read(struct bpf_dynptr *ptr, u32 off, char *user_buf, u32 len)
{
int i;
diff --git a/tools/testing/selftests/bpf/progs/verifier_arena_large.c b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
index 6ab8730d48782..dbdea14ca76f5 100644
--- a/tools/testing/selftests/bpf/progs/verifier_arena_large.c
+++ b/tools/testing/selftests/bpf/progs/verifier_arena_large.c
@@ -10,6 +10,9 @@
#include <bpf_arena_common.h>
#define ARENA_SIZE (1ull << 32)
+#define LARGE_PAGE_CNT 1025
+
+volatile int zero = 0;
struct {
__uint(type, BPF_MAP_TYPE_ARENA);
@@ -284,6 +287,7 @@ int big_alloc2(void *ctx)
return 0;
}
+/* Nonsleepable because it binds to a socket program. */
SEC("socket")
__success __retval(0)
int big_alloc3(void *ctx)
@@ -291,24 +295,56 @@ int big_alloc3(void *ctx)
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
char __arena *pages;
u64 i;
+ int err = 0;
- /*
- * Allocate 2051 pages in one go to check how kmalloc_nolock() handles large requests.
- * Since kmalloc_nolock() can allocate up to 1024 struct page * at a time, this call should
- * result in three batches: two batches of 1024 pages each, followed by a final batch of 3
- * pages.
- */
- pages = bpf_arena_alloc_pages(&arena, NULL, 2051, NUMA_NO_NODE, 0);
+ /* Verify that a nonsleepable allocation larger than 1024 pages succeeds. */
+ pages = bpf_arena_alloc_pages(&arena, NULL, LARGE_PAGE_CNT, NUMA_NO_NODE, 0);
if (!pages)
- return 0;
+ return 1;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++)
+ pages[i * PAGE_SIZE] = 123;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++) {
+ if (pages[i * PAGE_SIZE] == 123)
+ continue;
+ err = 2;
+ break;
+ }
+
+ bpf_arena_free_pages(&arena, pages, LARGE_PAGE_CNT);
+ return err;
+#endif
+ return 0;
+}
- bpf_for(i, 0, 2051)
- pages[i * PAGE_SIZE] = 123;
- bpf_for(i, 0, 2051)
- if (pages[i * PAGE_SIZE] != 123)
- return i;
+/* SYSCALL programs are always sleepable. */
+SEC("syscall")
+__success __retval(0)
+int big_alloc4(void *ctx)
+{
+#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
+ char __arena *pages;
+ u64 i;
+ int err = 0;
+
+ /* Verify that a sleepable allocation larger than 1024 pages succeeds. */
+ pages = bpf_arena_alloc_pages(&arena, NULL, LARGE_PAGE_CNT, NUMA_NO_NODE, 0);
+ if (!pages)
+ return 1;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++)
+ pages[i * PAGE_SIZE] = 123;
+
+ for (i = zero; i < LARGE_PAGE_CNT && can_loop; i++) {
+ if (pages[i * PAGE_SIZE] == 123)
+ continue;
+ err = 2;
+ break;
+ }
- bpf_arena_free_pages(&arena, pages, 2051);
+ bpf_arena_free_pages(&arena, pages, LARGE_PAGE_CNT);
+ return err;
#endif
return 0;
}
|
| 39/3 | 2026/09/30 00:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14551 output: 20 thoughts: 564 Thoughts: **Analyzing the Patch for KMSAN Fuzzing Needs** Okay, let's break down this patch and determine if we need a dedicated KMSAN fuzzing session for it. My initial thought is to understand the changes first, and then evaluate the risk. The patch looks like it's addressing two main areas within BPF: First, there's a significant change in memory management within `kernel/bpf/arena.c` and `kernel/bpf/syscall.c`. They're replacing the array-of-pages allocation, the `struct page **pages`, used in `arena_alloc_pages` and `bpf_map_alloc_pages`, with an `llist_head` of pages managed by new functions: `bpf_alloc_pages`, `bpf_free_pages`, and `bpf_alloc_page`. It seems they're using `page->pcp_llist` to link the pages in a lockless singly-linked list (`llist`). I see that `apply_range_set_cb` iterates through this list, popping pages. They've also refactored `arena_adjust_tree`. Now, digging deeper into `bpf_alloc_page`: It seems like we have conditional allocation logic. If it's `sleepable` and `can_alloc_pages()`, they use `alloc_pages_node` with `GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT | __GFP_NOWARN | __GFP_RETRY_MAYFAIL`. The key thing here is `__GFP_ZERO` – the pages are being zeroed. I need to be careful with this, zeroing can introduce subtle bugs. But what about the *other* case, when it's `!sleepable || !can_alloc_pages()`? They call `alloc_pages_nolock(__GFP_ACCOUNT, nid, 0)`. The question is, does `alloc_pages_nolock` zero the memory? I need to verify that; it's possible a vulnerability could have been created by changing the zeroing behavior. I'll need to check the code that defines `alloc_pages_nolock` to be sure. The second part of the patch, in `kernel/bpf/fixups.c`, `kernel/bpf/verifier.c`, and `include/linux/bpf_verifier.h`, deals with kfunc call descriptor handling to support call specialization. This sounds like they're enabling a kfunc to have both canonical and specialized call targets. This means they are refactoring `bpf_jit_find_kfunc_model` and `bpf_get_kfunc_addr`. It appears they're using `desc_idx` in `insn->off` instead of sorting by `imm` and `offset`. They are appending to `tab->descs` using `krealloc` in `add_kfunc_desc_target`. To thoroughly understand the code and possible implications, I'm going to quickly use `grep` or start reading the affected files directly. My primary focus will be on memory handling and any changes to the zeroing behavior, especially within the context of the new `llist` implementation and potential for uninitialized memory exposure. I'll need to carefully look for potential use-after-free and double-free scenarios, since they are using `llist` |
| 40/3 | 2026/09/30 00:59 | tool | grepper |
0mArgs:{
"Expression": "alloc_pages_nolock"
}Results: {
"Output": "include/linux/gfp.h=25=static inline bool gfpflags_allow_spinning(const gfp_t gfp_flags)\n--\ninclude/linux/gfp.h-30-\t * All GFP_* flags including GFP_NOWAIT use one or both flags.\ninclude/linux/gfp.h:31:\t * alloc_pages_nolock() is the only API that doesn't specify either flag.\ninclude/linux/gfp.h-32-\t *\n--\ninclude/linux/gfp.h-36-\t * on any locks (i.e. only trylocks). There is no high level\ninclude/linux/gfp.h:37:\t * GFP_$FOO flag for this use in alloc_pages_nolock() as the\ninclude/linux/gfp.h-38-\t * regular page allocator doesn't fully support this\n--\ninclude/linux/gfp.h=309=static inline struct page *alloc_page_vma_noprof(gfp_t gfp,\n--\ninclude/linux/gfp.h-317-\ninclude/linux/gfp.h:318:struct page *alloc_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order);\ninclude/linux/gfp.h:319:#define alloc_pages_nolock(...)\t\t\talloc_hooks(alloc_pages_nolock_noprof(__VA_ARGS__))\ninclude/linux/gfp.h-320-\n--\nkernel/bpf/syscall.c=605=struct page *bpf_alloc_page(int nid, bool sleepable)\n--\nkernel/bpf/syscall.c-607-\tif (!sleepable || !can_alloc_pages())\nkernel/bpf/syscall.c:608:\t\treturn alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);\nkernel/bpf/syscall.c-609-\n--\nmm/page_alloc.c=5343=static inline bool alloc_nolock_allowed(void)\n--\nmm/page_alloc.c-5355-/*\nmm/page_alloc.c:5356: * GFP flags to set for ALLOC_NOLOCK i.e. alloc_pages_nolock().\nmm/page_alloc.c-5357- *\n--\nmm/page_alloc.c-5363- *\nmm/page_alloc.c:5364: * Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason\nmm/page_alloc.c-5365- * to warn. Also warn would trigger printk() which is unsafe from\n--\nmm/page_alloc.c-5373- * Though __GFP_NOMEMALLOC is not checked in the code path below,\nmm/page_alloc.c:5374: * specify it here to highlight that alloc_pages_nolock()\nmm/page_alloc.c-5375- * doesn't want to deplete reserves.\n--\nmm/page_alloc.c=5569=EXPORT_SYMBOL(__free_pages);\n--\nmm/page_alloc.c-5572- * Can be called while holding raw_spin_lock or from IRQ and NMI for any\nmm/page_alloc.c:5573: * page type (not only those that came from alloc_pages_nolock)\nmm/page_alloc.c-5574- */\n--\nmm/page_alloc.c=8041=struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order)\n--\nmm/page_alloc.c-8048-/**\nmm/page_alloc.c:8049: * alloc_pages_nolock - opportunistic reentrant allocation from any context\nmm/page_alloc.c-8050- * @gfp_flags: GFP flags. Only __GFP_ACCOUNT, plus some flags that get set\n--\nmm/page_alloc.c-8056- * call from any context where RCU is watching (from atomic, NMI, and also\nmm/page_alloc.c:8057: * reentrant allocator -\u003e tracepoint -\u003e alloc_pages_nolock_noprof).\nmm/page_alloc.c-8058- * Allocation is best effort and to be expected to fail easily so nobody should\n--\nmm/page_alloc.c-8064- */\nmm/page_alloc.c:8065:struct page *alloc_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order)\nmm/page_alloc.c-8066-{\n--\nmm/page_alloc.c-8073-}\nmm/page_alloc.c:8074:EXPORT_SYMBOL_GPL(alloc_pages_nolock_noprof);\n--\nmm/page_owner.c=316=void __reset_page_owner(struct page *page, unsigned short order)\n--\nmm/page_owner.c-334-\t * to prevent issues in stack_depot_save().\nmm/page_owner.c:335:\t * This is similar to alloc_pages_nolock() gfp flags, but only used\nmm/page_owner.c-336-\t * to signal stack_depot to avoid spin_locks.\n"
} |
| 41/3 | 2026/09/30 00:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17178 output: 36 thoughts: 541 Thoughts: **Analyzing the BPF Page Allocation Changes** Okay, let's break down these changes. First, I need to understand what `__bpf_alloc_page` was doing *before* the patch. Looking at the code, it looks like `__bpf_alloc_page` had a crucial role in deciding how pages are allocated, handling both the lockless case and the regular allocation path. Specifically, if `can_alloc_pages()` returned false, it used `alloc_pages_nolock`. Otherwise it called `alloc_pages_node` with some GFP flags. Now, the patch modified it, adding a `sleepable` parameter and changing how the `can_alloc_pages()` check works. I need to understand why this was done. Next, I need to remind myself how page allocation was handled in `arena_alloc_pages` before the changes. It seems to have called `bpf_map_alloc_pages`, and there was zeroing involved. That's a key detail – the code was using `memset` to zero the pages allocated in `alloc_pages_bulk`. Why is that necessary? So what was `bpf_map_alloc_pages` doing before? Checking the diff, it appears `bpf_map_alloc_pages` was calling `__bpf_alloc_page(nid)` in a loop to allocate individual pages and assign them to the `pages` array. Right, that clarifies the connection. So the pre-patch allocation strategy was simple, loop through and allocate each page using the helper, filling the provided array. Now, I'm thinking about `alloc_pages_nolock` called within `__bpf_alloc_page`. Is the page zeroed when this function is used? I recall it might *not* be. I need to look at `alloc_frozen_pages_nolock_noprof` and its implementation. This will determine if the previous `memset` in `arena_alloc_pages` was really needed, or perhaps could be avoided. This difference in zeroing behavior seems like a core element of the overall changes. I should see if the patch altered the zeroing at any level. |
| 42/3 | 2026/09/30 00:59 | tool | read-file |
0mArgs:{
"File": "mm/page_alloc.c",
"FirstLine": 8040,
"LineCount": 40
}Results: {
"Contents": "8040:\t\n8041:\tstruct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order)\n8042:\t{\n8043:\t\tif (nid == NUMA_NO_NODE)\n8044:\t\t\tnid = numa_node_id();\n8045:\t\n8046:\t\treturn __alloc_frozen_pages_noprof(gfp_flags, order, nid, NULL, ALLOC_NOLOCK);\n8047:\t}\n8048:\t/**\n8049:\t * alloc_pages_nolock - opportunistic reentrant allocation from any context\n8050:\t * @gfp_flags: GFP flags. Only __GFP_ACCOUNT, plus some flags that get set\n8051:\t * internally regardless (see %gfp_nolock) are allowed.\n8052:\t * @nid: node to allocate from\n8053:\t * @order: allocation order size\n8054:\t *\n8055:\t * Allocates pages of a given order from the given node. This is safe to\n8056:\t * call from any context where RCU is watching (from atomic, NMI, and also\n8057:\t * reentrant allocator -\u003e tracepoint -\u003e alloc_pages_nolock_noprof).\n8058:\t * Allocation is best effort and to be expected to fail easily so nobody should\n8059:\t * rely on the success. Failures are not reported via warn_alloc().\n8060:\t * See always fail conditions below.\n8061:\t *\n8062:\t * Return: allocated page or NULL on failure. NULL does not mean EBUSY or EAGAIN.\n8063:\t * It means ENOMEM. There is no reason to call it again and expect !NULL.\n8064:\t */\n8065:\tstruct page *alloc_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order)\n8066:\t{\n8067:\t\tstruct page *page;\n8068:\t\n8069:\t\tpage = alloc_frozen_pages_nolock_noprof(gfp_flags, nid, order);\n8070:\t\tif (page)\n8071:\t\t\tset_page_refcounted(page);\n8072:\t\treturn page;\n8073:\t}\n8074:\tEXPORT_SYMBOL_GPL(alloc_pages_nolock_noprof);\n"
} |
| 43/3 | 2026/09/30 00:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18864 output: 27 thoughts: 34 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating Memory Allocation Behavior** Alright, let's dive into this memory allocation question. My immediate focus is on the `__alloc_frozen_pages_noprof` function and the `ALLOC_NOLOCK` flag. The crux of the matter is whether these components, in their current configuration, guarantee zeroed memory pages. I need to quickly ascertain this detail. Knowing the initialization state of these allocated pages is absolutely critical for security and predictable application behavior. Any unexpected values or uninitialized regions would be unacceptable, thus I need to verify its current behavior as fast as possible. |
| 44/3 | 2026/09/30 00:59 | tool | grepper |
0mArgs:{
"Expression": "ALLOC_NOLOCK",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/page_alloc.c=2535=static int rmqueue_bulk(struct zone *zone, unsigned int order,\n--\nmm/page_alloc.c-2542-\nmm/page_alloc.c:2543:\tif (unlikely(alloc_flags \u0026 ALLOC_NOLOCK)) {\nmm/page_alloc.c-2544-\t\tif (!spin_trylock_irqsave(\u0026zone-\u003elock, flags))\n--\nmm/page_alloc.c=3221=struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone,\n--\nmm/page_alloc.c-3229-\t\tpage = NULL;\nmm/page_alloc.c:3230:\t\tif (unlikely(alloc_flags \u0026 ALLOC_NOLOCK)) {\nmm/page_alloc.c-3231-\t\t\tif (!spin_trylock_irqsave(\u0026zone-\u003elock, flags))\n--\nmm/page_alloc.c=5091=static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,\n--\nmm/page_alloc.c-5118-\t */\nmm/page_alloc.c:5119:\tif (!(*alloc_flags \u0026 ALLOC_NOLOCK) \u0026\u0026\nmm/page_alloc.c-5120-\t should_fail_alloc_page(gfp_mask, order))\n--\nmm/page_alloc.c=5330=static inline bool alloc_order_allowed(gfp_t gfp, unsigned int order,\n--\nmm/page_alloc.c-5332-{\nmm/page_alloc.c:5333:\tif (alloc_flags \u0026 ALLOC_NOLOCK)\nmm/page_alloc.c-5334-\t\treturn pcp_allowed_order(order);\n--\nmm/page_alloc.c=5343=static inline bool alloc_nolock_allowed(void)\n--\nmm/page_alloc.c-5355-/*\nmm/page_alloc.c:5356: * GFP flags to set for ALLOC_NOLOCK i.e. alloc_pages_nolock().\nmm/page_alloc.c-5357- *\n--\nmm/page_alloc.c=5383=struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,\n--\nmm/page_alloc.c-5393-\t/* Other flags could be supported later if needed. */\nmm/page_alloc.c:5394:\tif (WARN_ON(alloc_flags \u0026 ~(ALLOC_NOLOCK | ALLOC_NO_CODETAG)))\nmm/page_alloc.c-5395-\t\treturn NULL;\n--\nmm/page_alloc.c-5399-\nmm/page_alloc.c:5400:\tif (alloc_flags \u0026 ALLOC_NOLOCK) {\nmm/page_alloc.c-5401-\t\t/* Certain other flags could be supported later if needed. */\n--\nmm/page_alloc.c-5424-\nmm/page_alloc.c:5425:\tif (!(alloc_flags \u0026 ALLOC_NOLOCK)) {\nmm/page_alloc.c-5426-\t\t/*\n--\nmm/page_alloc.c-5436-\tpage = get_page_from_freelist(alloc_gfp, order, fastpath_alloc_flags, \u0026ac);\nmm/page_alloc.c:5437:\tif (likely(page) || (alloc_flags \u0026 ALLOC_NOLOCK))\nmm/page_alloc.c-5438-\t\tgoto out;\n--\nmm/page_alloc.c-5454-\t\t__free_frozen_pages(page, order,\nmm/page_alloc.c:5455:\t\t\t\t alloc_flags \u0026 ALLOC_NOLOCK ? FPI_NOLOCK : 0);\nmm/page_alloc.c-5456-\t\tpage = NULL;\n--\nmm/page_alloc.c=7963=static bool cond_accept_memory(struct zone *zone, unsigned int order,\n--\nmm/page_alloc.c-7972-\t/* Bailout, since try_to_accept_memory_one() needs to take a lock */\nmm/page_alloc.c:7973:\tif (alloc_flags \u0026 ALLOC_NOLOCK)\nmm/page_alloc.c-7974-\t\treturn false;\n--\nmm/page_alloc.c=8041=struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order)\n--\nmm/page_alloc.c-8045-\nmm/page_alloc.c:8046:\treturn __alloc_frozen_pages_noprof(gfp_flags, order, nid, NULL, ALLOC_NOLOCK);\nmm/page_alloc.c-8047-}\n--\nmm/page_alloc.h-49-#define ALLOC_HIGHATOMIC\t0x200 /* Allows access to MIGRATE_HIGHATOMIC */\nmm/page_alloc.h:50:#define ALLOC_NOLOCK\t\t0x400 /* Only use spin_trylock in allocation path */\nmm/page_alloc.h-51-#define ALLOC_KSWAPD\t\t0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */\n--\nmm/slab.h-21-#define SLAB_ALLOC_DEFAULT\t0x00 /* no flags */\nmm/slab.h:22:#define SLAB_ALLOC_NOLOCK\t0x01 /* a kmalloc_nolock() allocation */\nmm/slab.h-23-#define SLAB_ALLOC_NEW_SLAB\t0x02 /* a flag for alloc_slab_obj_exts() */\n--\nmm/slab.h=30=static inline unsigned int to_alloc_flags(unsigned int free_flags)\n--\nmm/slab.h-32-\tif (free_flags \u0026 SLAB_FREE_NOLOCK)\nmm/slab.h:33:\t\treturn SLAB_ALLOC_NOLOCK;\nmm/slab.h-34-\telse\n--\nmm/slab.h=38=static inline bool alloc_flags_allow_spinning(const unsigned int alloc_flags)\nmm/slab.h-39-{\nmm/slab.h:40:\treturn !(alloc_flags \u0026 SLAB_ALLOC_NOLOCK);\nmm/slab.h-41-}\n--\nmm/slub.c=5523=void *_kmalloc_nolock_noprof(DECL_TOKEN_PARAMS(size, token), gfp_t gfp_flags, int node)\n--\nmm/slub.c-5527-\t\t.orig_size = size,\nmm/slub.c:5528:\t\t.alloc_flags = SLAB_ALLOC_NOLOCK,\nmm/slub.c-5529-\t};\n"
} |
| 45/3 | 2026/09/30 00:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20808 output: 36 thoughts: 689 Thoughts: **Analyzing Page Allocation in the BPF Subsystem** Okay, let's break this down. First, in `arena_alloc_pages`, I see a section that immediately flags my attention. The original code includes `memset(pages, 0, this_batch * sizeof(struct page *));`. The comment explicitly states that the zeroing is *for the pointer array itself*, not the page contents. This is counterintuitive, but I'll remember this. The function then uses `bpf_map_alloc_pages`, which is concerning. Looking further, `arena_vm_fault` uses `bpf_map_alloc_pages` *and* `bpf_alloc_page`. This is also true for allocating scratch pages in the arena. Now, the critical piece here is the difference between them. `bpf_alloc_page(int nid, bool sleepable)` is where the allocation actually happens and the logic is critical. Here's the kicker: `bpf_alloc_page` decides between two allocation paths. If `sleepable` and `can_alloc_pages()` is true, it calls `alloc_pages_node`, which is specified to allocate with `__GFP_ZERO`. Perfect. But if either of those are false, it then calls `alloc_pages_nolock`. Now, the question is: does `alloc_pages_nolock` zero the memory? That's the key. If it *doesn't* zero, then there's a serious inconsistency. If the `!sleepable` path is taken, we won't be zeroing the memory allocated, which could lead to security issues or data leaks. The `memset` in `arena_alloc_pages` wouldn't be doing what we're hoping it is doing either. I need to dive into `alloc_pages_nolock` to confirm. That is the next logical step. |
| 46/3 | 2026/09/30 00:59 | tool | read-file |
0mArgs:{
"File": "mm/page_alloc.c",
"FirstLine": 5355,
"LineCount": 40
}Results: {
"Contents": "5355:\t/*\n5356:\t * GFP flags to set for ALLOC_NOLOCK i.e. alloc_pages_nolock().\n5357:\t *\n5358:\t * Do not specify __GFP_DIRECT_RECLAIM, since direct claim is not allowed.\n5359:\t * Do not specify __GFP_KSWAPD_RECLAIM either, since wake up of kswapd\n5360:\t * is not safe in arbitrary context.\n5361:\t *\n5362:\t * These two are the conditions for gfpflags_allow_spinning() being true.\n5363:\t *\n5364:\t * Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason\n5365:\t * to warn. Also warn would trigger printk() which is unsafe from\n5366:\t * various contexts. We cannot use printk_deferred_enter() to mitigate,\n5367:\t * since the running context is unknown.\n5368:\t *\n5369:\t * Specify __GFP_ZERO to make sure that call to kmsan_alloc_page() below\n5370:\t * is safe in any context. Also zeroing the page is mandatory for\n5371:\t * BPF use cases.\n5372:\t *\n5373:\t * Though __GFP_NOMEMALLOC is not checked in the code path below,\n5374:\t * specify it here to highlight that alloc_pages_nolock()\n5375:\t * doesn't want to deplete reserves.\n5376:\t */\n5377:\tstatic const gfp_t gfp_nolock = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC |\n5378:\t\t\t\t\t__GFP_COMP;\n5379:\t\n5380:\t/*\n5381:\t * This is the 'heart' of the zoned buddy allocator.\n5382:\t */\n5383:\tstruct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,\n5384:\t\t\tint preferred_nid, nodemask_t *nodemask, unsigned int alloc_flags)\n5385:\t{\n5386:\t\tstruct page *page;\n5387:\t\tgfp_t alloc_gfp; /* The gfp_t that was actually used for allocation */\n5388:\t\tstruct alloc_context ac = {\n5389:\t\t\t.alloc_flags = alloc_flags,\n5390:\t\t};\n5391:\t\tunsigned int fastpath_alloc_flags = alloc_flags;\n5392:\t\n5393:\t\t/* Other flags could be supported later if needed. */\n5394:\t\tif (WARN_ON(alloc_flags \u0026 ~(ALLOC_NOLOCK | ALLOC_NO_CODETAG)))\n"
} |
| 47/3 | 2026/09/30 00:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22660 output: 33 thoughts: 437 Thoughts: **Analyzing the Page Allocation Logic**
Okay, let's break this down. My initial thought is to examine lines 5369-5378; it seems we're focusing on the `__GFP_ZERO` flag and its implications for page allocation, specifically in relation to the `kmsan_alloc_page()` call, and for BPF. The code comments assert that `__GFP_ZERO` is essential for safety and BPF use cases.
Now, I'm recalling that `alloc_pages_nolock` is already configured to zero the page through `__GFP_ZERO`. This means that from the perspective of making sure we have a zeroed page, we already had this behavior.
Next, I'm looking at the `__bpf_alloc_page` function. Before the recent patch, its implementation looked like this:
```c
static struct page *__bpf_alloc_page(int nid)
{
if (!can_alloc_pages())
return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);
return alloc_pages_node(nid,
GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT
| __GFP_NOWARN,
0);
}
```
So, essentially, it's always been set to zero.
So, the new code, `bpf_alloc_page` is now checking if `sleepable`:
`if (!sleepable || !can_alloc_pages()) return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);`
And when sleepable:
`return alloc_pages_node(nid, GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT | __GFP_NOWARN | __GFP_RETRY_MAYFAIL, 0);`
Again, both paths zero the page!
I'm thinking, let's not make assumptions here. I'm going to look into `kernel/bpf/arena.c` around `arena_alloc_pages` to confirm how the behavior for sleepable vs. non-sleepable allocations was previously handled. Let's see if the logic there has changed.
|
| 48/3 | 2026/09/30 00:59 | tool | grepper |
0mArgs:{
"Expression": "arena_alloc_pages",
"PathPrefix": "kernel/bpf/arena.c"
}Results: {
"Output": "kernel/bpf/arena.c-39- * into kernel and user vma.\nkernel/bpf/arena.c:40: * bpf program can allocate a page via bpf_arena_alloc_pages() kfunc\nkernel/bpf/arena.c-41- * which will insert it into kernel vm_area.\n--\nkernel/bpf/arena.c=716=static int arena_adjust_tree(struct bpf_arena *arena, long uaddr, long page_cnt, long *pgoff)\n--\nkernel/bpf/arena.c-740- */\nkernel/bpf/arena.c:741:static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt, int node_id,\nkernel/bpf/arena.c-742-\t\t\t bool sleepable)\n--\nkernel/bpf/arena.c=894=static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt, bool sleepable)\n--\nkernel/bpf/arena.c-983- * Reserve an arena virtual address range without populating it. This call stops\nkernel/bpf/arena.c:984: * bpf_arena_alloc_pages from adding pages to this range.\nkernel/bpf/arena.c-985- */\n--\nkernel/bpf/arena.c=1094=__bpf_kfunc_start_defs();\nkernel/bpf/arena.c-1095-\nkernel/bpf/arena.c:1096:__bpf_kfunc void *bpf_arena_alloc_pages(void *p__map, void *addr__ign, u32 page_cnt,\nkernel/bpf/arena.c-1097-\t\t\t\t\tint node_id, u64 flags)\n--\nkernel/bpf/arena.c-1104-\nkernel/bpf/arena.c:1105:\treturn (void *)arena_alloc_pages(arena, (long)addr__ign, page_cnt, node_id, true);\nkernel/bpf/arena.c-1106-}\nkernel/bpf/arena.c-1107-\nkernel/bpf/arena.c:1108:void *bpf_arena_alloc_pages_non_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\nkernel/bpf/arena.c-1109-\t\t\t\t\t int node_id, u64 flags)\n--\nkernel/bpf/arena.c-1116-\nkernel/bpf/arena.c:1117:\treturn (void *)arena_alloc_pages(arena, (long)addr__ign, page_cnt, node_id, false);\nkernel/bpf/arena.c-1118-}\nkernel/bpf/arena.c-1119-\nkernel/bpf/arena.c:1120:void *bpf_arena_alloc_pages_sleepable(void *p__map, void *addr__ign, u32 page_cnt,\nkernel/bpf/arena.c-1121-\t\t\t\t int node_id, u64 flags)\n--\nkernel/bpf/arena.c-1128-\nkernel/bpf/arena.c:1129:\treturn (void *)arena_alloc_pages(arena, (long)addr__ign, page_cnt, node_id, true);\nkernel/bpf/arena.c-1130-}\n--\nkernel/bpf/arena.c=1167=BTF_KFUNCS_START(arena_kfuncs)\nkernel/bpf/arena.c:1168:BTF_ID_FLAGS(func, bpf_arena_alloc_pages, KF_ARENA_RET | KF_ARENA_ARG2 | KF_SPINLOCK_SAFE)\nkernel/bpf/arena.c-1169-BTF_ID_FLAGS(func, bpf_arena_free_pages, KF_ARENA_ARG2 | KF_SPINLOCK_SAFE)\n"
} |
| 49/3 | 2026/09/30 00:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24610 output: 38 thoughts: 70 Thoughts: Here's my take on those thoughts: **Analyzing BPF Arena Allocation Functions in the Context of `specialize_kfunc`** Alright, let's dive in. First, I see `bpf_arena_alloc_pages`, and immediately I'm thinking, "Okay, there are two flavors: `bpf_arena_alloc_pages_non_sleepable` and `bpf_arena_alloc_pages_sleepable`." That distinction is key, probably related to context and resource availability – are we under interrupt, or can we sleep? I need to understand the nuances of *when* each is used, because that has huge implications for system performance and potential deadlocks. Now, I need to understand how this allocation fits into the bigger picture of BPF. Specifically, I need to know the function of `specialize_kfunc` in `kernel/bpf/verifier.c`. What's the relationship between the allocator and specialization? Are we allocating specialized pages? Is the allocation conditional on the specialization? That's the real puzzle I need to solve – how is memory handled *during* function specialization. I'm going to look to see if the allocation of pages is the result of specialized function demands, or is it a preliminary step? The answers to those questions are critical to my understanding of the verifier's impact on memory usage and safety in BPF programs. This is where I start. |
| 50/3 | 2026/09/30 01:00 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 22050,
"LineCount": 40
}Results: {
"Contents": "22050:\t\t\t\taddr = (unsigned long)bpf_set_dentry_xattr_locked;\n22051:\t\t} else if (func_id == special_kfunc_list[KF_bpf_remove_dentry_xattr]) {\n22052:\t\t\tif (bpf_lsm_has_d_inode_locked(prog))\n22053:\t\t\t\taddr = (unsigned long)bpf_remove_dentry_xattr_locked;\n22054:\t\t} else if (func_id == special_kfunc_list[KF_bpf_dynptr_from_file]) {\n22055:\t\t\tif (!env-\u003einsn_aux_data[insn_idx].non_sleepable)\n22056:\t\t\t\taddr = (unsigned long)bpf_dynptr_from_file_sleepable;\n22057:\t\t} else if (func_id == special_kfunc_list[KF_bpf_arena_alloc_pages]) {\n22058:\t\t\tif (env-\u003einsn_aux_data[insn_idx].non_sleepable)\n22059:\t\t\t\taddr = (unsigned long)bpf_arena_alloc_pages_non_sleepable;\n22060:\t\t} else if (func_id == special_kfunc_list[KF_bpf_arena_free_pages]) {\n22061:\t\t\tif (env-\u003einsn_aux_data[insn_idx].non_sleepable)\n22062:\t\t\t\taddr = (unsigned long)bpf_arena_free_pages_non_sleepable;\n22063:\t\t}\n22064:\t\tdesc-\u003eaddr = addr;\n22065:\t\treturn 0;\n22066:\t}\n22067:\t\n22068:\tstatic int add_kfunc_desc_target(struct bpf_verifier_env *env,\n22069:\t\t\t\t\t const struct bpf_kfunc_desc *target_desc,\n22070:\t\t\t\t\t u16 base_desc_idx, u16 *desc_idx)\n22071:\t{\n22072:\t\tstruct bpf_kfunc_desc desc = *target_desc;\n22073:\t\tstruct bpf_kfunc_desc_tab *new_tab;\n22074:\t\tstruct bpf_kfunc_desc_tab *tab;\n22075:\t\tstruct bpf_prog_aux *prog_aux;\n22076:\t\tu32 i;\n22077:\t\n22078:\t\tprog_aux = env-\u003eprog-\u003eaux;\n22079:\t\ttab = prog_aux-\u003ekfunc_tab;\n22080:\t\n22081:\t\tif (WARN_ON_ONCE(base_desc_idx \u003e= tab-\u003enr_base_descs))\n22082:\t\t\treturn -EFAULT;\n22083:\t\tif (WARN_ON_ONCE(tab-\u003edescs[base_desc_idx].func_id != desc.func_id ||\n22084:\t\t\t\t tab-\u003edescs[base_desc_idx].offset != desc.offset))\n22085:\t\t\treturn -EFAULT;\n22086:\t\n22087:\t\tif (tab-\u003edescs[base_desc_idx].addr == desc.addr) {\n22088:\t\t\t*desc_idx = base_desc_idx;\n22089:\t\t\treturn 0;\n"
} |
| 51/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25903 output: 33 thoughts: 117 Thoughts: **Understanding the Specialization of kfunc Calls** Okay, so I'm looking at `specialize_kfunc`. My initial thought is that this function, based on its name, is designed to specialize calls to kfuncs, like `bpf_dynptr_from_file_sleepable` and `bpf_arena_alloc_pages_non_sleepable`. I'm immediately trying to recall the rationale behind this patch series – what was the specific bug we were addressing, or what performance gain were we aiming for? To get a clearer picture, I'll need some context. I'll reach for `git log` to review the commit messages related to these changes. It's the best way to understand the evolution of the code and the motivations driving it. However, I'll focus my search on `kernel/bpf/fixups.c` or `kernel/bpf/arena.c`, since that's where I would expect to find the relevant implementation details, which I can then connect to the reasoning in the commit messages. |
| 52/3 | 2026/09/30 01:00 | tool | grepper |
0mArgs:{
"Expression": "add_kfunc_desc_target",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/verifier.c=22019=static int specialize_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc, int insn_idx)\n--\nkernel/bpf/verifier.c-22067-\nkernel/bpf/verifier.c:22068:static int add_kfunc_desc_target(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-22069-\t\t\t\t const struct bpf_kfunc_desc *target_desc,\n--\nkernel/bpf/verifier.c=22135=int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-22181-\nkernel/bpf/verifier.c:22182:\terr = add_kfunc_desc_target(env, desc, base_desc_idx, \u0026desc_idx);\nkernel/bpf/verifier.c-22183-\tif (err)\n"
} |
| 53/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26556 output: 23 thoughts: 66 Thoughts: Okay, let's dive into this. Here's my thought process on this: **Investigating `bpf_jit_find_kfunc_model` and `bpf_get_kfunc_addr`** Alright, I'm going to start by understanding the roles of `bpf_jit_find_kfunc_model` and `bpf_get_kfunc_addr`. My immediate next step is to examine their definitions and implementations. I need to figure out precisely what these functions are designed to do within the BPF ecosystem. Next, I need to understand how these functions are *used*. I'll trace through the codebase to pinpoint the call sites of `bpf_jit_find_kfunc_model` and `bpf_get_kfunc_addr`. Identifying their usage patterns is key to understanding their purpose and impact. This will inform the wider context these functions exist within. This should provide a complete picture and allow me to make any necessary improvements. |
| 54/3 | 2026/09/30 01:00 | tool | grepper |
0mArgs:{
"Expression": "bpf_get_kfunc_addr"
}Results: {
"Output": "include/linux/bpf.h=3301=bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\ninclude/linux/bpf.h-3302-\t\t\t const struct bpf_insn *insn);\ninclude/linux/bpf.h:3303:int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\ninclude/linux/bpf.h-3304-\t\t u16 desc_idx, u8 **func_addr);\n--\ninclude/linux/bpf.h=3645=static inline int\ninclude/linux/bpf.h:3646:bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\ninclude/linux/bpf.h-3647-\t\t u16 desc_idx, u8 **func_addr)\n--\nkernel/bpf/core.c=1310=int bpf_jit_get_func_addr(const struct bpf_prog *prog,\n--\nkernel/bpf/core.c-1333-\t\t bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/core.c:1334:\t\terr = bpf_get_kfunc_addr(prog, insn-\u003eimm, insn-\u003eoff, \u0026addr);\nkernel/bpf/core.c-1335-\t\tif (err)\n--\nkernel/bpf/verifier.c=2573=find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2585-\nkernel/bpf/verifier.c:2586:int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\nkernel/bpf/verifier.c-2587-\t\t u16 desc_idx, u8 **func_addr)\n"
} |
| 55/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27365 output: 34 thoughts: 1426 Thoughts: **Analyzing BPF Arena Page Allocation Refactor** Okay, let's break down these BPF changes. The primary focus seems to be a refactor of how arena pages are allocated and managed, specifically moving away from a `struct page **pages` array to an `llist_head`. That's interesting; switching to a linked list for page references could have some performance implications, especially with the overhead of linked list manipulation versus direct array access. Looking at `apply_range_set_cb`, it's clear the code is now iterating through the pages using the `llist_head`. The use of `READ_ONCE` and `WARN_ON_ONCE` is good to see; this signals concerns about atomicity and potential race conditions, but these are fairly standard idioms for this type of low level concurrency. The `llist_del_first` call raises a flag, though - is there a chance that other threads might be racing to grab pages? We will have to analyze the bigger picture. In `arena_map_alloc` and `arena_vm_fault`, the `bpf_map_alloc_pages` function is replaced by `bpf_alloc_page`. This seems like a straightforward change to consolidate page allocation, which is likely a good simplification. It's using `bpf_alloc_page`, which appears to wrap `alloc_pages_nolock` and `alloc_pages_node`, with an added check for a "sleepable" allocation. Also, the use of `LLIST_HEAD` in `arena_vm_fault` and `arena_alloc_pages` confirms this refactoring's trend. The changes within `arena_alloc_pages` are similar, removing the allocation of the `pages` array itself in favor of the linked list approach, and there are corresponding changes to the data structures used. The allocation cap with `KMALLOC_MAX_CACHE_SIZE` is gone, but I suppose this is no longer a concern. Now, a couple of questions are bubbling up. First, this `page->pcp_llist`. I need to figure out what that field is within the `struct page`. It looks like it's a part of the linked list data structure! Is it initialized before use, given the nature of llist? This is key because using an uninitialized memory is never a good thing. We need to verify how `pcp_llist` is being initialized and used to ensure the list is consistent. If we don't, we are certainly in for some nasty surprises. I'll need to check the `struct page` definition in the kernel headers to understand what other uses this field has and ensure that this usage is safe and well-defined. |
| 56/3 | 2026/09/30 01:00 | tool | grepper |
0mArgs:{
"Expression": "pcp_llist",
"PathPrefix": "include/linux/mm_types.h"
}Results: {
"Output": "include/linux/mm_types.h=80=struct page {\n--\ninclude/linux/mm_types.h-101-\t\t\t\tstruct list_head pcp_list;\ninclude/linux/mm_types.h:102:\t\t\t\tstruct llist_node pcp_llist;\ninclude/linux/mm_types.h-103-\t\t\t};\n--\ninclude/linux/mm_types.h-113-\t\t\t * Indicates order in the buddy system if PageBuddy\ninclude/linux/mm_types.h:114:\t\t\t * or on pcp_llist.\ninclude/linux/mm_types.h-115-\t\t\t */\n"
} |
| 57/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29571 output: 37 thoughts: 1204 Thoughts: **Analyzing Kernel Function Descriptor Handling** Okay, so I'm diving into this `pcp_llist` and page allocation thing. It's pretty straightforward: when a page isn't in the buddy system or the pcp list, `pcp_llist` in the `struct page` is used. Pages are refcounted when allocated via `alloc_pages_node` or `alloc_pages_nolock`, and the `llist_add` sets the `next` pointer of `page->pcp_llist`. Importantly, these allocation paths zero the page content using `__GFP_ZERO`. All standard stuff. But wait, I need to refocus. What's the deal with these kernel function descriptor changes? I'm examining this `bpf_kfunc_desc` structure and the related `bpf_kfunc_desc_tab`. It looks like it's holding metadata about BPF kernel function calls. The `add_kfunc_desc_target` function is what I really need to understand. Here's the situation: `add_kfunc_desc_target` takes a `target_desc` and adds it to the function descriptor table. It checks if the `target_desc` already exists. If not, it allocates a new entry in the table. The interesting bit is how `add_kfunc_desc_target` gets the `target_desc`. It seems that the original `target_desc` is copied to the local stack variable called `desc`. Where does `target_desc` actually come from? Aha! It's initialized in `bpf_fixup_kfunc_call`. It grabs the `desc` from `find_kfunc_desc`, then copies to `desc_copy`. Where does `find_kfunc_desc` get its data from? That's right, from the `tab->descs`, which are the function descriptors stored in the table. Now, how was `tab->descs` populated during `bpf_add_kfunc_call`? That's the crucial question. I need to trace back from `find_kfunc_desc` to the initial population of the table. Let me check `bpf_add_kfunc_call`. |
| 58/3 | 2026/09/30 01:00 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 2970,
"LineCount": 35
}Results: {
"Contents": "2970:\t\t\t\t\tkfunc.name);\n2971:\t\t\t\treturn -EOPNOTSUPP;\n2972:\t\t\t}\n2973:\t\t}\n2974:\t\n2975:\t\tmemset(\u0026meta, 0, sizeof(meta));\n2976:\t\tmeta.btf = kfunc.btf;\n2977:\t\tmeta.func_id = kfunc.id;\n2978:\t\tmeta.func_proto = kfunc.proto;\n2979:\t\tmeta.func_name = kfunc.name;\n2980:\t\tmeta.kfunc_flags = kfunc.flags ? *kfunc.flags : 0;\n2981:\t\n2982:\t\ttab = krealloc(tab, struct_size(tab, descs, tab-\u003enr_descs + 1), GFP_KERNEL_ACCOUNT);\n2983:\t\tif (!tab)\n2984:\t\t\treturn -ENOMEM;\n2985:\t\tprog_aux-\u003ekfunc_tab = tab;\n2986:\t\n2987:\t\tdesc = \u0026tab-\u003edescs[tab-\u003enr_descs];\n2988:\t\tmemset(desc, 0, sizeof(*desc));\n2989:\t\n2990:\t\terr = gen_kfunc_arg_proto(env, \u0026meta, \u0026func_model, \u0026desc-\u003eproto);\n2991:\t\tif (err)\n2992:\t\t\treturn err;\n2993:\t\n2994:\t\tdesc-\u003efunc_id = func_id;\n2995:\t\tdesc-\u003eoffset = offset;\n2996:\t\tdesc-\u003eaddr = addr;\n2997:\t\tdesc-\u003efunc_model = func_model;\n2998:\t\ttab-\u003enr_descs++;\n2999:\t\ttab-\u003enr_base_descs++;\n3000:\t\tsort(tab-\u003edescs, tab-\u003enr_base_descs, sizeof(tab-\u003edescs[0]),\n3001:\t\t kfunc_desc_cmp_by_id_off, NULL);\n3002:\t\treturn 0;\n3003:\t}\n3004:\t\n"
} |
| 59/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31847 output: 36 thoughts: 1847 Thoughts: **Unraveling Potential BPF Memory Issues** Okay, so I'm diving into this BPF code, and initially, it seems like the `bpf_kfunc_desc` struct is always zero-initialized, then copied. That's good, minimizes the chance of garbage values. But, I need to check how it's *used*. Jumping into `bpf_jit_find_kfunc_model` and `bpf_get_kfunc_addr`, I see a reliance on `insn->off` or `desc_idx` as indices into an array of `bpf_kfunc_desc` structs within a `bpf_kfunc_desc_tab`. The code checks bounds, preventing out-of-bounds reads. However, is there potential for uninitialized memory to sneak through? My next thought is to investigate the allocation and freeing of the memory where these descriptors live. That leads me to `apply_range_set_cb` which has me wondering how pages are actually managed during mapping. I see pages being added to an LIFO list (`pages`), and then later, `apply_range_set_cb` pops them off one by one to configure the PTEs for mapping. The code makes sense, it maps a contiguous chunk of memory in page-sized increments. If `apply_to_page_range` has an error, what happens? Looking deeper at the error handling, I see that partial mappings are cleaned up – the successfully mapped pages are unmapped and freed, and any *unmapped* pages remain on the llist which are then freed as well. That is handled correctly! Now, I'm thinking about the scenario of an error *within* `apply_range_set_cb`. If `apply_to_page_range` fails after some pages are popped from the list, are those pages freed? I can see from the code that `llist_del_first(&pages)` *does* remove the most recently added page from the list on failure, which looks correct. I will need to confirm this line by line. So, in `arena_vm_fault`, if `apply_to_page_range` fails *after* a page has been added, then `llist_del_first` removes it. I think I've got it, the code looks like it handles all failure cases, and cleans up properly to prevent uninitialized memory issues and potential leaks. |
| 60/3 | 2026/09/30 01:00 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/arena.c",
"FirstLine": 540,
"LineCount": 45
}Results: {
"Contents": " 540:\t\t\t * by bpf prog\n 541:\t\t\t */\n 542:\t\t\tfault_ret = VM_FAULT_SIGSEGV;\n 543:\t\t\tgoto out_err_locked;\n 544:\t\t}\n 545:\t\n 546:\t\tbpf_map_memcg_enter(\u0026arena-\u003emap, \u0026old_memcg, \u0026new_memcg);\n 547:\t\n 548:\t\tif (!new_page) {\n 549:\t\t\t/*\n 550:\t\t\t * The probed page was freed meanwhile or preallocation failed;\n 551:\t\t\t * try the non-blocking allocator, we cannot sleep here.\n 552:\t\t\t */\n 553:\t\t\tnew_page = bpf_alloc_page(map-\u003enuma_node, false);\n 554:\t\t\tif (!new_page) {\n 555:\t\t\t\tfault_ret = VM_FAULT_SIGBUS;\n 556:\t\t\t\tgoto out_err_locked_memcg;\n 557:\t\t\t}\n 558:\t\t}\n 559:\t\n 560:\t\tret = range_tree_clear(\u0026arena-\u003ert, vmf-\u003epgoff, 1);\n 561:\t\tif (ret) {\n 562:\t\t\tfault_ret = VM_FAULT_SIGBUS;\n 563:\t\t\tgoto out_err_locked_memcg;\n 564:\t\t}\n 565:\t\tllist_add(\u0026new_page-\u003epcp_llist, \u0026pages);\n 566:\t\tdata.arena = arena;\n 567:\t\tdata.pages = \u0026pages;\n 568:\t\tdata.i = 0;\n 569:\t\n 570:\t\tret = apply_to_page_range(\u0026init_mm, kaddr, PAGE_SIZE, apply_range_set_cb, \u0026data);\n 571:\t\tif (ret) {\n 572:\t\t\tllist_del_first(\u0026pages);\n 573:\t\t\trange_tree_set(\u0026arena-\u003ert, vmf-\u003epgoff, 1);\n 574:\t\t\tfault_ret = VM_FAULT_SIGBUS;\n 575:\t\t\tgoto out_err_locked_memcg;\n 576:\t\t}\n 577:\t\tflush_vmap_cache(kaddr, PAGE_SIZE);\n 578:\t\tbpf_map_memcg_exit(old_memcg, new_memcg);\n 579:\t\t/* new_page was consumed */\n 580:\t\tpage = new_page;\n 581:\t\tnew_page = NULL;\n 582:\tout:\n 583:\t\tpage_ref_add(page, 1);\n 584:\t\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n"
} |
| 61/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34968 output: 36 thoughts: 50 Thoughts: Okay, let's break this down. **Investigating the `out_err_locked_memcg` Function's Interaction with `new_page`** Right, so I need to understand what happens when `out_err_locked_memcg` encounters a `new_page`. The most direct route to that answer, given my familiarity with the kernel's memory management, is to dig into the relevant code. I'm going to jump straight into `kernel/bpf/arena.c` and focus on lines 585 through 610. That should give me the core logic related to this specific interaction. I'm expecting to find details on how it handles the page, potentially allocation/deallocation, error handling, and any associated memcg operations. |
| 62/3 | 2026/09/30 01:00 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/arena.c",
"FirstLine": 585,
"LineCount": 35
}Results: {
"Contents": " 585:\t\tif (new_page)\n 586:\t\t\tfree_pages_nolock(new_page, 0);\n 587:\t\tvmf-\u003epage = page;\n 588:\t\treturn 0;\n 589:\t\n 590:\tout_err_locked_memcg:\n 591:\t\tbpf_map_memcg_exit(old_memcg, new_memcg);\n 592:\tout_err_locked:\n 593:\t\traw_res_spin_unlock_irqrestore(\u0026arena-\u003espinlock, flags);\n 594:\t\tif (new_page)\n 595:\t\t\tfree_pages_nolock(new_page, 0);\n 596:\t\treturn fault_ret;\n 597:\t}\n 598:\t\n 599:\tstatic const struct vm_operations_struct arena_vm_ops = {\n 600:\t\t.open\t\t= arena_vm_open,\n 601:\t\t.may_split\t= arena_vm_may_split,\n 602:\t\t.mremap\t\t= arena_vm_mremap,\n 603:\t\t.close\t\t= arena_vm_close,\n 604:\t\t.fault = arena_vm_fault,\n 605:\t};\n 606:\t\n 607:\tstatic unsigned long arena_get_unmapped_area(struct file *filp, unsigned long addr,\n 608:\t\t\t\t\t\t unsigned long len, unsigned long pgoff,\n 609:\t\t\t\t\t\t unsigned long flags)\n 610:\t{\n 611:\t\tstruct bpf_map *map = filp-\u003eprivate_data;\n 612:\t\tstruct bpf_arena *arena = container_of(map, struct bpf_arena, map);\n 613:\t\tlong ret;\n 614:\t\n 615:\t\tif (pgoff)\n 616:\t\t\treturn -EINVAL;\n 617:\t\tif (len \u003e SZ_4G)\n 618:\t\t\treturn -E2BIG;\n 619:\t\n"
} |
| 63/3 | 2026/09/30 01:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35767 output: 36 thoughts: 549 Thoughts: **Analyzing Potential Memory Issues**
Okay, so I'm looking at this code and initially, I see that `new_page` is freed in `out_err_locked` using `free_pages_nolock(new_page, 0)`. My immediate thought is, "Standard memory management! Gotta watch out for leaks or double frees; KASAN and the page allocator should catch these though." But wait, let's step back and address the specific questions.
The questions are about whether the patch series introduces or modifies kernel structures sent to user space where fields or structure padding might not be fully initialized/zeroed. No, nothing seems to be copied to user space here. Oh, but wait! What about those pages allocated for the BPF arena? Those are mapped into user space! Okay, this *is* a potential problem area. Let's see how arena pages are handled in user space to see if this is an issue.
Digging into the code, I see that in `arena_vm_fault` the arena page mapped to user space is `new_page = bpf_alloc_page(map->numa_node, false);`. That seems fine, but let's see how that page gets allocated. Looking at `arena_alloc_pages`, pages are allocated via `bpf_alloc_pages(node_id, page_cnt, &pages, sleepable);`. Let's trace it and see how `bpf_alloc_page` is implemented:
```c
struct page *bpf_alloc_page(int nid, bool sleepable)
{
if (!sleepable || !can_alloc_pages())
return alloc_pages_nolock(__GFP_ACCOUNT, nid, 0);
return alloc_pages_node(nid,
GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT
| __GFP_NOWARN | __GFP_RETRY_MAYFAIL,
0);
}
```
Okay, I remember seeing that `alloc_pages_nolock` is being called and `alloc_pages_node` also being called. We previously checked `alloc_pages_nolock`:
```c
static const gfp_t gfp_nolock = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_COMP;
```
Aha! It's using `gfp_nolock` which *includes* `__GFP_ZERO`! And look, `alloc_pages_node` explicitly uses `__GFP_ZERO` too. This is great, both the sleepable and non-sleepable paths explicitly zero every page allocated. Okay, that's reassuring.
Just to be absolutely certain, I'm going to quickly verify that `alloc_pages_nolock` really *does* zero the page during allocation. I'm going to check `mm/page_alloc.c` around lines 5400-5450, just to be thorough and confirm the implementation.
|
| 64/3 | 2026/09/30 01:01 | tool | read-file |
0mArgs:{
"File": "mm/page_alloc.c",
"FirstLine": 5400,
"LineCount": 45
}Results: {
"Contents": "5400:\t\tif (alloc_flags \u0026 ALLOC_NOLOCK) {\n5401:\t\t\t/* Certain other flags could be supported later if needed. */\n5402:\t\t\tVM_WARN_ON_ONCE(gfp \u0026 ~(__GFP_ACCOUNT | gfp_nolock));\n5403:\t\t\tif (!alloc_nolock_allowed())\n5404:\t\t\t\treturn NULL;\n5405:\t\t\tgfp |= gfp_nolock;\n5406:\t\t\tfastpath_alloc_flags |= ALLOC_WMARK_MIN;\n5407:\t\t} else {\n5408:\t\t\tfastpath_alloc_flags |= ALLOC_WMARK_LOW;\n5409:\t\t}\n5410:\t\n5411:\t\tgfp \u0026= gfp_allowed_mask;\n5412:\t\t/*\n5413:\t\t * Apply scoped allocation constraints. This is mainly about GFP_NOFS\n5414:\t\t * resp. GFP_NOIO which has to be inherited for all allocation requests\n5415:\t\t * from a particular context which has been marked by\n5416:\t\t * memalloc_no{fs,io}_{save,restore}. And PF_MEMALLOC_PIN which ensures\n5417:\t\t * movable zones are not used during allocation.\n5418:\t\t */\n5419:\t\tgfp = current_gfp_context(gfp);\n5420:\t\talloc_gfp = gfp;\n5421:\t\tif (!prepare_alloc_pages(gfp, order, preferred_nid, nodemask, \u0026ac,\n5422:\t\t\t\t\u0026alloc_gfp, \u0026fastpath_alloc_flags))\n5423:\t\t\treturn NULL;\n5424:\t\n5425:\t\tif (!(alloc_flags \u0026 ALLOC_NOLOCK)) {\n5426:\t\t\t/*\n5427:\t\t\t * Forbid the first pass from falling back to types that\n5428:\t\t\t * fragment memory until all local zones are considered.\n5429:\t\t\t */\n5430:\t\t\tfastpath_alloc_flags |= alloc_flags_nofragment(\n5431:\t\t\t\tzonelist_zone(ac.preferred_zoneref), gfp);\n5432:\t\t}\n5433:\t\tfastpath_alloc_flags |= alloc_flags_nonblocking(gfp, order) \u0026 ALLOC_HIGHATOMIC;\n5434:\t\n5435:\t\t/* First allocation attempt (or, for nolock, only attempt) */\n5436:\t\tpage = get_page_from_freelist(alloc_gfp, order, fastpath_alloc_flags, \u0026ac);\n5437:\t\tif (likely(page) || (alloc_flags \u0026 ALLOC_NOLOCK))\n5438:\t\t\tgoto out;\n5439:\t\n5440:\t\talloc_gfp = gfp;\n5441:\t\tac.spread_dirty_pages = false;\n5442:\t\n5443:\t\t/*\n5444:\t\t * Restore the original nodemask if it was potentially replaced with\n"
} |
| 65/3 | 2026/09/30 01:01 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37773 output: 25 thoughts: 941 Thoughts: **Analyzing the Implications of the BPF Patch** Okay, let's break this down systematically. First, the memory allocation changes are straightforward. The core seems to be that `__GFP_ZERO` is now consistently being set, meaning pages are always zeroed. This is achieved through `gfp |= gfp_nolock;` and the subsequent call chain through `get_page_from_freelist` and `prep_new_page`. This zeroing behavior, however, isn't new, as `alloc_pages_node` with `__GFP_ZERO` was already in use. The main change here is the shift from batch allocation with `kmalloc_nolock` for a temporary `struct page *` buffer, to an `llist_head` managed by `page->pcp_llist`. This implies a more fine-grained page management with individual pages linked rather than batch processing. `bpf_free_pages` using `llist_del_all` and `free_pages_nolock` confirms this. Now, the second part of the patch, concerning kfunc descriptors and call specialization, is where it gets interesting. I see a few key changes: The `s32 imm` field in `bpf_kfunc_desc` is gone, and `u32 nr_base_descs` is added to `bpf_kfunc_desc_tab`. In `bpf_add_kfunc_call`, `nr_base_descs` is now critical, being checked against `MAX_KFUNC_DESCS`, and it's incremented along with `nr_descs`. The sorting now only applies to these base descriptors. The `find_kfunc_desc` function leverages `bsearch` on the base descriptors. The `add_kfunc_desc_target` function is where the call specialization logic lies: It checks for the target's presence within the `tab->descs` array (either base or extended descriptors), reallocates the table using `krealloc` if needed, and increments `tab->nr_descs`. `bpf_fixup_kfunc_call` calls `specialize_kfunc` and `add_kfunc_desc_target` as expected, updating `insn->off` with the `desc_idx`. In `bpf_jit_find_kfunc_model`, the code now relies on the `insn->off` index (which is `desc_idx` from the previous functions) to fetch the `bpf_kfunc_desc` from `tab->descs`. This function also does bounds checking on `insn->off`. `bpf_get_kfunc_addr` takes `desc_idx` as input instead of `btf_fd_idx`, does bounds checking, and retrieves the function address from the descriptor. The validation against `func_id` or `addr` against `insn->imm` suggests that there's a strong connection between the `insn`'s immediate value and the kfunc descriptor. To fully grasp the impact, I need to look for any other callers of `bpf_jit_find_kfunc_model` to understand how the new index based access is integrated throughout the codebase. The change is clearly focused on refining and optimizing the handling of kfunc descriptors during JIT compilation. |
| 66/3 | 2026/09/30 01:01 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_find_kfunc_model"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1357=static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1775-\narch/arm64/net/bpf_jit_comp.c:1776:\t\t\tfm = bpf_jit_find_kfunc_model(ctx-\u003eprog, insn);\narch/arm64/net/bpf_jit_comp.c-1777-\t\t\tif (!fm)\n--\narch/loongarch/net/bpf_jit.c=694=static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extra_pass)\n--\narch/loongarch/net/bpf_jit.c-1179-\narch/loongarch/net/bpf_jit.c:1180:\t\t\tm = bpf_jit_find_kfunc_model(ctx-\u003eprog, insn);\narch/loongarch/net/bpf_jit.c-1181-\t\t\tif (!m)\n--\narch/powerpc/net/bpf_jit_comp64.c=614=static int prepare_for_kfunc_call(const struct bpf_prog *fp, u32 *image,\n--\narch/powerpc/net/bpf_jit_comp64.c-617-{\narch/powerpc/net/bpf_jit_comp64.c:618:\tconst struct btf_func_model *m = bpf_jit_find_kfunc_model(fp, insn);\narch/powerpc/net/bpf_jit_comp64.c-619-\tint i;\n--\narch/riscv/net/bpf_jit_comp64.c=1399=int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\n--\narch/riscv/net/bpf_jit_comp64.c-1857-\narch/riscv/net/bpf_jit_comp64.c:1858:\t\t\tfm = bpf_jit_find_kfunc_model(ctx-\u003eprog, insn);\narch/riscv/net/bpf_jit_comp64.c-1859-\t\t\tif (!fm)\n--\narch/s390/net/bpf_jit_comp.c=971=static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,\n--\narch/s390/net/bpf_jit_comp.c-1875-\t\tif (insn-\u003esrc_reg == BPF_PSEUDO_KFUNC_CALL) {\narch/s390/net/bpf_jit_comp.c:1876:\t\t\tm = bpf_jit_find_kfunc_model(fp, insn);\narch/s390/net/bpf_jit_comp.c-1877-\t\t\tif (!m)\n--\narch/x86/net/bpf_jit_comp.c=2002=static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n--\narch/x86/net/bpf_jit_comp.c-2953-\t\t\tif (src_reg == BPF_PSEUDO_KFUNC_CALL) {\narch/x86/net/bpf_jit_comp.c:2954:\t\t\t\tfm = bpf_jit_find_kfunc_model(bpf_prog, insn);\narch/x86/net/bpf_jit_comp.c-2955-\t\t\t\tif (!fm)\n--\narch/x86/net/bpf_jit_comp32.c=1422=static u8 get_cond_jmp_opcode(const u8 op, bool is_cmp_lo)\n--\narch/x86/net/bpf_jit_comp32.c-1543- * emit_kfunc_call() finds out the btf_func_model by calling\narch/x86/net/bpf_jit_comp32.c:1544: * bpf_jit_find_kfunc_model(). A btf_func_model\narch/x86/net/bpf_jit_comp32.c-1545- * has the details about the number of args, size of each arg,\n--\narch/x86/net/bpf_jit_comp32.c=1569=static int emit_kfunc_call(const struct bpf_prog *bpf_prog, u8 *end_addr,\n--\narch/x86/net/bpf_jit_comp32.c-1580-\narch/x86/net/bpf_jit_comp32.c:1581:\tfm = bpf_jit_find_kfunc_model(bpf_prog, insn);\narch/x86/net/bpf_jit_comp32.c-1582-\tif (!fm)\n--\ninclude/linux/bpf.h=3300=const struct btf_func_model *\ninclude/linux/bpf.h:3301:bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\ninclude/linux/bpf.h-3302-\t\t\t const struct bpf_insn *insn);\n--\ninclude/linux/bpf.h=3638=static inline const struct btf_func_model *\ninclude/linux/bpf.h:3639:bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\ninclude/linux/bpf.h-3640-\t\t\t const struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c=118=const struct btf_func_model *\nkernel/bpf/fixups.c:119:bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\nkernel/bpf/fixups.c-120-\t\t\t const struct bpf_insn *insn)\n"
} |
| 67/3 | 2026/09/30 01:01 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41040 output: 409 thoughts: 2167 Thoughts: **KMSAN Evaluation: NeedsKMSAN = false** Okay, let's break this down. We're looking at changes in `kernel/bpf/core.c` related to BPF kfunc calls and arena page management. Specifically, it seems like the `insn->off` field, which used to be `btf_fd_idx`, is now being used as `desc_idx`, passed to `bpf_get_kfunc_addr`. No problem there, but let's be thorough and analyze potential risks. First, let's rule out uninitialized variables. Everything looks initialized. The `arena_vm_fault`, `arena_alloc_pages`, `bpf_alloc_pages`, `bpf_free_pages`, `bpf_jit_find_kfunc_model`, `add_kfunc_desc_target`, and `bpf_fixup_kfunc_call` functions all appear to handle memory correctly. `LLIST_HEAD` ensures initialization, and complex structures are populated before use. Page allocations are zeroed. The `bpf_kfunc_desc` struct is initialized from an existing descriptor, which, crucially, was zeroed during verification. Bounds checks are now explicit. The key KMSAN rule: does the patch introduce or modify things that could leak uninitialized memory? No. Nothing is going to user space uninitialized. There's no conditional logic that depends on garbage data. Data structures are allocated and initialized correctly, and bounds checks are now more robust than before. This suggests no. Now, what *could* go wrong? We're talking about potential out-of-bounds accesses in the descriptor table, memory leaks, linked list corruption, and similar issues. But these are all the usual suspects like KASAN, LOCKDEP, and standard bug detectors catch. They're not "uninitialized memory" bugs. So, the conclusion is clear. This refactoring focuses on replacing dynamic arrays of page pointers with linked lists and optimizing descriptor table management for kfunc calls by changing how indices work. It's not introducing uninitialized memory risks. All allocations are zeroed. The code is carefully initialized. The checks for `insn->off` are now explicit. Therefore, KMSAN is overkill here. We're not dealing with the kind of uninitialized-memory-related risks that KMSAN is designed to catch. We should set `NeedsKMSAN=false` and move on. |
| 68/3 | 2026/09/30 01:01 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series covers two main areas:\n1. BPF arena memory allocation refactoring: replacing temporary pointer arrays allocated with kmalloc_nolock() by an llist of struct pages linked via page-\u003epcp_llist (bpf_alloc_page/bpf_alloc_pages/bpf_free_pages).\n2. Kfunc descriptor table indexing for call specialization: expanding bpf_kfunc_desc_tab with krealloc to track specialized call targets alongside canonical descriptors, switching JIT lookup from sorting/bsearch to direct index-based lookups using insn-\u003eoff.\n\nKMSAN vs KASAN applicability:\n- Uninitialized memory / Info-leaks (KMSAN): All arena pages allocated through bpf_alloc_page() are explicitly zero-initialized at allocation time (alloc_pages_node uses __GFP_ZERO, and alloc_pages_nolock inherently enforces __GFP_ZERO via gfp_nolock). Stack and heap structures (such as apply_range_data and llist_head) are fully initialized before use. The new kfunc descriptors appended via krealloc in add_kfunc_desc_target() are directly copied from base descriptors that were previously zeroed via memset during bpf_add_kfunc_call(). No uninitialized data or padding is exposed or copied to user space.\n- Memory corruption / Bounds / Lifetime (KASAN): Potential bugs in this patch involve out-of-bounds indexing into tab-\u003edescs, krealloc resizing issues, linked-list corruption, or page refcount/freeing errors. These failure modes are comprehensively covered by KASAN, LOCKDEP, and page allocator debug checks.\n\nBecause there are no uninitialized memory risks or data leaks that escape KASAN detection, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series covers two main areas:\n1. BPF arena memory allocation refactoring: replacing temporary pointer arrays allocated with kmalloc_nolock() by an llist of struct pages linked via page-\u003epcp_llist (bpf_alloc_page/bpf_alloc_pages/bpf_free_pages).\n2. Kfunc descriptor table indexing for call specialization: expanding bpf_kfunc_desc_tab with krealloc to track specialized call targets alongside canonical descriptors, switching JIT lookup from sorting/bsearch to direct index-based lookups using insn-\u003eoff.\n\nKMSAN vs KASAN applicability:\n- Uninitialized memory / Info-leaks (KMSAN): All arena pages allocated through bpf_alloc_page() are explicitly zero-initialized at allocation time (alloc_pages_node uses __GFP_ZERO, and alloc_pages_nolock inherently enforces __GFP_ZERO via gfp_nolock). Stack and heap structures (such as apply_range_data and llist_head) are fully initialized before use. The new kfunc descriptors appended via krealloc in add_kfunc_desc_target() are directly copied from base descriptors that were previously zeroed via memset during bpf_add_kfunc_call(). No uninitialized data or padding is exposed or copied to user space.\n- Memory corruption / Bounds / Lifetime (KASAN): Potential bugs in this patch involve out-of-bounds indexing into tab-\u003edescs, krealloc resizing issues, linked-list corruption, or page refcount/freeing errors. These failure modes are comprehensively covered by KASAN, LOCKDEP, and page allocator debug checks.\n\nBecause there are no uninitialized memory risks or data leaks that escape KASAN detection, 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) |
|---|