| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/27 17:40 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"arena_alloc_pages",
"bpf_arena_alloc_pages",
"bpf_alloc_pages",
"bpf_free_pages",
"apply_range_set_cb",
"add_kfunc_desc_target",
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model"
],
"KMSANReasoning": "The patch series consists of two main changes:\n1. BPF arena memory management refactoring: Replaces the array-based page allocation and tracking (kmalloc_nolock array of struct page *) with a lockless singly-linked list (llist_head and struct page's pcp_llist member). The page allocation helpers bpf_alloc_page/bpf_alloc_pages ensure allocated pages are zeroed (via alloc_pages_node with __GFP_ZERO for sleepable contexts and alloc_pages_nolock which internally enforces __GFP_ZERO via gfp_nolock). Stack structures such as apply_range_data are fully initialized with all fields explicitly set.\n2. BPF kfunc descriptor table support for far-call JITs and specialized call targets: Dynamically extends the kfunc descriptor table (bpf_kfunc_desc_tab) using krealloc and initializes each appended descriptor by copying the specialized target descriptor. Bounds checks are strictly enforced (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs and desc_idx \u003e= tab-\u003enr_descs).\n\nNo uninitialized heap, stack, or page memory is read, branched upon, or exposed to user space. Potential bugs introduced by these changes would involve out-of-bounds indexing, memory leaks, linked-list corruption, or concurrency issues, all of which are covered by KASAN, LOCKDEP, and standard kernel debugging facilities. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies core BPF logic across arena memory allocation and kfunc descriptor management in the verifier and JIT fixups. It replaces the page array allocation mechanism in BPF arena with an llist-based approach (bpf_alloc_pages, bpf_free_pages, apply_range_set_cb), refactors arena tree adjustments and fault handling, and alters kfunc descriptor table tracking and specialization (add_kfunc_desc_target, bpf_fixup_kfunc_call, bpf_add_kfunc_call) with added WARN_ON_ONCE assertions. These changes affect reachable code paths accessible via the bpf syscall.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/27 17:40 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 32b39aabb2327eb62a0c39d8084cf0e3326b365f\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Sep 27 17:40:18 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf.h b/include/linux/bpf.h\nindex e7c5e203edddb..5a9580b1769de 100644\n--- a/include/linux/bpf.h\n+++ b/include/linux/bpf.h\n@@ -2884,8 +2884,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@@ -3281,7 +3283,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@@ -3624,7 +3626,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 92f528c456052..da219eb0a9cb1 100644\n--- a/include/linux/bpf_verifier.h\n+++ b/include/linux/bpf_verifier.h\n@@ -1714,6 +1714,8 @@ 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 \n struct bpf_kfunc_desc {\n \tstruct btf_func_model func_model;\n@@ -1726,12 +1728,17 @@ struct bpf_kfunc_desc {\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. 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. Near-call JITs look up\n+\t * descriptors by imm and offset after do_misc_fixups() sorts the table.\n+\t * Far-call JITs use the descriptor index stored in the finalized call's\n+\t * off field, so their table remains in verification order.\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 2add8001c3ec3..b9f76eee50160 100644\n--- a/kernel/bpf/fixups.c\n+++ b/kernel/bpf/fixups.c\n@@ -140,6 +140,13 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n \tstruct bpf_kfunc_desc_tab *tab;\n \n \ttab = prog-\u003eaux-\u003ekfunc_tab;\n+\tif (bpf_jit_supports_far_kfunc_call()) {\n+\t\tif (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs)\n+\t\t\treturn NULL;\n+\t\tres = \u0026tab-\u003edescs[insn-\u003eoff];\n+\t\treturn res-\u003efunc_id == insn-\u003eimm ? \u0026res-\u003efunc_model : NULL;\n+\t}\n+\n \tres = bsearch(\u0026desc, tab-\u003edescs, tab-\u003enr_descs,\n \t\t sizeof(tab-\u003edescs[0]), kfunc_desc_cmp_by_imm_off);\n \n@@ -2517,11 +2524,14 @@ 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+\t/*\n+\t * Do not change kfunc desc position into the table for far JIT.\n+\t * because we use the indices in the instructions.\n+\t */\n+\tif (bpf_jit_supports_far_kfunc_call())\n+\t\treturn 0;\n \n-\treturn 0;\n+\treturn sort_kfunc_descs_by_imm_off(env);\n }\n \n static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,\ndiff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c\nindex 74496fd716d3b..b3b0cd349eefd 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 a7c9e2d8965d5..12e33a568a3e9 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -2570,17 +2570,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@@ -2920,10 +2924,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@@ -2981,7 +2987,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@@ -21299,6 +21306,44 @@ 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 *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+\tfor (i = 0; 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@@ -21319,7 +21364,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 desc_idx;\n+\tbool near_call;\n \tint err;\n \n \tif (!insn-\u003eimm) {\n@@ -21340,12 +21389,29 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n \t\treturn -EFAULT;\n \t}\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, \u0026desc_idx);\n+\tif (err)\n+\t\treturn err;\n+\tif (!near_call)\n+\t\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/27 17:40 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"arena_alloc_pages",
"bpf_arena_alloc_pages",
"bpf_alloc_pages",
"bpf_free_pages",
"apply_range_set_cb",
"add_kfunc_desc_target",
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model"
],
"Reasoning": "The patch modifies core BPF logic across arena memory allocation and kfunc descriptor management in the verifier and JIT fixups. It replaces the page array allocation mechanism in BPF arena with an llist-based approach (bpf_alloc_pages, bpf_free_pages, apply_range_set_cb), refactors arena tree adjustments and fault handling, and alters kfunc descriptor table tracking and specialization (add_kfunc_desc_target, bpf_fixup_kfunc_call, bpf_add_kfunc_call) with added WARN_ON_ONCE assertions. These changes affect reachable code paths accessible 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 32b39aabb2327eb62a0c39d8084cf0e3326b365f
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 27 17:40:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index e7c5e203edddb..5a9580b1769de 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2884,8 +2884,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);
@@ -3281,7 +3283,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;
@@ -3624,7 +3626,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 92f528c456052..da219eb0a9cb1 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1714,6 +1714,8 @@ 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)
struct bpf_kfunc_desc {
struct btf_func_model func_model;
@@ -1726,12 +1728,17 @@ struct bpf_kfunc_desc {
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. The first nr_base_descs entries are the canonical
+ * descriptors used for verifier lookups. Call specialization may append
+ * immutable descriptors for additional targets. Near-call JITs look up
+ * descriptors by imm and offset after do_misc_fixups() sorts the table.
+ * Far-call JITs use the descriptor index stored in the finalized call's
+ * off field, so their table remains in verification order.
*
- * 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 2add8001c3ec3..b9f76eee50160 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -140,6 +140,13 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
struct bpf_kfunc_desc_tab *tab;
tab = prog->aux->kfunc_tab;
+ if (bpf_jit_supports_far_kfunc_call()) {
+ if (insn->off < 0 || insn->off >= tab->nr_descs)
+ return NULL;
+ res = &tab->descs[insn->off];
+ return res->func_id == insn->imm ? &res->func_model : NULL;
+ }
+
res = bsearch(&desc, tab->descs, tab->nr_descs,
sizeof(tab->descs[0]), kfunc_desc_cmp_by_imm_off);
@@ -2517,11 +2524,14 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
}
}
- ret = sort_kfunc_descs_by_imm_off(env);
- if (ret)
- return ret;
+ /*
+ * Do not change kfunc desc position into the table for far JIT.
+ * because we use the indices in the instructions.
+ */
+ if (bpf_jit_supports_far_kfunc_call())
+ return 0;
- return 0;
+ return sort_kfunc_descs_by_imm_off(env);
}
static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 74496fd716d3b..b3b0cd349eefd 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 a7c9e2d8965d5..12e33a568a3e9 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2570,17 +2570,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;
@@ -2920,10 +2924,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)
@@ -2981,7 +2987,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;
}
@@ -21299,6 +21306,44 @@ 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 *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;
+ for (i = 0; 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,
@@ -21319,7 +21364,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 desc_idx;
+ bool near_call;
int err;
if (!insn->imm) {
@@ -21340,12 +21389,29 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
return -EFAULT;
}
+ 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, &desc_idx);
+ if (err)
+ return err;
+ if (!near_call)
+ 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/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14347 output: 30 thoughts: 561 Thoughts: **My Assessment of the Git Commit for Fuzzing with syzkaller** Alright, let's dive into this commit and determine if it warrants fuzzing with syzkaller. The patch touches quite a few files: `include/linux/bpf.h`, `include/linux/bpf_verifier.h`, `kernel/bpf/arena.c`, `kernel/bpf/fixups.c`, `kernel/bpf/syscall.c`, `kernel/bpf/verifier.c`, and some self-tests. Wait a second, this is *all* core BPF code! Specifically, `kernel/bpf/arena.c`, `kernel/bpf/fixups.c`, `kernel/bpf/syscall.c`, and `kernel/bpf/verifier.c` are being modified. BPF is a key subsystem, and it's directly accessible from userspace through the `bpf()` syscall. This immediately flags it for potential fuzzing. Looking at the established criteria, this commit squarely hits a couple of high-risk areas. It impacts core subsystems, specifically BPF, and it also seems to involve refactoring and code cleanup within reachable data structures and algorithms. I'm also seeing runtime assertions being introduced! In `kernel/bpf/arena.c`, there are `WARN_ON_ONCE` checks like `WARN_ON_ONCE(!node)` and `WARN_ON_ONCE(llist_del_first(d->pages) != node)`. `kernel/bpf/verifier.c` includes a `WARN_ON_ONCE(tab->nr_descs != tab->nr_base_descs)`. This points towards potential issues being uncovered by new runtime checks. Furthermore, there is allocation logic rewritten. Specifically `arena_alloc_pages` is now using `llist` instead of an array of `struct page *`. We also have `bpf_alloc_pages`, `bpf_free_pages`, and `arena_adjust_tree`. There are also kfunc table changes: `add_kfunc_desc_target`, `bpf_jit_find_kfunc_model`, `bpf_do_misc_fixups`, `bpf_fixup_kfunc_call`, `bpf_get_kfunc_addr`. Given the scope and nature of these modifications, I'm confident in assessing this as **WorthFuzzing = true**. Now, let's determine the appropriate `FocusSymbols` and `EnableConfigs` based on the code and its Kconfig requirements. We'll utilize the tooling to make sure we're targeting the right areas for maximum impact. |
| 4/2 | 2026/09/27 17:40 | tool | grepper |
0mArgs:{
"Expression": "bpf_alloc_pages",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/arena.c=741=static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt, int node_id,\n--\nkernel/bpf/arena.c-773-\nkernel/bpf/arena.c:774:\tret = bpf_alloc_pages(node_id, page_cnt, \u0026pages, sleepable);\nkernel/bpf/arena.c-775-\tif (ret)\n--\nkernel/bpf/syscall.c=616=void bpf_free_pages(struct llist_head *pages)\n--\nkernel/bpf/syscall.c-625-\nkernel/bpf/syscall.c:626:int bpf_alloc_pages(int nid, unsigned long nr_pages,\nkernel/bpf/syscall.c-627-\t\t struct llist_head *pages, bool sleepable)\n"
} |
| 5/2 | 2026/09/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15746 output: 27 thoughts: 42 Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts: **Investigating BPF Arena and Syscall Kconfig Dependencies** Alright, time to get to the bottom of the BPF arena and syscall situation. First, I need to understand the Kconfig dependencies here. I'm going to quickly check where `kernel/bpf/arena.c` is actually built. The obvious place to start is the `kernel/bpf/Makefile`. That's where I would expect to see the build rules defined, and hopefully, the relevant Kconfig options tied to them. I'm expecting to find out some specifics around the context of the compilation. |
| 6/2 | 2026/09/27 17:40 | tool | grepper |
0mArgs:{
"Expression": "arena",
"PathPrefix": "kernel/bpf/Makefile"
}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/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16051 output: 27 thoughts: 74 Thoughts: Here's my thought process on this snippet: **Diving into BPF Arena and JIT Considerations** Okay, so I'm looking at `kernel/bpf/arena.c` and immediately my brain flags that it's compiled under `CONFIG_BPF_SYSCALL`, and that implies the presence of `CONFIG_MMU` and a 64-bit architecture, which makes sense in the context of modern BPF implementations. My next thought is to pivot towards the JIT compiler. I need to understand if JIT compilation is enabled for this code path, so I need to check the value of `CONFIG_BPF_JIT`. If it's enabled, then I'll likely want to understand what aspects of the JIT this code may be touching. I'm especially curious about whether there's any far kernel function calling involved, so I'll need to locate and evaluate the `bpf_jit_supports_far_kfunc_call()` function within the kernel. This will likely give me some insight into how this arena code plays with the JIT's architecture, and especially where to look for optimizations. |
| 8/2 | 2026/09/27 17:40 | 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=1242=bool bpf_jit_supports_arena_args(void);\ninclude/linux/filter.h:1243:bool bpf_jit_supports_far_kfunc_call(void);\ninclude/linux/filter.h-1244-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=3394=bool __weak bpf_jit_supports_arena_args(void)\n--\nkernel/bpf/core.c-3398-\nkernel/bpf/core.c:3399:bool __weak bpf_jit_supports_far_kfunc_call(void)\nkernel/bpf/core.c-3400-{\n--\nkernel/bpf/fixups.c=132=bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n--\nkernel/bpf/fixups.c-142-\ttab = prog-\u003eaux-\u003ekfunc_tab;\nkernel/bpf/fixups.c:143:\tif (bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/fixups.c-144-\t\tif (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs)\n--\nkernel/bpf/fixups.c=156=static int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)\n--\nkernel/bpf/fixups.c-159-\nkernel/bpf/fixups.c:160:\tif (bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/fixups.c-161-\t\tcall_imm = desc-\u003efunc_id;\n--\nkernel/bpf/fixups.c=1547=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2530-\t */\nkernel/bpf/fixups.c:2531:\tif (bpf_jit_supports_far_kfunc_call())\nkernel/bpf/fixups.c-2532-\t\treturn 0;\n--\nkernel/bpf/verifier.c=21364=int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-21382-\t * __bpf_call_base, unless the JIT needs to call functions that are\nkernel/bpf/verifier.c:21383:\t * further than 32 bits away (bpf_jit_supports_far_kfunc_call()).\nkernel/bpf/verifier.c-21384-\t */\n--\nkernel/bpf/verifier.c-21391-\nkernel/bpf/verifier.c:21392:\tnear_call = !bpf_jit_supports_far_kfunc_call();\nkernel/bpf/verifier.c-21393-\tdesc_copy = *desc;\n"
} |
| 9/2 | 2026/09/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17710 output: 36 thoughts: 538 Thoughts: **Analyzing BPF Kfunc Calls and Arena Management** Okay, let's break this down. On amd64, the `bpf_jit_supports_far_kfunc_call()` function returns false, which means `near_call` is true for x86_64. So, we're dealing with near calls. Looking at the code snippet, it's clear that after `specialize_kfunc`, we have this `near_call` check. If it's true, we calculate `call_imm` with `BPF_CALL_IMM`. A critical check happens here: is the address range a signed 32-bit integer? If not, we error out with -EINVAL, likely because the kernel function is too far away for a near call. Then, `insn->imm` gets the immediate value. Regardless of `near_call`, `add_kfunc_desc_target` always executes. This is interesting. And, of course, `bpf_fixup_kfunc_call` is triggered during verifier fixups. The `bpf_add_kfunc_call` in `kernel/bpf/verifier.c` has that crucial `tab->nr_base_descs` handling, with the `WARN_ON_ONCE` about the count mismatch. Now, let's consider the arena management. The arena functions in `kernel/bpf/arena.c` are key: `arena_alloc_pages`, `apply_range_set_cb`, `arena_adjust_tree`, `arena_vm_fault`, and `arena_map_alloc`. We also have memory allocation functions in `kernel/bpf/syscall.c`: `bpf_alloc_page`, `bpf_alloc_pages`, and `bpf_free_pages`. This implies significant dynamic memory management. My next step is to dive deeper into `kernel/bpf/arena.c`, specifically around `arena_alloc_pages` and `apply_range_set_cb`. I need to understand how these functions interact and how changes in arena allocation affect the overall kfunc call mechanism, especially in the context of `near_call` and potential address range limitations. It will also be important to understand how the verifier's use of these structures and functions in managing the kfunc calls, and ensuring memory is both present, and valid. |
| 10/2 | 2026/09/27 17:40 | 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"
} |
| 11/2 | 2026/09/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19756 output: 34 thoughts: 153 Thoughts: **Analyzing the `apply_range_set_cb` Function** Okay, let's break this down. I'm looking at `apply_range_set_cb` and it's accessing `d->pages`, which is a `struct llist_head *pages`. So, it's dealing with a linked list, which is standard enough. I see the code using `READ_ONCE(d->pages->first)` to get the first node. Good, making sure the compiler doesn't optimize it away. Then, there are these `WARN_ON_ONCE` checks. Right, safety checks for potential race conditions or invalid states. Specifically, they're checking if the node is NULL and then making sure the node that it thought it got is actually the first node. Then I see the `d->i++` which I assume is an index counter. But then, hold on a second...it's getting a `struct page` from that node using `llist_entry`, and the member used is `pcp_llist`. That's interesting, `pcp_llist` in `struct page`... That's not immediately obvious to me, so I need to check the definition of `struct page` to see what this `pcp_llist` is all about. This seems to be where the real work's being done, and I need to understand its role within the kernel's page management. Time to dig into the `struct page` definition. |
| 12/2 | 2026/09/27 17:40 | 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"
} |
| 13/2 | 2026/09/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20433 output: 29 thoughts: 757 Thoughts: **Diving Deep into BPF Memory Management** Alright, let's break this down. First, I see `arena_alloc_pages` – interesting. I'm focusing on the interaction between allocation and mapping within this function. The critical section appears to be protected by a spinlock within the `arena` structure. We allocate pages using `bpf_alloc_pages`, and then there's an `arena_adjust_tree` call, which is likely managing some kind of address space representation. The core logic hinges around `apply_to_page_range` and its callback, `apply_range_set_cb`. Now, look at this! Inside `apply_range_set_cb`, there's this `WARN_ON_ONCE` on a `llist_del_first` call, with a corresponding `llist_add` in `bpf_alloc_pages`. It seems we are expecting an LIFO behaviour using a linked list. This smells like a potential race condition or an uninitialized list. I need to understand the lifecycle of this linked list of pages. If pages can be allocated in different threads, and the list isn't appropriately synchronized, we are in trouble. Then I see `arena_vm_fault` – a separate but related function. This function uses a local `LLIST_HEAD` called `pages`. It adds pages to this local list and then calls `apply_to_page_range` using the *same* `apply_range_set_cb`. This is concerning. Is the pages list *local* to this function, or are we passing a reference? This seems like there's a different path, where pages are being allocated and subsequently mapped in a potentially different way. Let me pause. This `apply_range_set_cb` seems like the central point of contention and the common link between these two functions, let's track the pages that are passed to this function. Let's switch gears and go deeper into the BPF verifier. I see these functions in `kernel/bpf/verifier.c`: `add_kfunc_desc_target`, `bpf_add_kfunc_call`, `bpf_fixup_kfunc_call`, and `bpf_get_kfunc_addr`. It tells me that the verifier is calling these functions. I'd need to confirm the use of `bpf_arena_alloc_pages` kfunc, it will definitely be helpful to check where `arena_alloc_pages` is called, and understand if that is exposed to userspace. |
| 14/2 | 2026/09/27 17:40 | tool | grepper |
0mArgs:{
"Expression": "arena_alloc_pages",
"PathPrefix": "kernel/bpf"
}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--\nkernel/bpf/verifier.c=12573=enum special_kfunc_type {\n--\nkernel/bpf/verifier.c-12639-\tKF_bpf_call_rcu_tasks_trace,\nkernel/bpf/verifier.c:12640:\tKF_bpf_arena_alloc_pages,\nkernel/bpf/verifier.c-12641-\tKF_bpf_arena_free_pages,\n--\nkernel/bpf/verifier.c=12734=BTF_ID(func, bpf_call_rcu_tasks_trace)\nkernel/bpf/verifier.c:12735:BTF_ID(func, bpf_arena_alloc_pages)\nkernel/bpf/verifier.c-12736-BTF_ID(func, bpf_arena_free_pages)\n--\nkernel/bpf/verifier.c=21260=static int specialize_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc, int insn_idx)\n--\nkernel/bpf/verifier.c-21297-\t\t\taddr = (unsigned long)bpf_dynptr_from_file_sleepable;\nkernel/bpf/verifier.c:21298:\t} else if (func_id == special_kfunc_list[KF_bpf_arena_alloc_pages]) {\nkernel/bpf/verifier.c-21299-\t\tif (env-\u003einsn_aux_data[insn_idx].non_sleepable)\nkernel/bpf/verifier.c:21300:\t\t\taddr = (unsigned long)bpf_arena_alloc_pages_non_sleepable;\nkernel/bpf/verifier.c-21301-\t} else if (func_id == special_kfunc_list[KF_bpf_arena_free_pages]) {\n"
} |
| 15/2 | 2026/09/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23246 output: 31 thoughts: 484 Thoughts: **BPF Code Specialization and Verifier Enhancements: A Quick Scan** Alright, let's break down these changes. It looks like `specialize_kfunc` is doing some clever specialization of `bpf_arena_alloc_pages` into potentially non-sleepable or sleepable versions – and `bpf_dynptr_from_file_sleepable` is involved as well. Interestingly, `add_kfunc_desc_target` has been integrated into `verifier.c`, which is significant. Diving deeper, I see a flurry of activity in `kernel/bpf/arena.c` with functions like `apply_range_set_cb`, `arena_alloc_pages`, `arena_adjust_tree`, `arena_vm_fault`, and `arena_map_alloc`. The changes in `kernel/bpf/syscall.c` with `bpf_alloc_page`, `bpf_alloc_pages`, and `bpf_free_pages` are also relevant. In `kernel/bpf/fixups.c`, the appearance of `bpf_jit_find_kfunc_model` and `bpf_do_misc_fixups` means we're dealing with JIT-related adjustments. The verifier now includes `find_kfunc_desc`, `bpf_get_kfunc_addr`, `bpf_add_kfunc_call`, `add_kfunc_desc_target`, and `bpf_fixup_kfunc_call`. Clearly, this warrants a fuzzing pass. The affected subsystems are core BPF verifier and the BPF arena memory allocation. The modified code is definitely reachable via the BPF syscall interface, meaning we can hit this through program loading, map creation, running programs with arena or kfuncs, and mmap operations. There are also new runtime checks and assertions to keep an eye on, including `WARN_ON_ONCE(!node)`, `WARN_ON_ONCE(!pfn_valid(page_to_pfn(page)))`, `WARN_ON_ONCE(llist_del_first(d->pages) != node)`, and `WARN_ON_ONCE(tab->nr_descs != tab->nr_base_descs)`. My next step is to nail down the necessary configurations. I need to figure out which Kconfig flags are essential to enable the BPF syscall, BPF arena, kfuncs, etc. Time to search for `CONFIG_BPF_SYSCALL` and related flags. |
| 16/2 | 2026/09/27 17:40 | tool | grepper |
0mError:no matches Args: {
"Expression": "config BPF_SYSCALL",
"PathPrefix": "init/Kconfig"
}Results: {
"error": "no matches"
} |
| 17/2 | 2026/09/27 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24319 output: 21 thoughts: 14 Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience: **Hunting Down BPF_SYSCALL** Alright, so I need to understand how `BPF_SYSCALL` is working in this context. My immediate instinct is to figure out exactly where it's defined. I'm going to start by tracing the definition. The key here is to determine what include files are necessary and where that macro lands. My aim is to quickly understand the mechanics of it to determine how the compiler is interpreting it, its purpose, and what I can expect as its output. I'm thinking I'll start with the standard BPF headers, maybe poke around in the kernel source if it's not immediately obvious. Knowing the precise definition is the foundational step. |
| 18/2 | 2026/09/27 17:40 | tool | grepper |
0mArgs:{
"Expression": "config BPF_SYSCALL"
}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"
} |
| 19/2 | 2026/09/27 17:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24603 output: 34 thoughts: 19 Thoughts: Okay, let's dive into this. I'm going to take a look at the `kernel/bpf/Kconfig` file. Specifically, I need to focus around line 31. This should give me a good starting point for whatever it is I'm trying to figure out or understand in relation to BPF configuration. Line 31, in the context of a Kconfig, likely contains a crucial configuration option or a dependency that I need to analyze. My expert intuition tells me that this is probably a core setting, perhaps the introduction of a new feature or a critical dependency for a feature that's recently become available, or a crucial check. Let's see what we've got. |
| 20/2 | 2026/09/27 17:41 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/Kconfig",
"FirstLine": 30,
"LineCount": 50
}Results: {
"Contents": " 30:\t\n 31:\tconfig BPF_SYSCALL\n 32:\t\tbool \"Enable bpf() system call\"\n 33:\t\tselect BPF\n 34:\t\tselect IRQ_WORK\n 35:\t\tselect NEED_TASKS_RCU\n 36:\t\tselect TASKS_TRACE_RCU\n 37:\t\tselect BINARY_PRINTF\n 38:\t\tselect NET_SOCK_MSG if NET\n 39:\t\tselect NET_XGRESS if NET\n 40:\t\tselect PAGE_POOL if NET\n 41:\t\tdefault n\n 42:\t\thelp\n 43:\t\t Enable the bpf() system call that allows to manipulate BPF programs\n 44:\t\t and maps via file descriptors.\n 45:\t\n 46:\tconfig BPF_JIT\n 47:\t\tbool \"Enable BPF Just In Time compiler\"\n 48:\t\tdepends on BPF\n 49:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n 50:\t\tselect EXECMEM\n 51:\t\thelp\n 52:\t\t BPF programs are normally handled by a BPF interpreter. This option\n 53:\t\t allows the kernel to generate native code when a program is loaded\n 54:\t\t into the kernel. This will significantly speed-up processing of BPF\n 55:\t\t programs.\n 56:\t\n 57:\t\t Note, an admin should enable this feature changing:\n 58:\t\t /proc/sys/net/core/bpf_jit_enable\n 59:\t\t /proc/sys/net/core/bpf_jit_harden (optional)\n 60:\t\t /proc/sys/net/core/bpf_jit_kallsyms (optional)\n 61:\t\n 62:\tconfig BPF_JIT_ALWAYS_ON\n 63:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n 64:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 65:\t\thelp\n 66:\t\t Enables BPF JIT and removes BPF interpreter to avoid speculative\n 67:\t\t execution of BPF instructions by the interpreter.\n 68:\t\n 69:\t\t When CONFIG_BPF_JIT_ALWAYS_ON is enabled, /proc/sys/net/core/bpf_jit_enable\n 70:\t\t is permanently set to 1 and setting any other value than that will\n 71:\t\t return failure.\n 72:\t\n 73:\tconfig BPF_JIT_DEFAULT_ON\n 74:\t\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n 75:\t\tdepends on HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 76:\t\n 77:\tconfig BPF_UNPRIV_DEFAULT_OFF\n 78:\t\tbool \"Disable unprivileged BPF by default\"\n 79:\t\tdefault y\n"
} |
| 21/2 | 2026/09/27 17:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25565 output: 30 thoughts: 51 Thoughts: Okay, let's break this down. **Initial Considerations for BPF Implementation** Alright, the first thing that springs to mind is that I'm going to need `BPF_SYSCALL`. That's non-negotiable for my current project. Now, what's the deal with `DEBUG_INFO_BTF`? My understanding is that kfuncs depend on BTF, right? I'd better confirm that. Just to be absolutely certain, I need to verify whether the specific kfuncs I intend to utilize actually mandate the presence of `DEBUG_INFO_BTF`. It's a critical prerequisite, and I don't want any surprises down the line. Let's make sure I've got my bases covered here. |
| 22/2 | 2026/09/27 17:41 | tool | grepper |
0mArgs:{
"Expression": "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=6424=static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name,\n--\nkernel/bpf/btf.c-6429-\nkernel/bpf/btf.c:6430:\tif (!IS_ENABLED(CONFIG_DEBUG_INFO_BTF))\nkernel/bpf/btf.c-6431-\t\treturn ERR_PTR(-ENOENT);\n--\nkernel/bpf/btf.c=6510=__u32 btf_relocate_id(const struct btf *btf, __u32 id)\n--\nkernel/bpf/btf.c-6516-\nkernel/bpf/btf.c:6517:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-6518-\nkernel/bpf/btf.c=6519=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-6614-\nkernel/bpf/btf.c:6615:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-6616-\n--\nkernel/bpf/btf.c=8595=enum {\n--\nkernel/bpf/btf.c-8598-\nkernel/bpf/btf.c:8599:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8600-struct btf_module {\n--\nkernel/bpf/btf.c=8737=fs_initcall(btf_module_init);\nkernel/bpf/btf.c:8738:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-8739-\nkernel/bpf/btf.c=8740=struct module *btf_try_get_module(const struct btf *btf)\n--\nkernel/bpf/btf.c-8742-\tstruct module *res = NULL;\nkernel/bpf/btf.c:8743:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8744-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c=8770=struct btf *btf_get_module_btf(const struct module *module)\nkernel/bpf/btf.c-8771-{\nkernel/bpf/btf.c:8772:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8773-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-8783-\nkernel/bpf/btf.c:8784:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8785-\tmutex_lock(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=8800=static int check_btf_kconfigs(const struct module *module, const char *feature)\nkernel/bpf/btf.c-8801-{\nkernel/bpf/btf.c:8802:\tif (!module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/btf.c-8803-\t\tpr_err(\"missing vmlinux BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c-8805-\t}\nkernel/bpf/btf.c:8806:\tif (module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))\nkernel/bpf/btf.c-8807-\t\tpr_warn(\"missing module BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c=8948=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\nkernel/bpf/btf.c-8949-{\nkernel/bpf/btf.c:8950:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8951-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-8964-\nkernel/bpf/btf.c:8965:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-8966-\tguard(mutex)(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9613=static struct bpf_cand_cache *populate_cand_cache(struct bpf_cand_cache *cands,\n--\nkernel/bpf/btf.c-9640-\nkernel/bpf/btf.c:9641:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9642-static void __purge_cand_cache(struct btf *btf, struct bpf_cand_cache **cache,\n--\nkernel/bpf/verifier.c=2864=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2880-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:2881:\t\t\tverbose(env, \"calling kernel function is not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-2882-\t\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=6253=static int check_ptr_to_map_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6267-\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:6268:\t\tverbose(env, \"map_ptr access not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-6269-\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=19229=static int check_pseudo_btf_id(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19245-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:19246:\t\t\tverbose(env, \"kernel is missing BTF, make sure CONFIG_DEBUG_INFO_BTF=y is specified in Kconfig.\\n\");\nkernel/bpf/verifier.c-19247-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c=21140=struct btf *bpf_get_btf_vmlinux(void)\n--\nkernel/bpf/verifier.c-21144-\nkernel/bpf/verifier.c:21145:\tif (!btf \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/verifier.c-21146-\t\tmutex_lock(\u0026btf_vmlinux_lock);\n"
} |
| 23/2 | 2026/09/27 17:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27759 output: 304 thoughts: 1608 Thoughts: **Focusing Fuzzing on BPF Arena and Kfunc Logic** Okay, so we're diving into fuzzing BPF kfuncs, which means `DEBUG_INFO_BTF` is essential – no kfunc calls without it. Also, `BPF_JIT` is a must for JIT compilation, and `BPF_SYSCALL` is relevant, too. Got it. Now, let's zero in on what's changed. Specifically, in `kernel/bpf/arena.c`, we've got `apply_range_set_cb`, `arena_alloc_pages`, `arena_adjust_tree`, `arena_vm_fault`, `arena_map_alloc`, along with kfuncs calling `arena_alloc_pages`: `bpf_arena_alloc_pages`, `bpf_arena_alloc_pages_non_sleepable`, and `bpf_arena_alloc_pages_sleepable`. `kernel/bpf/syscall.c` sees additions/modifications to `bpf_alloc_page`, `bpf_alloc_pages`, and `bpf_free_pages`. `kernel/bpf/fixups.c` has `bpf_jit_find_kfunc_model` and `bpf_do_misc_fixups`. And finally, in `kernel/bpf/verifier.c`, we see additions/modifications to `find_kfunc_desc`, `bpf_get_kfunc_addr`, `bpf_add_kfunc_call`, `add_kfunc_desc_target`, and `bpf_fixup_kfunc_call`. We need to create specific FocusSymbols. We *must* avoid ubiquitous functions, so that eliminates the general memory allocators, page fault handlers, and synchronization primitives from consideration. We want to target the specific feature logic and API entrypoints for fuzzing. Also, we can use static functions from .c files if they are not inlined. Let's carefully pick the most relevant functions. `arena_alloc_pages` is a solid candidate. Also `bpf_arena_alloc_pages`, `bpf_alloc_pages`, `bpf_free_pages`. On top of that `add_kfunc_desc_target`, `bpf_fixup_kfunc_call`, `bpf_add_kfunc_call`, `bpf_get_kfunc_addr`, `bpf_jit_find_kfunc_model` and `arena_vm_fault` look promising. Are these ubiquitous? Nope! They are pretty specific to BPF arenas and kfunc call descriptors. These will only be hit when loading BPF programs with kfuncs or handling memory allocations in the BPF arenas. This looks good. Config-wise, we need `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF`. Let's check `kernel/bpf/Makefile` to confirm dependencies. Looks like `BPF_SYSCALL` depends on `MMU` and `64BIT` - which we are assuming is true for x86_64 architecture. Those are standard, so we're good. Alright, that covers all the instructions: We have `WorthFuzzing=true`, a good explanation, our targeted `FocusSymbols`, and the `EnableConfigs` listed. Ready to set results. |
| 24/2 | 2026/09/27 17:41 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"arena_alloc_pages",
"bpf_arena_alloc_pages",
"bpf_alloc_pages",
"bpf_free_pages",
"apply_range_set_cb",
"add_kfunc_desc_target",
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model"
],
"Reasoning": "The patch modifies core BPF logic across arena memory allocation and kfunc descriptor management in the verifier and JIT fixups. It replaces the page array allocation mechanism in BPF arena with an llist-based approach (bpf_alloc_pages, bpf_free_pages, apply_range_set_cb), refactors arena tree adjustments and fault handling, and alters kfunc descriptor table tracking and specialization (add_kfunc_desc_target, bpf_fixup_kfunc_call, bpf_add_kfunc_call) with added WARN_ON_ONCE assertions. These changes affect reachable code paths accessible via the bpf syscall.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"arena_alloc_pages",
"bpf_arena_alloc_pages",
"bpf_alloc_pages",
"bpf_free_pages",
"apply_range_set_cb",
"add_kfunc_desc_target",
"bpf_fixup_kfunc_call",
"bpf_add_kfunc_call",
"bpf_get_kfunc_addr",
"bpf_jit_find_kfunc_model"
],
"Reasoning": "The patch modifies core BPF logic across arena memory allocation and kfunc descriptor management in the verifier and JIT fixups. It replaces the page array allocation mechanism in BPF arena with an llist-based approach (bpf_alloc_pages, bpf_free_pages, apply_range_set_cb), refactors arena tree adjustments and fault handling, and alters kfunc descriptor table tracking and specialization (add_kfunc_desc_target, bpf_fixup_kfunc_call, bpf_add_kfunc_call) with added WARN_ON_ONCE assertions. These changes affect reachable code paths accessible via the bpf syscall.",
"WorthFuzzing": true
} |
| 25/1 | 2026/09/27 17:41 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 26/2 | 2026/09/27 17:41 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch series consists of two main changes:\n1. BPF arena memory management refactoring: Replaces the array-based page allocation and tracking (kmalloc_nolock array of struct page *) with a lockless singly-linked list (llist_head and struct page's pcp_llist member). The page allocation helpers bpf_alloc_page/bpf_alloc_pages ensure allocated pages are zeroed (via alloc_pages_node with __GFP_ZERO for sleepable contexts and alloc_pages_nolock which internally enforces __GFP_ZERO via gfp_nolock). Stack structures such as apply_range_data are fully initialized with all fields explicitly set.\n2. BPF kfunc descriptor table support for far-call JITs and specialized call targets: Dynamically extends the kfunc descriptor table (bpf_kfunc_desc_tab) using krealloc and initializes each appended descriptor by copying the specialized target descriptor. Bounds checks are strictly enforced (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs and desc_idx \u003e= tab-\u003enr_descs).\n\nNo uninitialized heap, stack, or page memory is read, branched upon, or exposed to user space. Potential bugs introduced by these changes would involve out-of-bounds indexing, memory leaks, linked-list corruption, or concurrency issues, all of which are covered by KASAN, LOCKDEP, and standard kernel debugging facilities. Therefore, 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 32b39aabb2327eb62a0c39d8084cf0e3326b365f
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 27 17:40:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index e7c5e203edddb..5a9580b1769de 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2884,8 +2884,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);
@@ -3281,7 +3283,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;
@@ -3624,7 +3626,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 92f528c456052..da219eb0a9cb1 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1714,6 +1714,8 @@ 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)
struct bpf_kfunc_desc {
struct btf_func_model func_model;
@@ -1726,12 +1728,17 @@ struct bpf_kfunc_desc {
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. The first nr_base_descs entries are the canonical
+ * descriptors used for verifier lookups. Call specialization may append
+ * immutable descriptors for additional targets. Near-call JITs look up
+ * descriptors by imm and offset after do_misc_fixups() sorts the table.
+ * Far-call JITs use the descriptor index stored in the finalized call's
+ * off field, so their table remains in verification order.
*
- * 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 2add8001c3ec3..b9f76eee50160 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -140,6 +140,13 @@ bpf_jit_find_kfunc_model(const struct bpf_prog *prog,
struct bpf_kfunc_desc_tab *tab;
tab = prog->aux->kfunc_tab;
+ if (bpf_jit_supports_far_kfunc_call()) {
+ if (insn->off < 0 || insn->off >= tab->nr_descs)
+ return NULL;
+ res = &tab->descs[insn->off];
+ return res->func_id == insn->imm ? &res->func_model : NULL;
+ }
+
res = bsearch(&desc, tab->descs, tab->nr_descs,
sizeof(tab->descs[0]), kfunc_desc_cmp_by_imm_off);
@@ -2517,11 +2524,14 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
}
}
- ret = sort_kfunc_descs_by_imm_off(env);
- if (ret)
- return ret;
+ /*
+ * Do not change kfunc desc position into the table for far JIT.
+ * because we use the indices in the instructions.
+ */
+ if (bpf_jit_supports_far_kfunc_call())
+ return 0;
- return 0;
+ return sort_kfunc_descs_by_imm_off(env);
}
static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 74496fd716d3b..b3b0cd349eefd 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 a7c9e2d8965d5..12e33a568a3e9 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2570,17 +2570,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;
@@ -2920,10 +2924,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)
@@ -2981,7 +2987,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;
}
@@ -21299,6 +21306,44 @@ 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 *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;
+ for (i = 0; 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,
@@ -21319,7 +21364,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 desc_idx;
+ bool near_call;
int err;
if (!insn->imm) {
@@ -21340,12 +21389,29 @@ int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
return -EFAULT;
}
+ 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, &desc_idx);
+ if (err)
+ return err;
+ if (!near_call)
+ 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;
}
|
| 27/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13559 output: 20 thoughts: 838 Thoughts: **Analyzing a Linux Kernel Patch for KMSAN Fuzzing Potential** Okay, so I need to decide if this patch series warrants a dedicated KMSAN fuzzing session. Let's dig in. It's touching a lot of BPF-related code – specifically `include/linux/bpf.h`, `include/linux/bpf_verifier.h`, `kernel/bpf/arena.c`, `kernel/bpf/fixups.c`, `kernel/bpf/syscall.c`, `kernel/bpf/verifier.c`, and even some selftests. That's a decent footprint, so I should examine this closely. Looks like it might be a multi-part patch or series. First, I need to understand the changes. It seems the main focus is refactoring BPF arena page allocation. They're moving away from an array of `struct page *` (using `bpf_map_alloc_pages`) to a linked list approach leveraging `struct llist_head` and `pcp_llist` linked lists on `struct page` with `bpf_alloc_page`, `bpf_alloc_pages`, and `bpf_free_pages`. In `arena.c`, the `apply_range_set_cb` function is getting a significant overhaul, now traversing a linked list for page access. The changes in `arena_alloc_pages` make it use `bpf_alloc_pages` to allocate pages in a linked list and then applies them to page range. A key part of this is `bpf_alloc_page` in `syscall.c`. This is where I'm starting to get interested. It checks for `sleepable` and calls either `alloc_pages_nolock` or `alloc_pages_node`. Hold on... `alloc_pages_nolock(__GFP_ACCOUNT, nid, 0)` – does *that* zero the page? I need to know for sure. I need to understand if the page is zeroed, because this affects how the kernel handles stale memory from pages. Let's compare the code now to what it did *before* the patch. Okay, it looks like it did call the same `alloc_pages_nolock` conditional. Alright, let me grep for `alloc_pages_nolock` in the codebase. Let's check the tools. |
| 28/3 | 2026/09/27 17:41 | 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"
} |
| 29/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16242 output: 36 thoughts: 47 Thoughts: Okay, let's dive into this. **Investigating Potential Page Zeroing in `alloc_pages_nolock_noprof`** Alright, I need to understand the page zeroing behavior within the kernel's memory allocation path, specifically when using `alloc_pages_nolock_noprof`. I'm going to jump straight into the source code, targeting the `mm/page_alloc.c` file. I'm focusing on lines 8040 through 8075 – that's the likely region where this allocation logic will reside and where I need to verify whether the newly allocated pages are being explicitly zeroed out or if that responsibility falls elsewhere, or is perhaps conditional. Understanding this is crucial for performance and security, so I'll meticulously go through the code block. |
| 30/3 | 2026/09/27 17:41 | 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"
} |
| 31/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17140 output: 30 thoughts: 401 Thoughts: **Analyzing the Recent BPF Page Allocation Changes**
Okay, so I'm looking at this recent change in the BPF page allocation code. The initial `alloc_pages_nolock` call in `__bpf_alloc_page` is throwing me a bit. I thought it was already being used, which makes sense because of the before and after of `bpf_alloc_page`:
Before, it looks 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);
}
```
And now it's:
```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);
}
```
Right, so `bpf_alloc_page` has a new `sleepable` parameter. The conditional logic decides between `alloc_pages_nolock` and `alloc_pages_node` depending on this parameter and whether we can allocate pages.
Now, I recall that `bpf_map_alloc_pages` was using `__bpf_alloc_page` directly, which makes sense. I see it was called like this:
`bpf_map_alloc_pages` takes: `struct bpf_map *map, int nid, unsigned long nr_pages, struct page **pages`.
Ah, but now I'm curious about the context. What's calling `bpf_map_alloc_pages`? I'm pretty sure it's `arena_alloc_pages`, so let me quickly review the callers in `kernel/bpf/arena.c`.
In particular I see `arena_alloc_pages`:
Before it was called:
`ret = bpf_map_alloc_pages(&arena->map, node_id, this_batch, pages);`
This makes sense as it makes the arena page allocations.
I want to confirm this is the primary location for allocating pages for BPF arena.
|
| 32/3 | 2026/09/27 17:41 | tool | grepper |
0mArgs:{
"Expression": "arena_alloc_pages",
"PathPrefix": "kernel/bpf/"
}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--\nkernel/bpf/verifier.c=12573=enum special_kfunc_type {\n--\nkernel/bpf/verifier.c-12639-\tKF_bpf_call_rcu_tasks_trace,\nkernel/bpf/verifier.c:12640:\tKF_bpf_arena_alloc_pages,\nkernel/bpf/verifier.c-12641-\tKF_bpf_arena_free_pages,\n--\nkernel/bpf/verifier.c=12734=BTF_ID(func, bpf_call_rcu_tasks_trace)\nkernel/bpf/verifier.c:12735:BTF_ID(func, bpf_arena_alloc_pages)\nkernel/bpf/verifier.c-12736-BTF_ID(func, bpf_arena_free_pages)\n--\nkernel/bpf/verifier.c=21260=static int specialize_kfunc(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc, int insn_idx)\n--\nkernel/bpf/verifier.c-21297-\t\t\taddr = (unsigned long)bpf_dynptr_from_file_sleepable;\nkernel/bpf/verifier.c:21298:\t} else if (func_id == special_kfunc_list[KF_bpf_arena_alloc_pages]) {\nkernel/bpf/verifier.c-21299-\t\tif (env-\u003einsn_aux_data[insn_idx].non_sleepable)\nkernel/bpf/verifier.c:21300:\t\t\taddr = (unsigned long)bpf_arena_alloc_pages_non_sleepable;\nkernel/bpf/verifier.c-21301-\t} else if (func_id == special_kfunc_list[KF_bpf_arena_free_pages]) {\n"
} |
| 33/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19615 output: 27 thoughts: 459 Thoughts: **Analyzing Memory Allocation in BPF Contexts** Okay, so I'm looking at this code and something immediately jumps out. Previously, `arena_alloc_pages` was correctly using `sleepable`. But then `bpf_map_alloc_pages` calls `__bpf_alloc_page(nid)`, which *doesn't* take that `sleepable` parameter. That feels risky. Let's dig in. Looking at `__bpf_alloc_page`, I see it calls either `alloc_pages_nolock` or `alloc_pages_node`, depending on `can_alloc_pages()`. Now, the `can_alloc_pages()` check is crucial. It looks for atomicity and interrupt contexts. If `arena_alloc_pages` was called from a non-sleepable context, like `bpf_arena_alloc_pages_non_sleepable`, `sleepable` was false. But here's the kicker: if `can_alloc_pages()` *returns* true, meaning we're *not* in a restricted context, we could end up calling `alloc_pages_node(nid, GFP_KERNEL...)` which *can* sleep. Which in a BPF context, could be problematic if this is called from non-sleepable context. So, the fix introduces `bpf_alloc_page(int nid, bool sleepable)` to check if we *should* be sleeping, and if we *can* sleep by calling `if (!sleepable || !can_alloc_pages())`. Hmm, I'm now curious - why doesn't `alloc_pages_nolock` zero the page? That's a potential security consideration. Let's look at `alloc_pages_nolock` directly. And then let's go check `gfp_nolock` in `mm/page_alloc.c`, that's where I need to be. |
| 34/3 | 2026/09/27 17:41 | tool | grepper |
0mArgs:{
"Expression": "gfp_nolock",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/page_alloc.c=5343=static inline bool alloc_nolock_allowed(void)\n--\nmm/page_alloc.c-5376- */\nmm/page_alloc.c:5377:static const gfp_t gfp_nolock = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC |\nmm/page_alloc.c-5378-\t\t\t\t__GFP_COMP;\n--\nmm/page_alloc.c=5383=struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,\n--\nmm/page_alloc.c-5401-\t\t/* Certain other flags could be supported later if needed. */\nmm/page_alloc.c:5402:\t\tVM_WARN_ON_ONCE(gfp \u0026 ~(__GFP_ACCOUNT | gfp_nolock));\nmm/page_alloc.c-5403-\t\tif (!alloc_nolock_allowed())\nmm/page_alloc.c-5404-\t\t\treturn NULL;\nmm/page_alloc.c:5405:\t\tgfp |= gfp_nolock;\nmm/page_alloc.c-5406-\t\tfastpath_alloc_flags |= ALLOC_WMARK_MIN;\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-8050- * @gfp_flags: GFP flags. Only __GFP_ACCOUNT, plus some flags that get set\nmm/page_alloc.c:8051: * internally regardless (see %gfp_nolock) are allowed.\nmm/page_alloc.c-8052- * @nid: node to allocate from\n"
} |
| 35/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20976 output: 39 thoughts: 962 Thoughts: **Analyzing Page Zeroing and BPF Kfunc Descriptor Handling**
Okay, so `gfp_nolock` has `__GFP_ZERO` defined, which immediately tells me that `alloc_pages_nolock` is *always* zeroing pages. And from what I see in `alloc_pages_node`, it's doing the same. So, explicitly zero-initialized pages are what we get from `bpf_alloc_page`, no question.
Now, that's settled, I need to dig deeper into the broader context of this commit. Wait, let me check the commit history, maybe use `git log` or the commit message to understand if this is a single, focused change or a collection of related fixes rolled up together. Oh, it's a "syz-cluster applied patch under review" - that means it's likely a composite patch. Need to get a full picture. Okay, let's list the changes...
First, we have this refactoring of arena page allocation. Instead of using `kmalloc_nolock` to batch page allocations and dealing with the `struct page *` array, they are using linked lists (`struct llist_head`). `apply_range_set_cb` is popping pages from the linked list, and pages are being added to the list in `arena_vm_fault` using `llist_add()`. And `arena_adjust_tree()` has been factored out from `arena_alloc_pages()`.
Second, there's this BPF kfunc descriptor handling and specialization for far-call/near-call JITs. It seems the key changes are:
* A new macro `#define MAX_KFUNC_CALL_DESCS (MAX_KFUNC_DESCS * 2)` and the struct `bpf_kfunc_desc_tab` with `u32 nr_descs; u32 nr_base_descs; ... struct bpf_kfunc_desc descs[];`.
* In `bpf_jit_find_kfunc_model`, if far call support is present, direct indexing into `tab->descs` happens.
* In `bpf_do_misc_fixups`, no sorting of kfunc descs happens if far call support is present.
* In `verifier.c`:
* `find_kfunc_desc` now only does a binary search within `tab->nr_base_descs`.
* `bpf_get_kfunc_addr` uses `desc_idx` instead of `btf_fd_idx`, and checks for `desc_idx >= tab->nr_descs` and `desc->func_id != func_id`.
* `bpf_add_kfunc_call` checks `tab->nr_base_descs == MAX_KFUNC_DESCS` and increments both `nr_descs` and `nr_base_descs`. It also sorts `tab->nr_base_descs`.
* Specialized call targets are appended to `tab->descs` in `add_kfunc_desc_target`, using `krealloc` to grow `tab`.
* `bpf_fixup_kfunc_call` handles `specialize_kfunc` and sets up the near/far call target descriptor index.
This looks like there might be a chance for uninitialized memory issues. I need to focus on `add_kfunc_desc_target` and `bpf_fixup_kfunc_call` specifically. Time to jump into `kernel/bpf/verifier.c` and start reading around line 21306...
|
| 36/3 | 2026/09/27 17:41 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 21300,
"LineCount": 100
}Results: {
"Contents": "21300:\t\t\t\taddr = (unsigned long)bpf_arena_alloc_pages_non_sleepable;\n21301:\t\t} else if (func_id == special_kfunc_list[KF_bpf_arena_free_pages]) {\n21302:\t\t\tif (env-\u003einsn_aux_data[insn_idx].non_sleepable)\n21303:\t\t\t\taddr = (unsigned long)bpf_arena_free_pages_non_sleepable;\n21304:\t\t}\n21305:\t\tdesc-\u003eaddr = addr;\n21306:\t\treturn 0;\n21307:\t}\n21308:\t\n21309:\tstatic int add_kfunc_desc_target(struct bpf_verifier_env *env,\n21310:\t\t\t\t\t const struct bpf_kfunc_desc *target_desc,\n21311:\t\t\t\t\t u16 *desc_idx)\n21312:\t{\n21313:\t\tstruct bpf_kfunc_desc desc = *target_desc;\n21314:\t\tstruct bpf_kfunc_desc_tab *new_tab;\n21315:\t\tstruct bpf_kfunc_desc_tab *tab;\n21316:\t\tstruct bpf_prog_aux *prog_aux;\n21317:\t\tu32 i;\n21318:\t\n21319:\t\tprog_aux = env-\u003eprog-\u003eaux;\n21320:\t\ttab = prog_aux-\u003ekfunc_tab;\n21321:\t\tfor (i = 0; i \u003c tab-\u003enr_descs; i++) {\n21322:\t\t\tif (tab-\u003edescs[i].func_id == desc.func_id \u0026\u0026\n21323:\t\t\t tab-\u003edescs[i].offset == desc.offset \u0026\u0026\n21324:\t\t\t tab-\u003edescs[i].addr == desc.addr) {\n21325:\t\t\t\t*desc_idx = i;\n21326:\t\t\t\treturn 0;\n21327:\t\t\t}\n21328:\t\t}\n21329:\t\n21330:\t\tif (tab-\u003enr_descs == MAX_KFUNC_CALL_DESCS) {\n21331:\t\t\tverbose(env, \"too many different kernel function call targets\\n\");\n21332:\t\t\treturn -E2BIG;\n21333:\t\t}\n21334:\t\n21335:\t\tnew_tab = krealloc(tab, struct_size(tab, descs, tab-\u003enr_descs + 1),\n21336:\t\t\t\t GFP_KERNEL_ACCOUNT);\n21337:\t\tif (!new_tab)\n21338:\t\t\treturn -ENOMEM;\n21339:\t\ttab = new_tab;\n21340:\t\tprog_aux-\u003ekfunc_tab = tab;\n21341:\t\n21342:\t\t*desc_idx = tab-\u003enr_descs;\n21343:\t\ttab-\u003edescs[tab-\u003enr_descs++] = desc;\n21344:\t\treturn 0;\n21345:\t}\n21346:\t\n21347:\tstatic void __fixup_collection_insert_kfunc(struct bpf_insn_aux_data *insn_aux,\n21348:\t\t\t\t\t\t u16 struct_meta_reg,\n21349:\t\t\t\t\t\t u16 node_offset_reg,\n21350:\t\t\t\t\t\t struct bpf_insn *insn,\n21351:\t\t\t\t\t\t struct bpf_insn *insn_buf,\n21352:\t\t\t\t\t\t int *cnt)\n21353:\t{\n21354:\t\tstruct btf_struct_meta *kptr_struct_meta = insn_aux-\u003ekptr_struct_meta;\n21355:\t\tstruct bpf_insn addr[2] = { BPF_LD_IMM64(struct_meta_reg, (long)kptr_struct_meta) };\n21356:\t\n21357:\t\tinsn_buf[0] = addr[0];\n21358:\t\tinsn_buf[1] = addr[1];\n21359:\t\tinsn_buf[2] = BPF_MOV64_IMM(node_offset_reg, insn_aux-\u003einsert_off);\n21360:\t\tinsn_buf[3] = *insn;\n21361:\t\t*cnt = 4;\n21362:\t}\n21363:\t\n21364:\tint bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n21365:\t\t\t struct bpf_insn *insn_buf, int insn_idx, int *cnt)\n21366:\t{\n21367:\t\tstruct bpf_kfunc_desc desc_copy;\n21368:\t\tstruct bpf_kfunc_desc *desc;\n21369:\t\tunsigned long call_imm;\n21370:\t\tu16 desc_idx;\n21371:\t\tbool near_call;\n21372:\t\tint err;\n21373:\t\n21374:\t\tif (!insn-\u003eimm) {\n21375:\t\t\tverbose(env, \"invalid kernel function call not eliminated in verifier pass\\n\");\n21376:\t\t\treturn -EINVAL;\n21377:\t\t}\n21378:\t\n21379:\t\t*cnt = 0;\n21380:\t\n21381:\t\t/* insn-\u003eimm has the btf func_id. Replace it with an offset relative to\n21382:\t\t * __bpf_call_base, unless the JIT needs to call functions that are\n21383:\t\t * further than 32 bits away (bpf_jit_supports_far_kfunc_call()).\n21384:\t\t */\n21385:\t\tdesc = find_kfunc_desc(env-\u003eprog, insn-\u003eimm, insn-\u003eoff);\n21386:\t\tif (!desc) {\n21387:\t\t\tverifier_bug(env, \"kernel function descriptor not found for func_id %u\",\n21388:\t\t\t\t insn-\u003eimm);\n21389:\t\t\treturn -EFAULT;\n21390:\t\t}\n21391:\t\n21392:\t\tnear_call = !bpf_jit_supports_far_kfunc_call();\n21393:\t\tdesc_copy = *desc;\n21394:\t\tdesc = \u0026desc_copy;\n21395:\t\n21396:\t\terr = specialize_kfunc(env, desc, insn_idx);\n21397:\t\tif (err)\n21398:\t\t\treturn err;\n21399:\t\n"
} |
| 37/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24562 output: 38 thoughts: 232 Thoughts: **Analyzing the Kernel BPF Fixup Process** Okay, let's break this down step-by-step. First, I see `desc_copy = *desc;` – a full struct copy, got it. Then, `desc = &desc_copy;` - we're now working with a pointer to that copied struct. Next, we have `specialize_kfunc` called on it. Afterwards, `add_kfunc_desc_target` is invoked. Inside `add_kfunc_desc_target`, the crucial part happens: `tab->descs[tab->nr_descs++] = desc;`. Ah, so `desc` here is that *full copy* of `target_desc`, and it gets directly assigned into the `tab->descs` array. Consequently, the entry in `tab->descs[...]` is completely and correctly initialized. Interesting, so any `krealloc` calls are just ensuring there's enough space, with no uninitialized memory issues. We allocate space, and then overwrite the corresponding entry with our `desc` struct. Now, let me shift gears and examine `sort_kfunc_descs_by_imm_off` and `bpf_do_misc_fixups` within `kernel/bpf/fixups.c`. I'm specifically looking around line 2515 to see how these copied descriptors are then used or modified in the kernel's BPF fixup procedures. I'm keen to understand how this copy-and-pointer-assignment approach interacts with later sorting and fixup operations. |
| 38/3 | 2026/09/27 17:41 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 2515,
"LineCount": 40
}Results: {
"Contents": "2515:\t\t\t !map_ptr-\u003eops-\u003emap_poke_run) {\n2516:\t\t\t\tverifier_bug(env, \"poke tab is misconfigured\");\n2517:\t\t\t\treturn -EFAULT;\n2518:\t\t\t}\n2519:\t\n2520:\t\t\tret = map_ptr-\u003eops-\u003emap_poke_track(map_ptr, prog-\u003eaux);\n2521:\t\t\tif (ret \u003c 0) {\n2522:\t\t\t\tverbose(env, \"tracking tail call prog failed\\n\");\n2523:\t\t\t\treturn ret;\n2524:\t\t\t}\n2525:\t\t}\n2526:\t\n2527:\t\t/*\n2528:\t\t * Do not change kfunc desc position into the table for far JIT.\n2529:\t\t * because we use the indices in the instructions.\n2530:\t\t */\n2531:\t\tif (bpf_jit_supports_far_kfunc_call())\n2532:\t\t\treturn 0;\n2533:\t\n2534:\t\treturn sort_kfunc_descs_by_imm_off(env);\n2535:\t}\n2536:\t\n2537:\tstatic struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,\n2538:\t\t\t\t\t\tint position,\n2539:\t\t\t\t\t\ts32 stack_base,\n2540:\t\t\t\t\t\tu32 callback_subprogno,\n2541:\t\t\t\t\t\tu32 *total_cnt)\n2542:\t{\n2543:\t\ts32 r6_offset = stack_base + 0 * BPF_REG_SIZE;\n2544:\t\ts32 r7_offset = stack_base + 1 * BPF_REG_SIZE;\n2545:\t\ts32 r8_offset = stack_base + 2 * BPF_REG_SIZE;\n2546:\t\tint reg_loop_max = BPF_REG_6;\n2547:\t\tint reg_loop_cnt = BPF_REG_7;\n2548:\t\tint reg_loop_ctx = BPF_REG_8;\n2549:\t\n2550:\t\tstruct bpf_insn *insn_buf = env-\u003einsn_buf;\n2551:\t\tstruct bpf_prog *new_prog;\n2552:\t\tu32 callback_start;\n2553:\t\tu32 call_insn_offset;\n2554:\t\ts32 callback_offset;\n"
} |
| 39/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25823 output: 27 thoughts: 36 Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts: **Investigating `sort_kfunc_descs_by_imm_off`** Right, so I'm looking at `sort_kfunc_descs_by_imm_off` and I need to figure out where this function is defined, specifically within the BPF kernel code. My instinct is to check `kernel/bpf/fixups.c`, as the prompt suggests, since that naming strongly implies a fixup-related function, and fixups are a common concern in BPF. Now, let's see where that takes me. Time to get digging in the codebase and check out the definition of that function. |
| 40/3 | 2026/09/27 17:41 | tool | grepper |
0mArgs:{
"Expression": "sort_kfunc_descs_by_imm_off"
}Results: {
"Output": "kernel/bpf/fixups.c=156=static int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)\n--\nkernel/bpf/fixups.c-174-\nkernel/bpf/fixups.c:175:static int sort_kfunc_descs_by_imm_off(struct bpf_verifier_env *env)\nkernel/bpf/fixups.c-176-{\n--\nkernel/bpf/fixups.c=1547=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2533-\nkernel/bpf/fixups.c:2534:\treturn sort_kfunc_descs_by_imm_off(env);\nkernel/bpf/fixups.c-2535-}\n"
} |
| 41/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26289 output: 37 thoughts: 41 Thoughts: Okay, let's dive into this. I need to understand how these BPF fixups are being handled, so I'm focusing on `sort_kfunc_descs_by_imm_off` within `kernel/bpf/fixups.c`. It looks like it’s around line 156-200, so that's where I'll begin. I'm assuming this function is crucial for ordering or organizing the kernel function descriptors based on their immediate offset values – likely during the fixup process. I'll need to see how the sorting algorithm works, what data structures it's operating on, and what the implications are for BPF program execution and relocation. I'm expecting this function to play a key role in ensuring that dependencies between BPF functions are correctly resolved. Let’s see what details I can glean from the code itself. |
| 42/3 | 2026/09/27 17:41 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 155,
"LineCount": 45
}Results: {
"Contents": " 155:\t\n 156:\tstatic int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)\n 157:\t{\n 158:\t\tunsigned long call_imm;\n 159:\t\n 160:\t\tif (bpf_jit_supports_far_kfunc_call()) {\n 161:\t\t\tcall_imm = desc-\u003efunc_id;\n 162:\t\t} else {\n 163:\t\t\tcall_imm = BPF_CALL_IMM(desc-\u003eaddr);\n 164:\t\t\t/* Check whether the relative offset overflows desc-\u003eimm */\n 165:\t\t\tif ((unsigned long)(s32)call_imm != call_imm) {\n 166:\t\t\t\tverbose(env, \"address of kernel func_id %u is out of range\\n\",\n 167:\t\t\t\t\tdesc-\u003efunc_id);\n 168:\t\t\t\treturn -EINVAL;\n 169:\t\t\t}\n 170:\t\t}\n 171:\t\tdesc-\u003eimm = call_imm;\n 172:\t\treturn 0;\n 173:\t}\n 174:\t\n 175:\tstatic int sort_kfunc_descs_by_imm_off(struct bpf_verifier_env *env)\n 176:\t{\n 177:\t\tstruct bpf_kfunc_desc_tab *tab;\n 178:\t\tint i, err;\n 179:\t\n 180:\t\ttab = env-\u003eprog-\u003eaux-\u003ekfunc_tab;\n 181:\t\tif (!tab)\n 182:\t\t\treturn 0;\n 183:\t\n 184:\t\tfor (i = 0; i \u003c tab-\u003enr_descs; i++) {\n 185:\t\t\terr = set_kfunc_desc_imm(env, \u0026tab-\u003edescs[i]);\n 186:\t\t\tif (err)\n 187:\t\t\t\treturn err;\n 188:\t\t}\n 189:\t\n 190:\t\tsort(tab-\u003edescs, tab-\u003enr_descs, sizeof(tab-\u003edescs[0]),\n 191:\t\t kfunc_desc_cmp_by_imm_off, NULL);\n 192:\t\treturn 0;\n 193:\t}\n 194:\t\n 195:\tstatic int add_kfunc_in_insns(struct bpf_verifier_env *env,\n 196:\t\t\t\t struct bpf_insn *insn, int cnt)\n 197:\t{\n 198:\t\tint i, ret;\n 199:\t\n"
} |
| 43/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27240 output: 20 thoughts: 325 Thoughts: **Diving into Arena Changes** Okay, let's dissect these arena changes. Specifically, I need to understand what's happening in `kernel/bpf/arena.c`, focusing on the `apply_range_set_cb` function. I'm seeing a callback structure here that iterates through something called `d->pages`, and it looks like it's operating on PTEs. The code grabs a node from an `llist` and then performs some validation checks on a page. The use of `WARN_ON_ONCE` here indicates potential error conditions that should be investigated further. We are doing some page tracking, making sure the page is valid before we process it. Now, this `llist_del_first` call is tripping me up a bit. It seems to be removing the first element from the linked list. What is an `llist` and what happens when it is deleted from the start? I should check the definition of `llist_del_first` to confirm my assumptions and grasp its behavior completely. Let's head over to `include/linux/llist.h` to clarify this point. |
| 44/3 | 2026/09/27 17:41 | tool | grepper |
0mArgs:{
"Expression": "llist_del_first"
}Results: {
"Output": "drivers/dma/cv1800b-dmamux.c=96=static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,\n--\ndrivers/dma/cv1800b-dmamux.c-140-\t} else {\ndrivers/dma/cv1800b-dmamux.c:141:\t\tnode = llist_del_first(\u0026dmamux-\u003efree_maps);\ndrivers/dma/cv1800b-dmamux.c-142-\t\tif (!node) {\n--\ndrivers/tty/tty_buffer.c=166=static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)\n--\ndrivers/tty/tty_buffer.c-174-\tif (size \u003c= MIN_TTYB_SIZE) {\ndrivers/tty/tty_buffer.c:175:\t\tfree = llist_del_first(\u0026port-\u003ebuf.free);\ndrivers/tty/tty_buffer.c-176-\t\tif (free) {\n--\ninclude/linux/llist.h-9- * used in producers and llist_del_all can be used in consumers simultaneously\ninclude/linux/llist.h:10: * without locking. Also a single consumer can use llist_del_first while\ninclude/linux/llist.h-11- * multiple producers simultaneously use llist_add, without any locking.\n--\ninclude/linux/llist.h-13- * Cases where locking is needed:\ninclude/linux/llist.h:14: * If we have multiple consumers with llist_del_first used in one consumer, and\ninclude/linux/llist.h:15: * llist_del_first or llist_del_all used in other consumers, then a lock is\ninclude/linux/llist.h:16: * needed. This is because llist_del_first depends on list-\u003efirst-\u003enext not\ninclude/linux/llist.h-17- * changing, but without lock protection, there's no way to be sure about that\n--\ninclude/linux/llist.h-19- * preempted back, the list-\u003efirst is the same as before causing the cmpxchg in\ninclude/linux/llist.h:20: * llist_del_first to succeed. For example, while a llist_del_first operation\ninclude/linux/llist.h:21: * is in progress in one consumer, then a llist_del_first, llist_add,\ninclude/linux/llist.h-22- * llist_add (or llist_del_all, llist_add, llist_add) sequence in another\n--\ninclude/linux/llist.h=286=static inline struct llist_node *__llist_del_all(struct llist_head *head)\n--\ninclude/linux/llist.h-293-\ninclude/linux/llist.h:294:extern struct llist_node *llist_del_first(struct llist_head *head);\ninclude/linux/llist.h-295-\ninclude/linux/llist.h-296-/**\ninclude/linux/llist.h:297: * llist_del_first_init - delete first entry from lock-list and mark is as being off-list\ninclude/linux/llist.h-298- * @head:\tthe head of lock-less list to delete from.\ninclude/linux/llist.h-299- *\ninclude/linux/llist.h:300: * This behave the same as llist_del_first() except that llist_init_node() is called\ninclude/linux/llist.h-301- * on the returned node so that llist_on_list() will report false for the node.\ninclude/linux/llist.h-302- */\ninclude/linux/llist.h:303:static inline struct llist_node *llist_del_first_init(struct llist_head *head)\ninclude/linux/llist.h-304-{\ninclude/linux/llist.h:305:\tstruct llist_node *n = llist_del_first(head);\ninclude/linux/llist.h-306-\n--\ninclude/linux/llist.h-311-\ninclude/linux/llist.h:312:extern bool llist_del_first_this(struct llist_head *head,\ninclude/linux/llist.h-313-\t\t\t\t struct llist_node *this);\n--\nkernel/bpf/arena.c=158=static int apply_range_set_cb(pte_t *pte, unsigned long addr, void *data)\n--\nkernel/bpf/arena.c-203-#endif\nkernel/bpf/arena.c:204:\tWARN_ON_ONCE(llist_del_first(d-\u003epages) != node);\nkernel/bpf/arena.c-205-\td-\u003ei++;\n--\nkernel/bpf/arena.c=484=static vm_fault_t arena_vm_fault(struct vm_fault *vmf)\n--\nkernel/bpf/arena.c-571-\tif (ret) {\nkernel/bpf/arena.c:572:\t\tllist_del_first(\u0026pages);\nkernel/bpf/arena.c-573-\t\trange_tree_set(\u0026arena-\u003ert, vmf-\u003epgoff, 1);\n--\nkernel/bpf/bpf_lru_list.c=367=__local_list_pop_free(struct bpf_lru_locallist *loc_l)\n--\nkernel/bpf/bpf_lru_list.c-370-\nkernel/bpf/bpf_lru_list.c:371:\tllnode = llist_del_first(\u0026loc_l-\u003efree_llist);\nkernel/bpf/bpf_lru_list.c-372-\tif (!llnode)\n--\nkernel/bpf/memalloc.c=81=struct bpf_mem_cache {\n--\nkernel/bpf/memalloc.c-83-\t * All accesses are done with interrupts disabled and 'active' counter\nkernel/bpf/memalloc.c:84:\t * protection with __llist_add() and __llist_del_first().\nkernel/bpf/memalloc.c-85-\t */\n--\nkernel/bpf/memalloc.c=128=static const u16 sizes[NUM_CACHES] = {96, 192, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096};\nkernel/bpf/memalloc.c-129-\nkernel/bpf/memalloc.c:130:static struct llist_node notrace *__llist_del_first(struct llist_head *head)\nkernel/bpf/memalloc.c-131-{\n--\nkernel/bpf/memalloc.c=207=static void alloc_bulk(struct bpf_mem_cache *c, int cnt, int node, bool atomic)\n--\nkernel/bpf/memalloc.c-218-\t\t/*\nkernel/bpf/memalloc.c:219:\t\t * For every 'c' llist_del_first(\u0026c-\u003efree_by_rcu_ttrace); is\nkernel/bpf/memalloc.c-220-\t\t * done only by one CPU == current CPU. Other CPUs might\n--\nkernel/bpf/memalloc.c-222-\t\t */\nkernel/bpf/memalloc.c:223:\t\tobj = llist_del_first(\u0026c-\u003efree_by_rcu_ttrace);\nkernel/bpf/memalloc.c-224-\t\tif (!obj)\n--\nkernel/bpf/memalloc.c-231-\tfor (; i \u003c cnt; i++) {\nkernel/bpf/memalloc.c:232:\t\tobj = llist_del_first(\u0026c-\u003ewaiting_for_gp_ttrace);\nkernel/bpf/memalloc.c-233-\t\tif (!obj)\n--\nkernel/bpf/memalloc.c=326=static void free_bulk(struct bpf_mem_cache *c)\n--\nkernel/bpf/memalloc.c-337-\t\tinc_active(c, \u0026flags);\nkernel/bpf/memalloc.c:338:\t\tllnode = __llist_del_first(\u0026c-\u003efree_llist);\nkernel/bpf/memalloc.c-339-\t\tif (llnode)\n--\nkernel/bpf/memalloc.c=776=static void notrace *unit_alloc(struct bpf_mem_cache *c)\n--\nkernel/bpf/memalloc.c-793-\tif (local_inc_return(\u0026c-\u003eactive) == 1) {\nkernel/bpf/memalloc.c:794:\t\tllnode = __llist_del_first(\u0026c-\u003efree_llist);\nkernel/bpf/memalloc.c-795-\t\tif (llnode) {\n--\nkernel/cgroup/rstat.c=166=static void css_process_update_tree(struct cgroup_subsys *ss, int cpu)\n--\nkernel/cgroup/rstat.c-170-\nkernel/cgroup/rstat.c:171:\twhile ((lnode = llist_del_first_init(lhead))) {\nkernel/cgroup/rstat.c-172-\t\tstruct css_rstat_cpu *rstatc;\n--\nkernel/rcu/rcuscale.c=501=static struct writer_mblock *rcu_scale_alloc(long me)\n--\nkernel/rcu/rcuscale.c-514-\t}\nkernel/rcu/rcuscale.c:515:\tllnp = llist_del_first(\u0026wflp-\u003ews_lhp);\nkernel/rcu/rcuscale.c-516-\tif (!llnp)\n--\nlib/llist.c-17-/**\nlib/llist.c:18: * llist_del_first - delete the first entry of lock-less list\nlib/llist.c-19- * @head:\tthe head for your lock-less list\n--\nlib/llist.c-23- *\nlib/llist.c:24: * Only one llist_del_first user can be used simultaneously with\nlib/llist.c-25- * multiple llist_add users without lock. Because otherwise\nlib/llist.c:26: * llist_del_first, llist_add, llist_add (or llist_del_all, llist_add,\nlib/llist.c-27- * llist_add) sequence in another user may change @head-\u003efirst-\u003enext,\n--\nlib/llist.c-30- */\nlib/llist.c:31:struct llist_node *llist_del_first(struct llist_head *head)\nlib/llist.c-32-{\n--\nlib/llist.c-43-}\nlib/llist.c:44:EXPORT_SYMBOL_GPL(llist_del_first);\nlib/llist.c-45-\nlib/llist.c-46-/**\nlib/llist.c:47: * llist_del_first_this - delete given entry of lock-less list if it is first\nlib/llist.c-48- * @head:\tthe head for your lock-less list\n--\nlib/llist.c-56- */\nlib/llist.c:57:bool llist_del_first_this(struct llist_head *head,\nlib/llist.c-58-\t\t\t struct llist_node *this)\n--\nlib/llist.c-61-\nlib/llist.c:62:\t/* acquire ensures orderig wrt try_cmpxchg() is llist_del_first() */\nlib/llist.c-63-\tentry = smp_load_acquire(\u0026head-\u003efirst);\n--\nlib/llist.c-71-}\nlib/llist.c:72:EXPORT_SYMBOL_GPL(llist_del_first_this);\nlib/llist.c-73-\n--\nmm/slab_common.c=1513=get_cached_bnode(struct kfree_rcu_cpu *krcp)\n--\nmm/slab_common.c-1519-\treturn (struct kvfree_rcu_bulk_data *)\nmm/slab_common.c:1520:\t\tllist_del_first(\u0026krcp-\u003ebkvcache);\nmm/slab_common.c-1521-}\n--\nnet/rds/ib_rdma.c=194=struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *pool)\n--\nnet/rds/ib_rdma.c-200-\tspin_lock_irqsave(\u0026pool-\u003eclean_lock, flags);\nnet/rds/ib_rdma.c:201:\tret = llist_del_first(\u0026pool-\u003eclean_list);\nnet/rds/ib_rdma.c-202-\tspin_unlock_irqrestore(\u0026pool-\u003eclean_lock, flags);\n--\nnet/sunrpc/svc_xprt.c=784=static bool svc_thread_wait_for_work(struct svc_rqst *rqstp, long timeo)\n--\nnet/sunrpc/svc_xprt.c-794-\nnet/sunrpc/svc_xprt.c:795:\t\twhile (!llist_del_first_this(\u0026pool-\u003esp_idle_threads,\nnet/sunrpc/svc_xprt.c-796-\t\t\t\t\t \u0026rqstp-\u003erq_idle)) {\n--\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c=182=void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma)\n--\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c-186-\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c:187:\twhile ((node = llist_del_first(\u0026rdma-\u003esc_recv_ctxts))) {\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c-188-\t\tctxt = llist_entry(node, struct svc_rdma_recv_ctxt, rc_node);\n--\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c=199=struct svc_rdma_recv_ctxt *svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma)\n--\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c-203-\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c:204:\tnode = llist_del_first(\u0026rdma-\u003esc_recv_ctxts);\nnet/sunrpc/xprtrdma/svc_rdma_recvfrom.c-205-\tif (!node)\n--\nnet/sunrpc/xprtrdma/svc_rdma_rw.c=60=svc_rdma_get_rw_ctxt(struct svcxprt_rdma *rdma, unsigned int nr_bvec)\n--\nnet/sunrpc/xprtrdma/svc_rdma_rw.c-67-\tspin_lock(\u0026rdma-\u003esc_rw_ctxt_lock);\nnet/sunrpc/xprtrdma/svc_rdma_rw.c:68:\tnode = llist_del_first(\u0026rdma-\u003esc_rw_ctxts);\nnet/sunrpc/xprtrdma/svc_rdma_rw.c-69-\tspin_unlock(\u0026rdma-\u003esc_rw_ctxt_lock);\n--\nnet/sunrpc/xprtrdma/svc_rdma_rw.c=125=void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma)\n--\nnet/sunrpc/xprtrdma/svc_rdma_rw.c-129-\nnet/sunrpc/xprtrdma/svc_rdma_rw.c:130:\twhile ((node = llist_del_first(\u0026rdma-\u003esc_rw_ctxts)) != NULL) {\nnet/sunrpc/xprtrdma/svc_rdma_rw.c-131-\t\tctxt = llist_entry(node, struct svc_rdma_rw_ctxt, rw_node);\n--\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c=178=void svc_rdma_send_ctxts_destroy(struct svcxprt_rdma *rdma)\n--\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c-183-\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c:184:\twhile ((node = llist_del_first(\u0026rdma-\u003esc_send_ctxts)) != NULL) {\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c-185-\t\tctxt = llist_entry(node, struct svc_rdma_send_ctxt, sc_node);\n--\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c=201=struct svc_rdma_send_ctxt *svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma)\n--\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c-206-\tspin_lock(\u0026rdma-\u003esc_send_lock);\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c:207:\tnode = llist_del_first(\u0026rdma-\u003esc_send_ctxts);\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c-208-\tspin_unlock(\u0026rdma-\u003esc_send_lock);\n--\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c-231-\tspin_lock(\u0026rdma-\u003esc_send_lock);\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c:232:\tnode = llist_del_first(\u0026rdma-\u003esc_send_ctxts);\nnet/sunrpc/xprtrdma/svc_rdma_sendto.c-233-\tspin_unlock(\u0026rdma-\u003esc_send_lock);\n--\nnet/sunrpc/xprtrdma/verbs.c=1082=static struct rpcrdma_rep *rpcrdma_rep_get_locked(struct rpcrdma_buffer *buf)\n--\nnet/sunrpc/xprtrdma/verbs.c-1085-\nnet/sunrpc/xprtrdma/verbs.c:1086:\t/* Calls to llist_del_first are required to be serialized */\nnet/sunrpc/xprtrdma/verbs.c:1087:\tnode = llist_del_first(\u0026buf-\u003erb_free_reps);\nnet/sunrpc/xprtrdma/verbs.c-1088-\tif (!node)\n--\nnet/sunrpc/xprtrdma/verbs.c=1321=rpcrdma_buffer_get(struct rpcrdma_buffer *buffers)\n--\nnet/sunrpc/xprtrdma/verbs.c-1324-\nnet/sunrpc/xprtrdma/verbs.c:1325:\t/* Calls to llist_del_first are required to be serialized */\nnet/sunrpc/xprtrdma/verbs.c-1326-\tspin_lock(\u0026buffers-\u003erb_lock);\nnet/sunrpc/xprtrdma/verbs.c:1327:\tnode = llist_del_first(\u0026buffers-\u003erb_send_bufs);\nnet/sunrpc/xprtrdma/verbs.c-1328-\tspin_unlock(\u0026buffers-\u003erb_lock);\n"
} |
| 45/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32893 output: 29 thoughts: 50 Thoughts: Okay, here's my understanding, assuming I'm an expert in this area: **Investigating the `pcp_llist` in `struct page`** Right, let's take a look at the `pcp_llist` field within the `struct page`. It's essential to understand its role within the page management infrastructure. The question is, where is this precisely defined? The best place to find the authoritative declaration would be the header files. Let's start with `include/linux/mm_types.h`. That's the likely location for core memory management data structures like `struct page`. I'll delve into that header file to get the definitive answer about `pcp_llist`'s placement and purpose. |
| 46/3 | 2026/09/27 17:41 | tool | grepper |
0mArgs:{
"Expression": "pcp_llist",
"PathPrefix": "include/linux/"
}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"
} |
| 47/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33302 output: 36 thoughts: 36 Thoughts: Okay, let's dive into this. I need to refresh my memory on how `pcp_llist` is structured. I'm going to take a look at `include/linux/mm_types.h`, specifically lines 95 through 125. That's where the definition should be. It's crucial for understanding how these pre-created page lists work. Let me check the specifics of the `pcp_llist` union now. I need to confirm the organization and its possible members. Understanding this structure is essential for tracing the memory allocation path and potential synchronization requirements. I'm focusing on that precise region to get this clear in my head. |
| 48/3 | 2026/09/27 17:41 | tool | read-file |
0mArgs:{
"File": "include/linux/mm_types.h",
"FirstLine": 95,
"LineCount": 35
}Results: {
"Contents": " 95:\t\t\t\t */\n 96:\t\t\t\tunion {\n 97:\t\t\t\t\tstruct list_head lru;\n 98:\t\n 99:\t\t\t\t\t/* Or, free page */\n 100:\t\t\t\t\tstruct list_head buddy_list;\n 101:\t\t\t\t\tstruct list_head pcp_list;\n 102:\t\t\t\t\tstruct llist_node pcp_llist;\n 103:\t\t\t\t};\n 104:\t\t\t\tstruct address_space *mapping;\n 105:\t\t\t\tunion {\n 106:\t\t\t\t\tpgoff_t __folio_index;\t\t/* Our offset within mapping. */\n 107:\t\t\t\t\tunsigned long share;\t/* share count for fsdax */\n 108:\t\t\t\t};\n 109:\t\t\t\t/**\n 110:\t\t\t\t * @private: Mapping-private opaque data.\n 111:\t\t\t\t * Usually used for buffer_heads if PagePrivate.\n 112:\t\t\t\t * Used for swp_entry_t if swapcache flag set.\n 113:\t\t\t\t * Indicates order in the buddy system if PageBuddy\n 114:\t\t\t\t * or on pcp_llist.\n 115:\t\t\t\t */\n 116:\t\t\t\tunsigned long private;\n 117:\t\t\t};\n 118:\t\t\tstruct {\t/* page_pool used by netstack */\n 119:\t\t\t\t/**\n 120:\t\t\t\t * @pp_magic: magic value to avoid recycling non\n 121:\t\t\t\t * page_pool allocated pages.\n 122:\t\t\t\t */\n 123:\t\t\t\tunsigned long pp_magic;\n 124:\t\t\t\tstruct page_pool *pp;\n 125:\t\t\t\tunsigned long _pp_mapping_pad;\n 126:\t\t\t\tunsigned long dma_addr;\n 127:\t\t\t\tatomic_long_t pp_ref_count;\n 128:\t\t\t};\n 129:\t\t\tstruct {\t/* Tail pages of compound page */\n"
} |
| 49/3 | 2026/09/27 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34002 output: 36 thoughts: 1964 Thoughts: **Analysis of BPF Page Allocation and Fault Handling** Okay, let's break this down. First, I'm examining how BPF allocates and frees pages, starting with `bpf_alloc_pages` and `bpf_free_pages`. The code uses a linked list (`llist_head`) to track allocated pages. `bpf_alloc_pages` allocates `nr_pages` and adds each page to the list. If allocation fails mid-way, it calls `bpf_free_pages` to clean up. I see that `bpf_free_pages` iterates through the list and frees each page. Now, focusing on `arena_alloc_pages`, I see the core allocation flow. A linked list `pages` is initialized, and `bpf_alloc_pages` allocates pages to it. Then, crucially, there's a call to `apply_to_page_range`. This function seems to handle the actual mapping of the allocated pages. Inside `apply_to_page_range`, the `apply_range_set_cb` callback is key. Each time this callback executes, it removes one page from the `pages` list using `llist_del_first`. This means, *as* pages are successfully mapped, they're removed from the list. Now, I'm noting the implications of this. If `apply_to_page_range` fails *after* some pages have been mapped (because `apply_range_set_cb` has been called some times), the `pages` list will only contain the *unmapped* pages. The `out_free_pages` label then calls `bpf_free_pages` on the unmapped pages, which is the expected behavior. `arena_free_pages` is then called to unmap the already mapped pages, and *then* frees them. If the range mapping *succeeds*, the `pages` list will be empty, because all pages have been successfully mapped and removed in the callback. Okay, let's pivot to the fault handling in `arena_vm_fault`. A similar pattern emerges, but with a crucial difference. A single page is allocated and added to a list called `pages`. Then, `apply_to_page_range` is called for a single page. If this *fails* inside the `apply_range_set_cb` callback, the code executes a `llist_del_first(&pages)`, which removes the *single* page from the list *before* it can be freed. What I'm thinking here is the callback could fail for a bunch of reasons. The question then is, what happens if `apply_to_page_range` fails *before* it gets to the callback? For example, if there is a failure in the page table allocation? My immediate concern is the linked list `pages` still contains the `new_page`, and `llist_del_first(&pages)` is called regardless. This seems to represent a double-free risk. I need to check how the code handles the deletion of the node in the error handling path. I'm now going to go look at lines 570-600 of `kernel/bpf/arena.c` to confirm this suspicion, because it looks like a clear resource leak, and potential double free, could be here! |
| 50/3 | 2026/09/27 17:42 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/arena.c",
"FirstLine": 565,
"LineCount": 40
}Results: {
"Contents": " 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 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"
} |
| 51/3 | 2026/09/27 17:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37408 output: 23 thoughts: 284 Thoughts: **My Analysis of the Patch** Okay, so I'm looking at this patch and immediately, the first thing that jumps out is the potential for a memory leak if `new_page` isn't used. The code `if (new_page) free_pages_nolock(new_page, 0);` handles freeing the page if it wasn't consumed, which is good. We're being careful with memory management here. Now, I want to dig into how this page allocation works in more detail. Let's see... the `arena_map_alloc` function. Ah, `arena->scratch_page = bpf_alloc_page(NUMA_NO_NODE, true);`. The `true` flag is interesting; it looks like we are using `bpf_alloc_page` with that argument, and within that, calling `alloc_pages_node` with flags that include `__GFP_ZERO`. So, this `scratch_page` is being zeroed out. That's what I'd expect for security reasons, so there's nothing leaking from previous allocations, which is the right practice. Now for the second part of the patch, the change in `include/linux/bpf.h`. They're changing the parameter name in `bpf_get_kfunc_addr` from `btf_fd_idx` to `desc_idx`. My immediate thought is, okay, why the rename? Is this a simple documentation/clarification change, or is there an underlying change in what the index refers to? The obvious next step is to figure out where `bpf_get_kfunc_addr` is *actually* called and see how the parameter is used in those contexts. Let me run a `grepper` search to see where this function is called and how the `desc_idx` argument is used, to determine if there are corresponding changes to the calling code or if this is just a more descriptive rename. |
| 52/3 | 2026/09/27 17:42 | tool | grepper |
0mArgs:{
"Expression": "bpf_get_kfunc_addr"
}Results: {
"Output": "include/linux/bpf.h=3283=bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\ninclude/linux/bpf.h-3284-\t\t\t const struct bpf_insn *insn);\ninclude/linux/bpf.h:3285:int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\ninclude/linux/bpf.h-3286-\t\t u16 desc_idx, u8 **func_addr);\n--\ninclude/linux/bpf.h=3627=static inline int\ninclude/linux/bpf.h:3628:bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\ninclude/linux/bpf.h-3629-\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=2564=find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2576-\nkernel/bpf/verifier.c:2577:int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id,\nkernel/bpf/verifier.c-2578-\t\t u16 desc_idx, u8 **func_addr)\n"
} |
| 53/3 | 2026/09/27 17:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38644 output: 37 thoughts: 26 Thoughts: Here's a summary of my immediate thought process: **Diving into the BPF Core** Right, okay, let's zero in on a specific area. I need to refresh my memory on how this part of the BPF core is handling things. Let me start by looking at `kernel/bpf/core.c`, specifically around lines 1310 to 1350. This section likely handles a critical aspect of [insert your field's relevant function here - e.g., instruction verification, map management, program loading]. I need to quickly grasp the surrounding context to understand what's happening at this precise section in the code base. |
| 54/3 | 2026/09/27 17:42 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/core.c",
"FirstLine": 1310,
"LineCount": 35
}Results: {
"Contents": "1310:\tint bpf_jit_get_func_addr(const struct bpf_prog *prog,\n1311:\t\t\t\t const struct bpf_insn *insn, bool extra_pass,\n1312:\t\t\t\t u64 *func_addr, bool *func_addr_fixed)\n1313:\t{\n1314:\t\ts16 off = insn-\u003eoff;\n1315:\t\ts32 imm = insn-\u003eimm;\n1316:\t\tu8 *addr;\n1317:\t\tint err;\n1318:\t\n1319:\t\t*func_addr_fixed = insn-\u003esrc_reg != BPF_PSEUDO_CALL;\n1320:\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}\n"
} |
| 55/3 | 2026/09/27 17:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39462 output: 27 thoughts: 617 Thoughts: **Analyzing Kernel Function Call Mechanism** Okay, let's break this down. My initial focus is the interaction of kernel functions within the BPF framework, specifically regarding how function addresses are handled, and how indirect calls are supported. The code snippet for `bpf_get_kfunc_addr` looks pretty straightforward: it retrieves the address of a kernel function given its ID and an index, after performing some basic bounds checks. This seems to be the fundamental address lookup function. Then, there's `bpf_fixup_kfunc_call`. This is where the magic happens, or at least, the crucial decision-making. I see a `near_call` variable, which appears to control whether a "near" or "far" call is employed. The check `bpf_jit_supports_far_kfunc_call()` is really grabbing my attention here. It seems that if this function returns true, meaning far calls are supported, `insn->off` gets set to `desc_idx`, an index within a table. Otherwise, a direct immediate value is calculated, and checked for overflow, and directly written into `insn->imm`. Finally, the `bpf_jit_find_kfunc_model` function seems to use the `insn->off` value as an index into that same table to retrieve function descriptors if a far call is supported. It appears this function is used for indirect calls where the `insn->off` field is used as an index into a table of function descriptors. However, I need to check the logic, because if a near call is made, `insn->off` is not used. But, back to the key question: `bpf_jit_supports_far_kfunc_call()`... is it true on amd64 (x86_64)? This is the crux of the matter: it is important to know if the compiler is using an immediate or a table to represent the function pointer. I need to grep the codebase to confirm if the far call optimization exists for x86_64. If it does, `insn->off` is an index into a table of function descriptors. If not, the address is stored as an immediate value. This could be a critical optimization, or a performance bottleneck, depending on the architecture and available features. Time to get that grep command running. |
| 56/3 | 2026/09/27 17:42 | 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=1242=bool bpf_jit_supports_arena_args(void);\ninclude/linux/filter.h:1243:bool bpf_jit_supports_far_kfunc_call(void);\ninclude/linux/filter.h-1244-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=3394=bool __weak bpf_jit_supports_arena_args(void)\n--\nkernel/bpf/core.c-3398-\nkernel/bpf/core.c:3399:bool __weak bpf_jit_supports_far_kfunc_call(void)\nkernel/bpf/core.c-3400-{\n--\nkernel/bpf/fixups.c=132=bpf_jit_find_kfunc_model(const struct bpf_prog *prog,\n--\nkernel/bpf/fixups.c-142-\ttab = prog-\u003eaux-\u003ekfunc_tab;\nkernel/bpf/fixups.c:143:\tif (bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/fixups.c-144-\t\tif (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs)\n--\nkernel/bpf/fixups.c=156=static int set_kfunc_desc_imm(struct bpf_verifier_env *env, struct bpf_kfunc_desc *desc)\n--\nkernel/bpf/fixups.c-159-\nkernel/bpf/fixups.c:160:\tif (bpf_jit_supports_far_kfunc_call()) {\nkernel/bpf/fixups.c-161-\t\tcall_imm = desc-\u003efunc_id;\n--\nkernel/bpf/fixups.c=1547=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2530-\t */\nkernel/bpf/fixups.c:2531:\tif (bpf_jit_supports_far_kfunc_call())\nkernel/bpf/fixups.c-2532-\t\treturn 0;\n--\nkernel/bpf/verifier.c=21364=int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-21382-\t * __bpf_call_base, unless the JIT needs to call functions that are\nkernel/bpf/verifier.c:21383:\t * further than 32 bits away (bpf_jit_supports_far_kfunc_call()).\nkernel/bpf/verifier.c-21384-\t */\n--\nkernel/bpf/verifier.c-21391-\nkernel/bpf/verifier.c:21392:\tnear_call = !bpf_jit_supports_far_kfunc_call();\nkernel/bpf/verifier.c-21393-\tdesc_copy = *desc;\n"
} |
| 57/3 | 2026/09/27 17:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41921 output: 345 thoughts: 2280 Thoughts: **KMSAN Assessment: No Need Here** Okay, so I've been taking a close look at this patch, specifically concerning the potential for uninitialized memory usage, and after a careful analysis, I'm pretty confident we *don't* need to set `NeedsKMSAN` to true. My reasoning? Well, let's break it down: First, let's establish the context of the platform. On amd64, the `bpf_jit_supports_far_kfunc_call()` function returns false, which is important for understanding some of the behaviors we'll be looking at. While LoongArch, PowerPC, and s390 do support far kfunc calls, amd64 does not. Now, the fundamental question: when *do* we need KMSAN? The rule is: KMSAN is for detecting the reads of uninitialized memory and kernel-to-user memory info-leaks, KMSAN incurs significant resource costs. If KASAN, LOCKDEP, or standard bug detectors would have caught the issue, then we *don't* need KMSAN. It's a matter of efficiency. We only activate KMSAN for truly unique vulnerabilities. So, I've gone through the code, looking for the classic KMSAN triggers: 1. **Kernel structures to userspace:** Are we passing any kernel data structures to user space? If so, are we ensuring all fields are initialized to prevent information leaks? No, this patch doesn't send any kernel structures to user space. 2. **Conditional logic on uninitialized data:** Is any conditional logic or branching relying on the value of potentially uninitialized variables? Nope. 3. **Complex data structure initialization:** Are we allocating complex structures where later code paths might read uninitialized fields? Again, the answer is no. 4. **Bounds checks exposing uninitialized bytes:** Are we dealing with bounds checks or lengths in a way that allows surrounding code to access uninitialized bytes? Not in this case. I've examined the code blocks, in detail. * `arena_alloc_pages` and `arena_vm_fault`: I checked the initialization of `struct apply_range_data` and all the involved fields. All the fields are explicitly initialized. The allocated pages themselves are zeroed upon allocation using `GFP_KERNEL | __GFP_ZERO`. * `struct bpf_kfunc_desc` and `struct bpf_kfunc_desc_tab`: I followed the flow from the allocation of `bpf_kfunc_desc_tab` within `add_kfunc_desc_target` through `bpf_fixup_kfunc_call`, ensuring that all fields are initialized before use and after assignment. * `bpf_jit_find_kfunc_model` and `bpf_get_kfunc_addr`: There's careful bounds checking here, which prevents reading from invalid memory locations. So, where could things go wrong? It seems the code is well covered by existing sanitizers. We might see: * Concurrency issues / race conditions: LOCKDEP / KCSAN. * Out-of-bounds access: KASAN. * Memory leaks: standard detectors / KASAN. * Use-after-free: KASAN. Crucially, **none** of these are uninitialized memory bugs detectable *only* by KMSAN. All the standard bug detectors apply. We're safe. Thus, `NeedsKMSAN = false`. I'm confident in setting `NeedsKMSAN = false` here. |
| 58/3 | 2026/09/27 17:42 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series consists of two main changes:\n1. BPF arena memory management refactoring: Replaces the array-based page allocation and tracking (kmalloc_nolock array of struct page *) with a lockless singly-linked list (llist_head and struct page's pcp_llist member). The page allocation helpers bpf_alloc_page/bpf_alloc_pages ensure allocated pages are zeroed (via alloc_pages_node with __GFP_ZERO for sleepable contexts and alloc_pages_nolock which internally enforces __GFP_ZERO via gfp_nolock). Stack structures such as apply_range_data are fully initialized with all fields explicitly set.\n2. BPF kfunc descriptor table support for far-call JITs and specialized call targets: Dynamically extends the kfunc descriptor table (bpf_kfunc_desc_tab) using krealloc and initializes each appended descriptor by copying the specialized target descriptor. Bounds checks are strictly enforced (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs and desc_idx \u003e= tab-\u003enr_descs).\n\nNo uninitialized heap, stack, or page memory is read, branched upon, or exposed to user space. Potential bugs introduced by these changes would involve out-of-bounds indexing, memory leaks, linked-list corruption, or concurrency issues, all of which are covered by KASAN, LOCKDEP, and standard kernel debugging facilities. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series consists of two main changes:\n1. BPF arena memory management refactoring: Replaces the array-based page allocation and tracking (kmalloc_nolock array of struct page *) with a lockless singly-linked list (llist_head and struct page's pcp_llist member). The page allocation helpers bpf_alloc_page/bpf_alloc_pages ensure allocated pages are zeroed (via alloc_pages_node with __GFP_ZERO for sleepable contexts and alloc_pages_nolock which internally enforces __GFP_ZERO via gfp_nolock). Stack structures such as apply_range_data are fully initialized with all fields explicitly set.\n2. BPF kfunc descriptor table support for far-call JITs and specialized call targets: Dynamically extends the kfunc descriptor table (bpf_kfunc_desc_tab) using krealloc and initializes each appended descriptor by copying the specialized target descriptor. Bounds checks are strictly enforced (insn-\u003eoff \u003c 0 || insn-\u003eoff \u003e= tab-\u003enr_descs and desc_idx \u003e= tab-\u003enr_descs).\n\nNo uninitialized heap, stack, or page memory is read, branched upon, or exposed to user space. Potential bugs introduced by these changes would involve out-of-bounds indexing, memory leaks, linked-list corruption, or concurrency issues, all of which are covered by KASAN, LOCKDEP, and standard kernel debugging facilities. Therefore, 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) |
|---|