| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/03 13:42 | flow | patch-triage |
10mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "All changes in this patch series are restricted to user-space tools and libraries (tools/bpf/bpftool, tools/lib/bpf) and selftests (tools/testing/selftests/bpf). They do not affect the compiled kernel image (vmlinux) or kernel modules, and are therefore not suitable for kernel fuzzing.",
"WorthFuzzing": false
} |
| 1/1 | 2026/11/03 13:42 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit a98a58361415582a654163ae08fa3d6f9b9b8186\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Nov 3 13:42:41 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/tools/bpf/bpftool/Documentation/bpftool-gen.rst b/tools/bpf/bpftool/Documentation/bpftool-gen.rst\nindex d0a36f442db72f..4bf8b0b99ea225 100644\n--- a/tools/bpf/bpftool/Documentation/bpftool-gen.rst\n+++ b/tools/bpf/bpftool/Documentation/bpftool-gen.rst\n@@ -24,7 +24,7 @@ GEN COMMANDS\n =============\n \n | **bpftool** **gen object** *OUTPUT_FILE* *INPUT_FILE* [*INPUT_FILE*...]\n-| **bpftool** **gen skeleton** *FILE* [**name** *OBJECT_NAME*]\n+| **bpftool** **gen skeleton** *FILE* [**name** *OBJECT_NAME*] [**attach**]\n | **bpftool** **gen subskeleton** *FILE* [**name** *OBJECT_NAME*]\n | **bpftool** **gen min_core_btf** *INPUT* *OUTPUT* *OBJECT* [*OBJECT*...]\n | **bpftool** **gen help**\n@@ -51,6 +51,15 @@ bpftool gen object *OUTPUT_FILE* *INPUT_FILE* [*INPUT_FILE*...]\n bpftool gen skeleton *FILE*\n Generate BPF skeleton C header file for a given *FILE*.\n \n+ With **-L**, **attach** requests attachment during execution of the\n+ generated loader. Supported programs are ordinary LSM programs and\n+ BTF-based tracing programs using **fentry**, **fexit**, **fmod_ret**, or\n+ **tp_btf** sections, with kernel targets resolved during loading.\n+ The generated **__load()** function loads and attaches the programs;\n+ **__attach()** checks that the links exist, and **__detach()** closes them.\n+ Reattaching after detachment is not supported in this mode. Without\n+ **attach**, loading and attachment remain separate operations.\n+\n BPF skeleton is an alternative interface to existing libbpf APIs for\n working with BPF objects. Skeleton code is intended to significantly\n shorten and simplify code to load and work with BPF programs from userspace\ndiff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool\nindex a28af31937ad4b..9247a9fdcaef9a 100644\n--- a/tools/bpf/bpftool/bash-completion/bpftool\n+++ b/tools/bpf/bpftool/bash-completion/bpftool\n@@ -1021,7 +1021,7 @@ _bpftool()\n return 0\n ;;\n *)\n- _bpftool_once_attr 'name'\n+ _bpftool_once_attr 'name attach'\n return 0\n ;;\n esac\ndiff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c\nindex ee680f7c211602..62e21bd773ff4c 100644\n--- a/tools/bpf/bpftool/gen.c\n+++ b/tools/bpf/bpftool/gen.c\n@@ -566,7 +566,8 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)\n \t\t\");\n }\n \n-static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)\n+static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name,\n+\t\t\t\t bool gen_attach)\n {\n \tstruct bpf_program *prog;\n \n@@ -582,21 +583,30 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)\n \t\t\t\tint prog_fd = skel-\u003eprogs.%2$s.prog_fd;\t\t \\n\\\n \t\t\t\", obj_name, bpf_program__name(prog));\n \n-\t\tswitch (bpf_program__type(prog)) {\n-\t\tcase BPF_PROG_TYPE_RAW_TRACEPOINT:\n-\t\t\ttp_name = strchr(bpf_program__section_name(prog), '/') + 1;\n-\t\t\tprintf(\"\\tint fd = skel_raw_tracepoint_open(\\\"%s\\\", prog_fd);\\n\", tp_name);\n-\t\t\tbreak;\n-\t\tcase BPF_PROG_TYPE_TRACING:\n-\t\tcase BPF_PROG_TYPE_LSM:\n-\t\t\tif (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER)\n-\t\t\t\tprintf(\"\\tint fd = skel_link_create(prog_fd, 0, BPF_TRACE_ITER);\\n\");\n+\t\tif (gen_attach) {\n+\t\t\tif (bpf_program__autoload(prog) \u0026\u0026 bpf_program__autoattach(prog))\n+\t\t\t\tprintf(\"\\tint fd = ((void)prog_fd, skel-\u003elinks.%s_fd \u003c= 0 ? -ENOLINK : 0);\\n\",\n+\t\t\t\t bpf_program__name(prog));\n \t\t\telse\n-\t\t\t\tprintf(\"\\tint fd = skel_raw_tracepoint_open(NULL, prog_fd);\\n\");\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tprintf(\"\\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\\n\");\n-\t\t\tbreak;\n+\t\t\t\tprintf(\"\\tint fd = ((void)prog_fd, 0);\\n\");\n+\t\t} else {\n+\t\t\tswitch (bpf_program__type(prog)) {\n+\t\t\tcase BPF_PROG_TYPE_RAW_TRACEPOINT:\n+\t\t\t\ttp_name = strchr(bpf_program__section_name(prog), '/') + 1;\n+\t\t\t\tprintf(\"\\tint fd = skel_raw_tracepoint_open(\\\"%s\\\", prog_fd);\\n\",\n+\t\t\t\t tp_name);\n+\t\t\t\tbreak;\n+\t\t\tcase BPF_PROG_TYPE_TRACING:\n+\t\t\tcase BPF_PROG_TYPE_LSM:\n+\t\t\t\tif (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER)\n+\t\t\t\t\tprintf(\"\\tint fd = skel_link_create(prog_fd, 0, BPF_TRACE_ITER);\\n\");\n+\t\t\t\telse\n+\t\t\t\t\tprintf(\"\\tint fd = skel_raw_tracepoint_open(NULL, prog_fd);\\n\");\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tprintf(\"\\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\\n\");\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t}\n \t\tcodegen(\"\\\n \t\t\t\\n\\\n@@ -640,6 +650,8 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)\n \t\t\t\\n\\\n \t\t\t\tskel_closenz(skel-\u003elinks.%1$s_fd);\t \\n\\\n \t\t\t\", bpf_program__name(prog));\n+\t\tif (gen_attach)\n+\t\t\tprintf(\"\\tskel-\u003elinks.%s_fd = 0;\\n\", bpf_program__name(prog));\n \t}\n \n \tcodegen(\"\\\n@@ -691,7 +703,8 @@ static void codegen_destroy(struct bpf_object *obj, const char *obj_name)\n \t\tobj_name);\n }\n \n-static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard)\n+static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard,\n+\t\t bool gen_attach)\n {\n \tDECLARE_LIBBPF_OPTS(gen_loader_opts, opts);\n \tstruct bpf_load_and_run_opts sopts = {};\n@@ -702,6 +715,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h\n \tchar ident[256];\n \tint err = 0;\n \n+\topts.gen_attach = gen_attach;\n \tif (sign_progs)\n \t\topts.gen_hash = true;\n \n@@ -726,7 +740,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h\n \t\t\", obj_name);\n \n \n-\tcodegen_attach_detach(obj, obj_name);\n+\tcodegen_attach_detach(obj, obj_name, gen_attach);\n \n \tcodegen_destroy(obj, obj_name);\n \n@@ -743,6 +757,8 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h\n \t\t\tskel-\u003ectx.sz = (char *)\u0026skel-\u003elinks - (char *)skel; \\n\\\n \t\t\",\n \t\tobj_name, opts.data_sz);\n+\tif (gen_attach)\n+\t\tprintf(\"\\tskel-\u003ectx.sz += sizeof(skel-\u003elinks);\\n\");\n \tbpf_object__for_each_map(map, obj) {\n \t\tconst void *mmap_data = NULL;\n \t\tsize_t mmap_size = 0;\n@@ -1249,6 +1265,7 @@ static int do_skeleton(int argc, char **argv)\n \tstruct bpf_map *map;\n \tstruct btf *btf;\n \tstruct stat st;\n+\tbool gen_attach = false;\n \n \tif (!REQ_ARGS(1)) {\n \t\tusage();\n@@ -1257,10 +1274,9 @@ static int do_skeleton(int argc, char **argv)\n \tfile = GET_ARG();\n \n \twhile (argc) {\n-\t\tif (!REQ_ARGS(2))\n-\t\t\treturn -1;\n-\n \t\tif (is_prefix(*argv, \"name\")) {\n+\t\t\tif (!REQ_ARGS(2))\n+\t\t\t\treturn -1;\n \t\t\tNEXT_ARG();\n \n \t\t\tif (obj_name[0] != '\\0') {\n@@ -1270,6 +1286,8 @@ static int do_skeleton(int argc, char **argv)\n \n \t\t\tstrncpy(obj_name, *argv, MAX_OBJ_NAME_LEN - 1);\n \t\t\tobj_name[MAX_OBJ_NAME_LEN - 1] = '\\0';\n+\t\t} else if (is_prefix(*argv, \"attach\")) {\n+\t\t\tgen_attach = true;\n \t\t} else {\n \t\t\tp_err(\"unknown arg %s\", *argv);\n \t\t\treturn -1;\n@@ -1278,6 +1296,11 @@ static int do_skeleton(int argc, char **argv)\n \t\tNEXT_ARG();\n \t}\n \n+\tif (gen_attach \u0026\u0026 !use_loader) {\n+\t\tp_err(\"attach requires a light skeleton (-L)\");\n+\t\treturn -1;\n+\t}\n+\n \tif (argc) {\n \t\tp_err(\"extra unknown arguments\");\n \t\treturn -1;\n@@ -1441,7 +1464,7 @@ static int do_skeleton(int argc, char **argv)\n \t\t\tgoto out;\n \t}\n \tif (use_loader) {\n-\t\terr = gen_trace(obj, obj_name, header_guard);\n+\t\terr = gen_trace(obj, obj_name, header_guard, gen_attach);\n \t\tgoto out;\n \t}\n \n@@ -2005,7 +2028,7 @@ static int do_help(int argc, char **argv)\n \n \tfprintf(stderr,\n \t\t\"Usage: %1$s %2$s object OUTPUT_FILE INPUT_FILE [INPUT_FILE...]\\n\"\n-\t\t\" %1$s %2$s skeleton FILE [name OBJECT_NAME]\\n\"\n+\t\t\" %1$s %2$s skeleton FILE [name OBJECT_NAME] [attach]\\n\"\n \t\t\" %1$s %2$s subskeleton FILE [name OBJECT_NAME]\\n\"\n \t\t\" %1$s %2$s min_core_btf INPUT OUTPUT OBJECT [OBJECT...]\\n\"\n \t\t\" %1$s %2$s help\\n\"\ndiff --git a/tools/lib/bpf/bpf_gen_internal.h b/tools/lib/bpf/bpf_gen_internal.h\nindex 206adf28793d76..1332094bfd4b09 100644\n--- a/tools/lib/bpf/bpf_gen_internal.h\n+++ b/tools/lib/bpf/bpf_gen_internal.h\n@@ -6,6 +6,8 @@\n #include \"bpf.h\"\n #include \"libbpf_internal.h\"\n \n+#define MAX_USED_PROGS 32\n+\n struct ksym_relo_desc {\n \tconst char *name;\n \tint kind;\n@@ -39,6 +41,9 @@ struct bpf_gen {\n \tssize_t cleanup_label;\n \t__u32 nr_progs;\n \t__u32 nr_maps;\n+\tint link_fds;\n+\t__u32 nr_link_slots;\n+\tint prog_output_idx[MAX_USED_PROGS];\n \tint log_level;\n \tint error;\n \tstruct ksym_relo_desc *relos;\n@@ -73,6 +78,8 @@ void bpf_gen__prog_load(struct bpf_gen *gen,\n \t\t\tenum bpf_prog_type prog_type, const char *prog_name,\n \t\t\tconst char *license, struct bpf_insn *insns, size_t insn_cnt,\n \t\t\tstruct bpf_prog_load_opts *load_attr, int prog_idx);\n+void bpf_gen__link_create(struct bpf_gen *gen, int prog_idx, int link_idx,\n+\t\t\t enum bpf_attach_type attach_type);\n void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *value, __u32 value_size,\n \t\t\t __u64 flags);\n void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx);\ndiff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c\nindex 555d4757a898c7..06d056a326f04f 100644\n--- a/tools/lib/bpf/gen_loader.c\n+++ b/tools/lib/bpf/gen_loader.c\n@@ -16,7 +16,6 @@\n #include \"skel_internal.h\"\n \n #define MAX_USED_MAPS\t64\n-#define MAX_USED_PROGS\t32\n #define MAX_KFUNC_DESCS 256\n #define MAX_FD_ARRAY_SZ (MAX_USED_MAPS + MAX_KFUNC_DESCS)\n \n@@ -122,6 +121,10 @@ void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps\n \tgen-\u003elog_level = log_level;\n \tgen-\u003enr_obj_maps = nr_maps;\n \tgen-\u003emax_func_ptr_maps = max_func_ptr_maps;\n+\tif (OPTS_GET(gen-\u003eopts, gen_attach, false)) {\n+\t\tgen-\u003elink_fds = add_data(gen, NULL, nr_progs * sizeof(int));\n+\t\tgen-\u003enr_link_slots = nr_progs;\n+\t}\n \tif (nr_maps + max_func_ptr_maps \u003e MAX_USED_MAPS) {\n \t\tpr_warn(\"Total maps exceeds %d\\n\", MAX_USED_MAPS);\n \t\tgen-\u003eerror = -E2BIG;\n@@ -150,10 +153,14 @@ void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps\n \t\t\t /* 6 insns for emit_sys_close_blob,\n \t\t\t * 6 insns for debug_regs in emit_sys_close_blob\n \t\t\t */\n-\t\t\t nr_maps * (6 + (gen-\u003elog_level ? 6 : 0))));\n+\t\t\t (nr_maps + gen-\u003enr_link_slots) *\n+\t\t\t (6 + (gen-\u003elog_level ? 6 : 0))));\n \n \t/* remember the label where all error branches will jump to */\n \tgen-\u003ecleanup_label = gen-\u003einsn_cur - gen-\u003einsn_start;\n+\t/* Detach any programs activated before a later operation failed. */\n+\tfor (i = 0; i \u003c gen-\u003enr_link_slots; i++)\n+\t\temit_sys_close_blob(gen, gen-\u003elink_fds + i * sizeof(int));\n \t/* emit cleanup code: close all temp FDs */\n \tfor (i = 0; i \u003c nr_progs_sz; i += 4) {\n \t\temit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_10, -stack_sz + i));\n@@ -404,7 +411,8 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)\n \t\tmove_stack2ctx(gen,\n \t\t\t sizeof(struct bpf_loader_ctx) +\n \t\t\t sizeof(struct bpf_map_desc) * gen-\u003enr_maps +\n-\t\t\t sizeof(struct bpf_prog_desc) * i +\n+\t\t\t sizeof(struct bpf_prog_desc) *\n+\t\t\t (gen-\u003enr_link_slots ? gen-\u003eprog_output_idx[i] : i) +\n \t\t\t offsetof(struct bpf_prog_desc, prog_fd), 4,\n \t\t\t stack_off(prog_fd[i]));\n \tfor (i = 0; i \u003c gen-\u003enr_maps; i++)\n@@ -413,6 +421,13 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)\n \t\t\t sizeof(struct bpf_map_desc) * i +\n \t\t\t offsetof(struct bpf_map_desc, map_fd), 4,\n \t\t\t blob_fd_array_off(gen, i));\n+\tfor (i = 0; i \u003c gen-\u003enr_link_slots; i++)\n+\t\tmove_blob2ctx(gen,\n+\t\t\t sizeof(struct bpf_loader_ctx) +\n+\t\t\t sizeof(struct bpf_map_desc) * gen-\u003enr_maps +\n+\t\t\t sizeof(struct bpf_prog_desc) * gen-\u003enr_link_slots +\n+\t\t\t sizeof(struct bpf_link_desc) * i, 4,\n+\t\t\t gen-\u003elink_fds + i * sizeof(int));\n \temit(gen, BPF_MOV64_IMM(BPF_REG_0, 0));\n \temit(gen, BPF_EXIT_INSN());\n \tif (!gen-\u003eerror) {\n@@ -1015,6 +1030,26 @@ static void info_blob_bswap(struct bpf_gen *gen, int func_info, int line_info,\n \t\tbpf_core_relo_bswap(cr++);\n }\n \n+void bpf_gen__link_create(struct bpf_gen *gen, int prog_idx, int link_idx,\n+\t\t\t enum bpf_attach_type attach_type)\n+{\n+\tint attr_size = offsetofend(union bpf_attr, link_create.flags);\n+\tunion bpf_attr attr;\n+\tint link_create_attr;\n+\n+\tmemset(\u0026attr, 0, attr_size);\n+\tattr.link_create.attach_type = tgt_endian(attach_type);\n+\tlink_create_attr = add_data(gen, \u0026attr, attr_size);\n+\tmove_stack2blob(gen, attr_field(link_create_attr, link_create.prog_fd), 4,\n+\t\t\tstack_off(prog_fd[prog_idx]));\n+\temit_sys_bpf(gen, BPF_LINK_CREATE, link_create_attr, attr_size);\n+\tdebug_ret(gen, \"link_create prog_idx %d attach_type %u\", prog_idx, attach_type);\n+\temit_check_err(gen);\n+\temit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_0, BPF_PSEUDO_MAP_IDX_VALUE,\n+\t\t\t\t\t 0, 0, 0, gen-\u003elink_fds + link_idx * sizeof(int)));\n+\temit(gen, BPF_STX_MEM(BPF_W, BPF_REG_0, BPF_REG_7, 0));\n+}\n+\n void bpf_gen__prog_load(struct bpf_gen *gen,\n \t\t\tenum bpf_prog_type prog_type, const char *prog_name,\n \t\t\tconst char *license, struct bpf_insn *insns, size_t insn_cnt,\ndiff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c\nindex 02e75b183ed091..32f041e999c571 100644\n--- a/tools/lib/bpf/libbpf.c\n+++ b/tools/lib/bpf/libbpf.c\n@@ -9784,6 +9784,47 @@ static int bpf_object_prepare(struct bpf_object *obj, const char *target_btf_pat\n \treturn 0;\n }\n \n+static bool bpf_program_supports_gen_attach(const struct bpf_program *prog)\n+{\n+\tswitch (prog-\u003etype) {\n+\tcase BPF_PROG_TYPE_LSM:\n+\t\treturn prog-\u003eexpected_attach_type == BPF_LSM_MAC;\n+\tcase BPF_PROG_TYPE_TRACING:\n+\t\treturn prog-\u003eexpected_attach_type == BPF_TRACE_FENTRY ||\n+\t\t prog-\u003eexpected_attach_type == BPF_TRACE_FEXIT ||\n+\t\t prog-\u003eexpected_attach_type == BPF_MODIFY_RETURN ||\n+\t\t prog-\u003eexpected_attach_type == BPF_TRACE_RAW_TP;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+}\n+\n+static int bpf_object_gen_links(struct bpf_object *obj)\n+{\n+\tstruct bpf_program *prog;\n+\tint prog_idx = -1, link_idx = -1;\n+\n+\tbpf_object__for_each_program(prog, obj) {\n+\t\tlink_idx++;\n+\t\tif (prog-\u003eload_strategy != BPF_PROG_LOAD_STRATEGY_AUTO)\n+\t\t\tcontinue;\n+\t\tprog_idx++;\n+\t\tobj-\u003egen_loader-\u003eprog_output_idx[prog_idx] = link_idx;\n+\t\tif (!prog-\u003eautoattach)\n+\t\t\tcontinue;\n+\t\tif (!bpf_program_supports_gen_attach(prog)) {\n+\t\t\tpr_warn(\"prog '%s': loader attachment is not supported for section '%s'\\n\",\n+\t\t\t\tprog-\u003ename, prog-\u003esec_name);\n+\t\t\treturn -EOPNOTSUPP;\n+\t\t}\n+\t\tbpf_gen__link_create(obj-\u003egen_loader, prog_idx, link_idx,\n+\t\t\t\t prog-\u003eexpected_attach_type);\n+\t\tif (obj-\u003egen_loader-\u003eerror)\n+\t\t\treturn obj-\u003egen_loader-\u003eerror;\n+\t}\n+\treturn 0;\n+}\n+\n static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const char *target_btf_path)\n {\n \tint err;\n@@ -9800,7 +9841,7 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch\n \t * permit cross-endian creation of \"light skeleton\".\n \t */\n \tif (obj-\u003egen_loader) {\n-\t\tint nr_func_ptr_maps = 0, nr_progs = 0, i;\n+\t\tint nr_func_ptr_maps = 0, nr_progs = 0, nr_obj_progs = 0, i;\n \t\tbool text_has_callx = false;\n \n \t\t/*\n@@ -9815,13 +9856,16 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch\n \t\t\tif (prog_is_subprog(obj, \u0026obj-\u003eprograms[i]) \u0026\u0026\n \t\t\t prog_has_callx(\u0026obj-\u003eprograms[i]))\n \t\t\t\ttext_has_callx = true;\n-\t\tfor (i = 0; i \u003c obj-\u003enr_programs; i++)\n+\t\tfor (i = 0; i \u003c obj-\u003enr_programs; i++) {\n+\t\t\tif (prog_is_subprog(obj, \u0026obj-\u003eprograms[i]))\n+\t\t\t\tcontinue;\n+\t\t\tnr_obj_progs++;\n \t\t\tif (obj-\u003eprograms[i].load_strategy != BPF_PROG_LOAD_STRATEGY_DISABLED \u0026\u0026\n-\t\t\t !prog_is_subprog(obj, \u0026obj-\u003eprograms[i]) \u0026\u0026\n \t\t\t (text_has_callx || prog_has_callx(\u0026obj-\u003eprograms[i])))\n \t\t\t\tnr_progs++;\n+\t\t}\n \t\tbpf_gen__init(obj-\u003egen_loader, obj-\u003elog_level | extra_log_level,\n-\t\t\t obj-\u003enr_programs, obj-\u003enr_maps, nr_func_ptr_maps * nr_progs);\n+\t\t\t nr_obj_progs, obj-\u003enr_maps, nr_func_ptr_maps * nr_progs);\n \t} else if (!is_native_endianness(obj)) {\n \t\tpr_warn(\"object '%s': loading non-native endianness is unsupported\\n\", obj-\u003ename);\n \t\treturn libbpf_err(-LIBBPF_ERRNO__ENDIAN);\n@@ -9840,6 +9884,9 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch\n \t\t/* reset FDs */\n \t\tif (obj-\u003ebtf)\n \t\t\tbtf__set_fd(obj-\u003ebtf, -1);\n+\t\tif (!err \u0026\u0026 !obj-\u003egen_loader-\u003eerror \u0026\u0026\n+\t\t OPTS_GET(obj-\u003egen_loader-\u003eopts, gen_attach, false))\n+\t\t\terr = bpf_object_gen_links(obj);\n \t\tif (!err)\n \t\t\terr = bpf_gen__finish(obj-\u003egen_loader, obj-\u003enr_programs, obj-\u003enr_maps);\n \t}\ndiff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h\nindex 22204a544b23ba..a2ee239c114d96 100644\n--- a/tools/lib/bpf/libbpf.h\n+++ b/tools/lib/bpf/libbpf.h\n@@ -1990,9 +1990,10 @@ struct gen_loader_opts {\n \t__u32 data_sz;\n \t__u32 insns_sz;\n \tbool gen_hash;\n+\tbool gen_attach;\n };\n \n-#define gen_loader_opts__last_field gen_hash\n+#define gen_loader_opts__last_field gen_attach\n LIBBPF_API int bpf_object__gen_loader(struct bpf_object *obj,\n \t\t\t\t struct gen_loader_opts *opts);\n \ndiff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h\nindex 9e16b8e8cb7c90..cac7b1d2abfbf3 100644\n--- a/tools/lib/bpf/skel_internal.h\n+++ b/tools/lib/bpf/skel_internal.h\n@@ -47,6 +47,10 @@ struct bpf_prog_desc {\n \tint prog_fd;\n };\n \n+struct bpf_link_desc {\n+\tint link_fd;\n+};\n+\n enum {\n \tBPF_SKEL_KERNEL = (1ULL \u003c\u003c 0),\n };\ndiff --git a/tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c b/tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c\nnew file mode 100644\nindex 00000000000000..1277709d7ef2b9\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c\n@@ -0,0 +1,229 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Isovalent */\n+#include \u003ctest_progs.h\u003e\n+#include \u003cdirent.h\u003e\n+#include \u003cbpf/skel_internal.h\u003e\n+\n+#define NR_PROGS 7\n+\n+enum execution_case {\n+\tATTACH,\n+\tNO_AUTOLOAD,\n+\tNO_AUTOATTACH,\n+\tROLLBACK,\n+};\n+\n+static int link_create_attr_offset(const struct gen_loader_opts *opts, int index)\n+{\n+\tconst struct bpf_insn *insns = (const void *)opts-\u003einsns;\n+\tint i, count = opts-\u003einsns_sz / sizeof(*insns);\n+\n+\tfor (i = 4; i \u003c count; i++) {\n+\t\tif (insns[i].code != (BPF_JMP | BPF_CALL) ||\n+\t\t insns[i].imm != BPF_FUNC_sys_bpf ||\n+\t\t insns[i - 4].code != (BPF_ALU64 | BPF_MOV | BPF_K) ||\n+\t\t insns[i - 4].dst_reg != BPF_REG_1 ||\n+\t\t insns[i - 4].imm != BPF_LINK_CREATE)\n+\t\t\tcontinue;\n+\t\tif (!index--)\n+\t\t\treturn insns[i - 2].imm;\n+\t}\n+\treturn -1;\n+}\n+\n+static struct bpf_object *generate(struct gen_loader_opts *opts, enum execution_case test)\n+{\n+\tstruct bpf_program *prog;\n+\tstruct bpf_object *obj;\n+\n+\tobj = bpf_object__open_file(\"gen_loader_attach.bpf.o\", NULL);\n+\tif (!ASSERT_OK_PTR(obj, \"open\"))\n+\t\treturn NULL;\n+\tprog = bpf_object__find_program_by_name(obj, \"lsm_open\");\n+\tbpf_program__set_autoload(prog, test != NO_AUTOLOAD);\n+\tbpf_program__set_autoattach(prog, test != NO_AUTOATTACH);\n+\tif (!ASSERT_OK(bpf_object__gen_loader(obj, opts), \"gen_loader\") ||\n+\t !ASSERT_OK(bpf_object__load(obj), \"generate\"))\n+\t\tgoto err_out;\n+\treturn obj;\n+\n+err_out:\n+\tbpf_object__close(obj);\n+\treturn NULL;\n+}\n+\n+static void check_load_only(void)\n+{\n+\tLIBBPF_OPTS(gen_loader_opts, opts);\n+\tstruct bpf_object *obj;\n+\n+\tobj = generate(\u0026opts, ATTACH);\n+\tif (!obj)\n+\t\treturn;\n+\tASSERT_EQ(link_create_attr_offset(\u0026opts, 0), -1, \"no_link_create\");\n+\tbpf_object__close(obj);\n+}\n+\n+static void check_unsupported(void)\n+{\n+\tLIBBPF_OPTS(gen_loader_opts, opts, .gen_attach = true);\n+\tstruct bpf_program *prog;\n+\tstruct bpf_object *obj;\n+\n+\tobj = bpf_object__open_file(\"gen_loader_attach.bpf.o\", NULL);\n+\tif (!ASSERT_OK_PTR(obj, \"open\"))\n+\t\treturn;\n+\tprog = bpf_object__find_program_by_name(obj, \"socket\");\n+\tbpf_program__set_autoload(prog, true);\n+\tif (ASSERT_OK(bpf_object__gen_loader(obj, \u0026opts), \"gen_loader\"))\n+\t\tASSERT_EQ(bpf_object__load(obj), -EOPNOTSUPP, \"unsupported_attach\");\n+\tbpf_object__close(obj);\n+}\n+\n+static void check_tracing_generation(void)\n+{\n+\tLIBBPF_OPTS(gen_loader_opts, opts, .gen_attach = true);\n+\tstruct bpf_program *prog;\n+\tstruct bpf_object *obj;\n+\tint index = 0;\n+\n+\tobj = bpf_object__open_file(\"gen_loader_attach.bpf.o\", NULL);\n+\tif (!ASSERT_OK_PTR(obj, \"open\"))\n+\t\treturn;\n+\tbpf_object__for_each_program(prog, obj)\n+\t\tbpf_program__set_autoload(prog, bpf_program__type(prog) == BPF_PROG_TYPE_TRACING);\n+\tif (!ASSERT_OK(bpf_object__gen_loader(obj, \u0026opts), \"gen_loader\") ||\n+\t !ASSERT_OK(bpf_object__load(obj), \"generate\"))\n+\t\tgoto out;\n+\tbpf_object__for_each_program(prog, obj) {\n+\t\tconst union bpf_attr *attr;\n+\t\tint off;\n+\n+\t\tif (!bpf_program__autoload(prog))\n+\t\t\tcontinue;\n+\t\toff = link_create_attr_offset(\u0026opts, index++);\n+\t\tif (!ASSERT_GE(off, 0, bpf_program__name(prog)))\n+\t\t\tgoto out;\n+\t\tattr = (const void *)(opts.data + off);\n+\t\tASSERT_EQ(attr-\u003elink_create.attach_type,\n+\t\t\t bpf_program__expected_attach_type(prog), bpf_program__name(prog));\n+\t}\n+\tASSERT_EQ(link_create_attr_offset(\u0026opts, index), -1, \"link_count\");\n+out:\n+\tbpf_object__close(obj);\n+}\n+\n+static int count_fds(void)\n+{\n+\tstruct dirent *entry;\n+\tint count = 0;\n+\tDIR *dir;\n+\n+\tdir = opendir(\"/proc/self/fd\");\n+\tif (!dir)\n+\t\treturn -errno;\n+\twhile ((entry = readdir(dir)))\n+\t\tif (entry-\u003ed_name[0] != '.')\n+\t\t\tcount++;\n+\tclosedir(dir);\n+\treturn count;\n+}\n+\n+static void check_execution(enum execution_case test)\n+{\n+\tLIBBPF_OPTS(gen_loader_opts, gen, .gen_attach = true);\n+\tstruct {\n+\t\tstruct bpf_loader_ctx ctx;\n+\t\tstruct bpf_prog_desc progs[NR_PROGS];\n+\t\tstruct bpf_link_desc links[NR_PROGS];\n+\t} ctx = { .ctx.sz = sizeof(ctx) };\n+\tstruct bpf_load_and_run_opts run = { .ctx = \u0026ctx.ctx };\n+\tstruct bpf_object *obj;\n+\tint i, off, err, before;\n+\n+\tobj = generate(\u0026gen, test);\n+\tif (!obj)\n+\t\treturn;\n+\trun.insns = gen.insns;\n+\trun.insns_sz = gen.insns_sz;\n+\trun.data = gen.data;\n+\trun.data_sz = gen.data_sz;\n+\n+\tif (test == ROLLBACK) {\n+\t\toff = link_create_attr_offset(\u0026gen, 1);\n+\t\tif (!ASSERT_GE(off, 0, \"second_link_attr\"))\n+\t\t\tgoto out;\n+\t\t/* Force the second attachment to fail after the first succeeded. */\n+\t\t((union bpf_attr *)(gen.data + off))-\u003elink_create.attach_type = BPF_TRACE_FENTRY;\n+\n+\t\tbefore = count_fds();\n+\t\tif (!ASSERT_GE(before, 0, \"count_fds\"))\n+\t\t\tgoto out;\n+\t\tASSERT_EQ(bpf_load_and_run(\u0026run), -EINVAL, \"second_attach_failed\");\n+\t\tASSERT_EQ(count_fds(), before, \"rollback_fds\");\n+\t\tgoto out;\n+\t}\n+\n+\terr = bpf_load_and_run(\u0026run);\n+\tif (!ASSERT_OK(err, \"run_loader\"))\n+\t\tgoto out;\n+\n+\tfor (i = 0; i \u003c NR_PROGS; i++) {\n+\t\tstruct bpf_link_info link = {};\n+\t\tstruct bpf_prog_info prog = {};\n+\t\t__u32 size;\n+\n+\t\t/*\n+\t\t * Only the first two programs load by default; NO_AUTOLOAD also\n+\t\t * skips the first. NO_AUTOATTACH must still return its program FD.\n+\t\t */\n+\t\tif (i \u003e= 2 || (!i \u0026\u0026 test == NO_AUTOLOAD)) {\n+\t\t\tASSERT_EQ(ctx.progs[i].prog_fd, 0, \"skipped_program\");\n+\t\t} else {\n+\t\t\tsize = sizeof(prog);\n+\t\t\tif (!ASSERT_GT(ctx.progs[i].prog_fd, 0, \"program_fd\") ||\n+\t\t\t !ASSERT_OK(bpf_prog_get_info_by_fd(ctx.progs[i].prog_fd, \u0026prog, \u0026size),\n+\t\t\t\t \"prog_info\"))\n+\t\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Unloaded programs have no link. NO_AUTOATTACH also leaves the\n+\t\t * first program's link slot zero, even though its program is loaded.\n+\t\t */\n+\t\tif (i \u003e= 2 || (!i \u0026\u0026 (test == NO_AUTOLOAD || test == NO_AUTOATTACH))) {\n+\t\t\tASSERT_EQ(ctx.links[i].link_fd, 0, \"skipped_link\");\n+\t\t\tcontinue;\n+\t\t}\n+\t\t/* Verify the link references the corresponding loaded program. */\n+\t\tsize = sizeof(link);\n+\t\tif (!ASSERT_OK(bpf_link_get_info_by_fd(ctx.links[i].link_fd, \u0026link, \u0026size),\n+\t\t\t \"link_info\"))\n+\t\t\tcontinue;\n+\t\tASSERT_EQ(link.prog_id, prog.id, \"attached_program\");\n+\t}\n+out:\n+\tfor (i = 0; i \u003c NR_PROGS; i++) {\n+\t\tskel_closenz(ctx.links[i].link_fd);\n+\t\tskel_closenz(ctx.progs[i].prog_fd);\n+\t}\n+\tbpf_object__close(obj);\n+}\n+\n+void test_gen_loader_attach(void)\n+{\n+\tif (test__start_subtest(\"load_only\"))\n+\t\tcheck_load_only();\n+\tif (test__start_subtest(\"unsupported\"))\n+\t\tcheck_unsupported();\n+\tif (test__start_subtest(\"tracing\"))\n+\t\tcheck_tracing_generation();\n+\tif (test__start_subtest(\"execute\"))\n+\t\tcheck_execution(ATTACH);\n+\tif (test__start_subtest(\"execute_no_autoload\"))\n+\t\tcheck_execution(NO_AUTOLOAD);\n+\tif (test__start_subtest(\"execute_no_autoattach\"))\n+\t\tcheck_execution(NO_AUTOATTACH);\n+\tif (test__start_subtest(\"rollback\"))\n+\t\tcheck_execution(ROLLBACK);\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/gen_loader_attach.c b/tools/testing/selftests/bpf/progs/gen_loader_attach.c\nnew file mode 100644\nindex 00000000000000..9a38fe4ac7bb70\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/gen_loader_attach.c\n@@ -0,0 +1,48 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Isovalent */\n+#include \"vmlinux.h\"\n+#include \u003cbpf/bpf_helpers.h\u003e\n+\n+SEC(\"lsm/file_open\")\n+int lsm_open(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"lsm/file_permission\")\n+int lsm_perm(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"?socket\")\n+int socket(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"?fentry/security_inode_getattr\")\n+int fentry(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"?fexit/security_inode_getattr\")\n+int fexit(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"?fmod_ret/security_inode_getattr\")\n+int fmod_ret(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+SEC(\"?tp_btf/sys_enter\")\n+int tp_btf(void *ctx)\n+{\n+\treturn 0;\n+}\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n"
} |
| 2/1 | 2026/11/03 13:42 | agent | patch-evaluator |
10mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "All changes in this patch series are restricted to user-space tools and libraries (tools/bpf/bpftool, tools/lib/bpf) and selftests (tools/testing/selftests/bpf). They do not affect the compiled kernel image (vmlinux) or kernel modules, and are therefore not suitable for kernel fuzzing.",
"WorthFuzzing": false
}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 a98a58361415582a654163ae08fa3d6f9b9b8186
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 3 13:42:41 2026 +0000
syz-cluster: applied patch under review
diff --git a/tools/bpf/bpftool/Documentation/bpftool-gen.rst b/tools/bpf/bpftool/Documentation/bpftool-gen.rst
index d0a36f442db72f..4bf8b0b99ea225 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-gen.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-gen.rst
@@ -24,7 +24,7 @@ GEN COMMANDS
=============
| **bpftool** **gen object** *OUTPUT_FILE* *INPUT_FILE* [*INPUT_FILE*...]
-| **bpftool** **gen skeleton** *FILE* [**name** *OBJECT_NAME*]
+| **bpftool** **gen skeleton** *FILE* [**name** *OBJECT_NAME*] [**attach**]
| **bpftool** **gen subskeleton** *FILE* [**name** *OBJECT_NAME*]
| **bpftool** **gen min_core_btf** *INPUT* *OUTPUT* *OBJECT* [*OBJECT*...]
| **bpftool** **gen help**
@@ -51,6 +51,15 @@ bpftool gen object *OUTPUT_FILE* *INPUT_FILE* [*INPUT_FILE*...]
bpftool gen skeleton *FILE*
Generate BPF skeleton C header file for a given *FILE*.
+ With **-L**, **attach** requests attachment during execution of the
+ generated loader. Supported programs are ordinary LSM programs and
+ BTF-based tracing programs using **fentry**, **fexit**, **fmod_ret**, or
+ **tp_btf** sections, with kernel targets resolved during loading.
+ The generated **__load()** function loads and attaches the programs;
+ **__attach()** checks that the links exist, and **__detach()** closes them.
+ Reattaching after detachment is not supported in this mode. Without
+ **attach**, loading and attachment remain separate operations.
+
BPF skeleton is an alternative interface to existing libbpf APIs for
working with BPF objects. Skeleton code is intended to significantly
shorten and simplify code to load and work with BPF programs from userspace
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index a28af31937ad4b..9247a9fdcaef9a 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -1021,7 +1021,7 @@ _bpftool()
return 0
;;
*)
- _bpftool_once_attr 'name'
+ _bpftool_once_attr 'name attach'
return 0
;;
esac
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index ee680f7c211602..62e21bd773ff4c 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -566,7 +566,8 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
");
}
-static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)
+static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name,
+ bool gen_attach)
{
struct bpf_program *prog;
@@ -582,21 +583,30 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)
int prog_fd = skel->progs.%2$s.prog_fd; \n\
", obj_name, bpf_program__name(prog));
- switch (bpf_program__type(prog)) {
- case BPF_PROG_TYPE_RAW_TRACEPOINT:
- tp_name = strchr(bpf_program__section_name(prog), '/') + 1;
- printf("\tint fd = skel_raw_tracepoint_open(\"%s\", prog_fd);\n", tp_name);
- break;
- case BPF_PROG_TYPE_TRACING:
- case BPF_PROG_TYPE_LSM:
- if (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER)
- printf("\tint fd = skel_link_create(prog_fd, 0, BPF_TRACE_ITER);\n");
+ if (gen_attach) {
+ if (bpf_program__autoload(prog) && bpf_program__autoattach(prog))
+ printf("\tint fd = ((void)prog_fd, skel->links.%s_fd <= 0 ? -ENOLINK : 0);\n",
+ bpf_program__name(prog));
else
- printf("\tint fd = skel_raw_tracepoint_open(NULL, prog_fd);\n");
- break;
- default:
- printf("\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\n");
- break;
+ printf("\tint fd = ((void)prog_fd, 0);\n");
+ } else {
+ switch (bpf_program__type(prog)) {
+ case BPF_PROG_TYPE_RAW_TRACEPOINT:
+ tp_name = strchr(bpf_program__section_name(prog), '/') + 1;
+ printf("\tint fd = skel_raw_tracepoint_open(\"%s\", prog_fd);\n",
+ tp_name);
+ break;
+ case BPF_PROG_TYPE_TRACING:
+ case BPF_PROG_TYPE_LSM:
+ if (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER)
+ printf("\tint fd = skel_link_create(prog_fd, 0, BPF_TRACE_ITER);\n");
+ else
+ printf("\tint fd = skel_raw_tracepoint_open(NULL, prog_fd);\n");
+ break;
+ default:
+ printf("\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\n");
+ break;
+ }
}
codegen("\
\n\
@@ -640,6 +650,8 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)
\n\
skel_closenz(skel->links.%1$s_fd); \n\
", bpf_program__name(prog));
+ if (gen_attach)
+ printf("\tskel->links.%s_fd = 0;\n", bpf_program__name(prog));
}
codegen("\
@@ -691,7 +703,8 @@ static void codegen_destroy(struct bpf_object *obj, const char *obj_name)
obj_name);
}
-static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard)
+static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *header_guard,
+ bool gen_attach)
{
DECLARE_LIBBPF_OPTS(gen_loader_opts, opts);
struct bpf_load_and_run_opts sopts = {};
@@ -702,6 +715,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
char ident[256];
int err = 0;
+ opts.gen_attach = gen_attach;
if (sign_progs)
opts.gen_hash = true;
@@ -726,7 +740,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
", obj_name);
- codegen_attach_detach(obj, obj_name);
+ codegen_attach_detach(obj, obj_name, gen_attach);
codegen_destroy(obj, obj_name);
@@ -743,6 +757,8 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
skel->ctx.sz = (char *)&skel->links - (char *)skel; \n\
",
obj_name, opts.data_sz);
+ if (gen_attach)
+ printf("\tskel->ctx.sz += sizeof(skel->links);\n");
bpf_object__for_each_map(map, obj) {
const void *mmap_data = NULL;
size_t mmap_size = 0;
@@ -1249,6 +1265,7 @@ static int do_skeleton(int argc, char **argv)
struct bpf_map *map;
struct btf *btf;
struct stat st;
+ bool gen_attach = false;
if (!REQ_ARGS(1)) {
usage();
@@ -1257,10 +1274,9 @@ static int do_skeleton(int argc, char **argv)
file = GET_ARG();
while (argc) {
- if (!REQ_ARGS(2))
- return -1;
-
if (is_prefix(*argv, "name")) {
+ if (!REQ_ARGS(2))
+ return -1;
NEXT_ARG();
if (obj_name[0] != '\0') {
@@ -1270,6 +1286,8 @@ static int do_skeleton(int argc, char **argv)
strncpy(obj_name, *argv, MAX_OBJ_NAME_LEN - 1);
obj_name[MAX_OBJ_NAME_LEN - 1] = '\0';
+ } else if (is_prefix(*argv, "attach")) {
+ gen_attach = true;
} else {
p_err("unknown arg %s", *argv);
return -1;
@@ -1278,6 +1296,11 @@ static int do_skeleton(int argc, char **argv)
NEXT_ARG();
}
+ if (gen_attach && !use_loader) {
+ p_err("attach requires a light skeleton (-L)");
+ return -1;
+ }
+
if (argc) {
p_err("extra unknown arguments");
return -1;
@@ -1441,7 +1464,7 @@ static int do_skeleton(int argc, char **argv)
goto out;
}
if (use_loader) {
- err = gen_trace(obj, obj_name, header_guard);
+ err = gen_trace(obj, obj_name, header_guard, gen_attach);
goto out;
}
@@ -2005,7 +2028,7 @@ static int do_help(int argc, char **argv)
fprintf(stderr,
"Usage: %1$s %2$s object OUTPUT_FILE INPUT_FILE [INPUT_FILE...]\n"
- " %1$s %2$s skeleton FILE [name OBJECT_NAME]\n"
+ " %1$s %2$s skeleton FILE [name OBJECT_NAME] [attach]\n"
" %1$s %2$s subskeleton FILE [name OBJECT_NAME]\n"
" %1$s %2$s min_core_btf INPUT OUTPUT OBJECT [OBJECT...]\n"
" %1$s %2$s help\n"
diff --git a/tools/lib/bpf/bpf_gen_internal.h b/tools/lib/bpf/bpf_gen_internal.h
index 206adf28793d76..1332094bfd4b09 100644
--- a/tools/lib/bpf/bpf_gen_internal.h
+++ b/tools/lib/bpf/bpf_gen_internal.h
@@ -6,6 +6,8 @@
#include "bpf.h"
#include "libbpf_internal.h"
+#define MAX_USED_PROGS 32
+
struct ksym_relo_desc {
const char *name;
int kind;
@@ -39,6 +41,9 @@ struct bpf_gen {
ssize_t cleanup_label;
__u32 nr_progs;
__u32 nr_maps;
+ int link_fds;
+ __u32 nr_link_slots;
+ int prog_output_idx[MAX_USED_PROGS];
int log_level;
int error;
struct ksym_relo_desc *relos;
@@ -73,6 +78,8 @@ void bpf_gen__prog_load(struct bpf_gen *gen,
enum bpf_prog_type prog_type, const char *prog_name,
const char *license, struct bpf_insn *insns, size_t insn_cnt,
struct bpf_prog_load_opts *load_attr, int prog_idx);
+void bpf_gen__link_create(struct bpf_gen *gen, int prog_idx, int link_idx,
+ enum bpf_attach_type attach_type);
void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *value, __u32 value_size,
__u64 flags);
void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx);
diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
index 555d4757a898c7..06d056a326f04f 100644
--- a/tools/lib/bpf/gen_loader.c
+++ b/tools/lib/bpf/gen_loader.c
@@ -16,7 +16,6 @@
#include "skel_internal.h"
#define MAX_USED_MAPS 64
-#define MAX_USED_PROGS 32
#define MAX_KFUNC_DESCS 256
#define MAX_FD_ARRAY_SZ (MAX_USED_MAPS + MAX_KFUNC_DESCS)
@@ -122,6 +121,10 @@ void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps
gen->log_level = log_level;
gen->nr_obj_maps = nr_maps;
gen->max_func_ptr_maps = max_func_ptr_maps;
+ if (OPTS_GET(gen->opts, gen_attach, false)) {
+ gen->link_fds = add_data(gen, NULL, nr_progs * sizeof(int));
+ gen->nr_link_slots = nr_progs;
+ }
if (nr_maps + max_func_ptr_maps > MAX_USED_MAPS) {
pr_warn("Total maps exceeds %d\n", MAX_USED_MAPS);
gen->error = -E2BIG;
@@ -150,10 +153,14 @@ void bpf_gen__init(struct bpf_gen *gen, int log_level, int nr_progs, int nr_maps
/* 6 insns for emit_sys_close_blob,
* 6 insns for debug_regs in emit_sys_close_blob
*/
- nr_maps * (6 + (gen->log_level ? 6 : 0))));
+ (nr_maps + gen->nr_link_slots) *
+ (6 + (gen->log_level ? 6 : 0))));
/* remember the label where all error branches will jump to */
gen->cleanup_label = gen->insn_cur - gen->insn_start;
+ /* Detach any programs activated before a later operation failed. */
+ for (i = 0; i < gen->nr_link_slots; i++)
+ emit_sys_close_blob(gen, gen->link_fds + i * sizeof(int));
/* emit cleanup code: close all temp FDs */
for (i = 0; i < nr_progs_sz; i += 4) {
emit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_10, -stack_sz + i));
@@ -404,7 +411,8 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)
move_stack2ctx(gen,
sizeof(struct bpf_loader_ctx) +
sizeof(struct bpf_map_desc) * gen->nr_maps +
- sizeof(struct bpf_prog_desc) * i +
+ sizeof(struct bpf_prog_desc) *
+ (gen->nr_link_slots ? gen->prog_output_idx[i] : i) +
offsetof(struct bpf_prog_desc, prog_fd), 4,
stack_off(prog_fd[i]));
for (i = 0; i < gen->nr_maps; i++)
@@ -413,6 +421,13 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)
sizeof(struct bpf_map_desc) * i +
offsetof(struct bpf_map_desc, map_fd), 4,
blob_fd_array_off(gen, i));
+ for (i = 0; i < gen->nr_link_slots; i++)
+ move_blob2ctx(gen,
+ sizeof(struct bpf_loader_ctx) +
+ sizeof(struct bpf_map_desc) * gen->nr_maps +
+ sizeof(struct bpf_prog_desc) * gen->nr_link_slots +
+ sizeof(struct bpf_link_desc) * i, 4,
+ gen->link_fds + i * sizeof(int));
emit(gen, BPF_MOV64_IMM(BPF_REG_0, 0));
emit(gen, BPF_EXIT_INSN());
if (!gen->error) {
@@ -1015,6 +1030,26 @@ static void info_blob_bswap(struct bpf_gen *gen, int func_info, int line_info,
bpf_core_relo_bswap(cr++);
}
+void bpf_gen__link_create(struct bpf_gen *gen, int prog_idx, int link_idx,
+ enum bpf_attach_type attach_type)
+{
+ int attr_size = offsetofend(union bpf_attr, link_create.flags);
+ union bpf_attr attr;
+ int link_create_attr;
+
+ memset(&attr, 0, attr_size);
+ attr.link_create.attach_type = tgt_endian(attach_type);
+ link_create_attr = add_data(gen, &attr, attr_size);
+ move_stack2blob(gen, attr_field(link_create_attr, link_create.prog_fd), 4,
+ stack_off(prog_fd[prog_idx]));
+ emit_sys_bpf(gen, BPF_LINK_CREATE, link_create_attr, attr_size);
+ debug_ret(gen, "link_create prog_idx %d attach_type %u", prog_idx, attach_type);
+ emit_check_err(gen);
+ emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_0, BPF_PSEUDO_MAP_IDX_VALUE,
+ 0, 0, 0, gen->link_fds + link_idx * sizeof(int)));
+ emit(gen, BPF_STX_MEM(BPF_W, BPF_REG_0, BPF_REG_7, 0));
+}
+
void bpf_gen__prog_load(struct bpf_gen *gen,
enum bpf_prog_type prog_type, const char *prog_name,
const char *license, struct bpf_insn *insns, size_t insn_cnt,
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 02e75b183ed091..32f041e999c571 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9784,6 +9784,47 @@ static int bpf_object_prepare(struct bpf_object *obj, const char *target_btf_pat
return 0;
}
+static bool bpf_program_supports_gen_attach(const struct bpf_program *prog)
+{
+ switch (prog->type) {
+ case BPF_PROG_TYPE_LSM:
+ return prog->expected_attach_type == BPF_LSM_MAC;
+ case BPF_PROG_TYPE_TRACING:
+ return prog->expected_attach_type == BPF_TRACE_FENTRY ||
+ prog->expected_attach_type == BPF_TRACE_FEXIT ||
+ prog->expected_attach_type == BPF_MODIFY_RETURN ||
+ prog->expected_attach_type == BPF_TRACE_RAW_TP;
+ default:
+ return false;
+ }
+}
+
+static int bpf_object_gen_links(struct bpf_object *obj)
+{
+ struct bpf_program *prog;
+ int prog_idx = -1, link_idx = -1;
+
+ bpf_object__for_each_program(prog, obj) {
+ link_idx++;
+ if (prog->load_strategy != BPF_PROG_LOAD_STRATEGY_AUTO)
+ continue;
+ prog_idx++;
+ obj->gen_loader->prog_output_idx[prog_idx] = link_idx;
+ if (!prog->autoattach)
+ continue;
+ if (!bpf_program_supports_gen_attach(prog)) {
+ pr_warn("prog '%s': loader attachment is not supported for section '%s'\n",
+ prog->name, prog->sec_name);
+ return -EOPNOTSUPP;
+ }
+ bpf_gen__link_create(obj->gen_loader, prog_idx, link_idx,
+ prog->expected_attach_type);
+ if (obj->gen_loader->error)
+ return obj->gen_loader->error;
+ }
+ return 0;
+}
+
static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const char *target_btf_path)
{
int err;
@@ -9800,7 +9841,7 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch
* permit cross-endian creation of "light skeleton".
*/
if (obj->gen_loader) {
- int nr_func_ptr_maps = 0, nr_progs = 0, i;
+ int nr_func_ptr_maps = 0, nr_progs = 0, nr_obj_progs = 0, i;
bool text_has_callx = false;
/*
@@ -9815,13 +9856,16 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch
if (prog_is_subprog(obj, &obj->programs[i]) &&
prog_has_callx(&obj->programs[i]))
text_has_callx = true;
- for (i = 0; i < obj->nr_programs; i++)
+ for (i = 0; i < obj->nr_programs; i++) {
+ if (prog_is_subprog(obj, &obj->programs[i]))
+ continue;
+ nr_obj_progs++;
if (obj->programs[i].load_strategy != BPF_PROG_LOAD_STRATEGY_DISABLED &&
- !prog_is_subprog(obj, &obj->programs[i]) &&
(text_has_callx || prog_has_callx(&obj->programs[i])))
nr_progs++;
+ }
bpf_gen__init(obj->gen_loader, obj->log_level | extra_log_level,
- obj->nr_programs, obj->nr_maps, nr_func_ptr_maps * nr_progs);
+ nr_obj_progs, obj->nr_maps, nr_func_ptr_maps * nr_progs);
} else if (!is_native_endianness(obj)) {
pr_warn("object '%s': loading non-native endianness is unsupported\n", obj->name);
return libbpf_err(-LIBBPF_ERRNO__ENDIAN);
@@ -9840,6 +9884,9 @@ static int bpf_object_load(struct bpf_object *obj, int extra_log_level, const ch
/* reset FDs */
if (obj->btf)
btf__set_fd(obj->btf, -1);
+ if (!err && !obj->gen_loader->error &&
+ OPTS_GET(obj->gen_loader->opts, gen_attach, false))
+ err = bpf_object_gen_links(obj);
if (!err)
err = bpf_gen__finish(obj->gen_loader, obj->nr_programs, obj->nr_maps);
}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 22204a544b23ba..a2ee239c114d96 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1990,9 +1990,10 @@ struct gen_loader_opts {
__u32 data_sz;
__u32 insns_sz;
bool gen_hash;
+ bool gen_attach;
};
-#define gen_loader_opts__last_field gen_hash
+#define gen_loader_opts__last_field gen_attach
LIBBPF_API int bpf_object__gen_loader(struct bpf_object *obj,
struct gen_loader_opts *opts);
diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
index 9e16b8e8cb7c90..cac7b1d2abfbf3 100644
--- a/tools/lib/bpf/skel_internal.h
+++ b/tools/lib/bpf/skel_internal.h
@@ -47,6 +47,10 @@ struct bpf_prog_desc {
int prog_fd;
};
+struct bpf_link_desc {
+ int link_fd;
+};
+
enum {
BPF_SKEL_KERNEL = (1ULL << 0),
};
diff --git a/tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c b/tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c
new file mode 100644
index 00000000000000..1277709d7ef2b9
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c
@@ -0,0 +1,229 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Isovalent */
+#include <test_progs.h>
+#include <dirent.h>
+#include <bpf/skel_internal.h>
+
+#define NR_PROGS 7
+
+enum execution_case {
+ ATTACH,
+ NO_AUTOLOAD,
+ NO_AUTOATTACH,
+ ROLLBACK,
+};
+
+static int link_create_attr_offset(const struct gen_loader_opts *opts, int index)
+{
+ const struct bpf_insn *insns = (const void *)opts->insns;
+ int i, count = opts->insns_sz / sizeof(*insns);
+
+ for (i = 4; i < count; i++) {
+ if (insns[i].code != (BPF_JMP | BPF_CALL) ||
+ insns[i].imm != BPF_FUNC_sys_bpf ||
+ insns[i - 4].code != (BPF_ALU64 | BPF_MOV | BPF_K) ||
+ insns[i - 4].dst_reg != BPF_REG_1 ||
+ insns[i - 4].imm != BPF_LINK_CREATE)
+ continue;
+ if (!index--)
+ return insns[i - 2].imm;
+ }
+ return -1;
+}
+
+static struct bpf_object *generate(struct gen_loader_opts *opts, enum execution_case test)
+{
+ struct bpf_program *prog;
+ struct bpf_object *obj;
+
+ obj = bpf_object__open_file("gen_loader_attach.bpf.o", NULL);
+ if (!ASSERT_OK_PTR(obj, "open"))
+ return NULL;
+ prog = bpf_object__find_program_by_name(obj, "lsm_open");
+ bpf_program__set_autoload(prog, test != NO_AUTOLOAD);
+ bpf_program__set_autoattach(prog, test != NO_AUTOATTACH);
+ if (!ASSERT_OK(bpf_object__gen_loader(obj, opts), "gen_loader") ||
+ !ASSERT_OK(bpf_object__load(obj), "generate"))
+ goto err_out;
+ return obj;
+
+err_out:
+ bpf_object__close(obj);
+ return NULL;
+}
+
+static void check_load_only(void)
+{
+ LIBBPF_OPTS(gen_loader_opts, opts);
+ struct bpf_object *obj;
+
+ obj = generate(&opts, ATTACH);
+ if (!obj)
+ return;
+ ASSERT_EQ(link_create_attr_offset(&opts, 0), -1, "no_link_create");
+ bpf_object__close(obj);
+}
+
+static void check_unsupported(void)
+{
+ LIBBPF_OPTS(gen_loader_opts, opts, .gen_attach = true);
+ struct bpf_program *prog;
+ struct bpf_object *obj;
+
+ obj = bpf_object__open_file("gen_loader_attach.bpf.o", NULL);
+ if (!ASSERT_OK_PTR(obj, "open"))
+ return;
+ prog = bpf_object__find_program_by_name(obj, "socket");
+ bpf_program__set_autoload(prog, true);
+ if (ASSERT_OK(bpf_object__gen_loader(obj, &opts), "gen_loader"))
+ ASSERT_EQ(bpf_object__load(obj), -EOPNOTSUPP, "unsupported_attach");
+ bpf_object__close(obj);
+}
+
+static void check_tracing_generation(void)
+{
+ LIBBPF_OPTS(gen_loader_opts, opts, .gen_attach = true);
+ struct bpf_program *prog;
+ struct bpf_object *obj;
+ int index = 0;
+
+ obj = bpf_object__open_file("gen_loader_attach.bpf.o", NULL);
+ if (!ASSERT_OK_PTR(obj, "open"))
+ return;
+ bpf_object__for_each_program(prog, obj)
+ bpf_program__set_autoload(prog, bpf_program__type(prog) == BPF_PROG_TYPE_TRACING);
+ if (!ASSERT_OK(bpf_object__gen_loader(obj, &opts), "gen_loader") ||
+ !ASSERT_OK(bpf_object__load(obj), "generate"))
+ goto out;
+ bpf_object__for_each_program(prog, obj) {
+ const union bpf_attr *attr;
+ int off;
+
+ if (!bpf_program__autoload(prog))
+ continue;
+ off = link_create_attr_offset(&opts, index++);
+ if (!ASSERT_GE(off, 0, bpf_program__name(prog)))
+ goto out;
+ attr = (const void *)(opts.data + off);
+ ASSERT_EQ(attr->link_create.attach_type,
+ bpf_program__expected_attach_type(prog), bpf_program__name(prog));
+ }
+ ASSERT_EQ(link_create_attr_offset(&opts, index), -1, "link_count");
+out:
+ bpf_object__close(obj);
+}
+
+static int count_fds(void)
+{
+ struct dirent *entry;
+ int count = 0;
+ DIR *dir;
+
+ dir = opendir("/proc/self/fd");
+ if (!dir)
+ return -errno;
+ while ((entry = readdir(dir)))
+ if (entry->d_name[0] != '.')
+ count++;
+ closedir(dir);
+ return count;
+}
+
+static void check_execution(enum execution_case test)
+{
+ LIBBPF_OPTS(gen_loader_opts, gen, .gen_attach = true);
+ struct {
+ struct bpf_loader_ctx ctx;
+ struct bpf_prog_desc progs[NR_PROGS];
+ struct bpf_link_desc links[NR_PROGS];
+ } ctx = { .ctx.sz = sizeof(ctx) };
+ struct bpf_load_and_run_opts run = { .ctx = &ctx.ctx };
+ struct bpf_object *obj;
+ int i, off, err, before;
+
+ obj = generate(&gen, test);
+ if (!obj)
+ return;
+ run.insns = gen.insns;
+ run.insns_sz = gen.insns_sz;
+ run.data = gen.data;
+ run.data_sz = gen.data_sz;
+
+ if (test == ROLLBACK) {
+ off = link_create_attr_offset(&gen, 1);
+ if (!ASSERT_GE(off, 0, "second_link_attr"))
+ goto out;
+ /* Force the second attachment to fail after the first succeeded. */
+ ((union bpf_attr *)(gen.data + off))->link_create.attach_type = BPF_TRACE_FENTRY;
+
+ before = count_fds();
+ if (!ASSERT_GE(before, 0, "count_fds"))
+ goto out;
+ ASSERT_EQ(bpf_load_and_run(&run), -EINVAL, "second_attach_failed");
+ ASSERT_EQ(count_fds(), before, "rollback_fds");
+ goto out;
+ }
+
+ err = bpf_load_and_run(&run);
+ if (!ASSERT_OK(err, "run_loader"))
+ goto out;
+
+ for (i = 0; i < NR_PROGS; i++) {
+ struct bpf_link_info link = {};
+ struct bpf_prog_info prog = {};
+ __u32 size;
+
+ /*
+ * Only the first two programs load by default; NO_AUTOLOAD also
+ * skips the first. NO_AUTOATTACH must still return its program FD.
+ */
+ if (i >= 2 || (!i && test == NO_AUTOLOAD)) {
+ ASSERT_EQ(ctx.progs[i].prog_fd, 0, "skipped_program");
+ } else {
+ size = sizeof(prog);
+ if (!ASSERT_GT(ctx.progs[i].prog_fd, 0, "program_fd") ||
+ !ASSERT_OK(bpf_prog_get_info_by_fd(ctx.progs[i].prog_fd, &prog, &size),
+ "prog_info"))
+ continue;
+ }
+
+ /*
+ * Unloaded programs have no link. NO_AUTOATTACH also leaves the
+ * first program's link slot zero, even though its program is loaded.
+ */
+ if (i >= 2 || (!i && (test == NO_AUTOLOAD || test == NO_AUTOATTACH))) {
+ ASSERT_EQ(ctx.links[i].link_fd, 0, "skipped_link");
+ continue;
+ }
+ /* Verify the link references the corresponding loaded program. */
+ size = sizeof(link);
+ if (!ASSERT_OK(bpf_link_get_info_by_fd(ctx.links[i].link_fd, &link, &size),
+ "link_info"))
+ continue;
+ ASSERT_EQ(link.prog_id, prog.id, "attached_program");
+ }
+out:
+ for (i = 0; i < NR_PROGS; i++) {
+ skel_closenz(ctx.links[i].link_fd);
+ skel_closenz(ctx.progs[i].prog_fd);
+ }
+ bpf_object__close(obj);
+}
+
+void test_gen_loader_attach(void)
+{
+ if (test__start_subtest("load_only"))
+ check_load_only();
+ if (test__start_subtest("unsupported"))
+ check_unsupported();
+ if (test__start_subtest("tracing"))
+ check_tracing_generation();
+ if (test__start_subtest("execute"))
+ check_execution(ATTACH);
+ if (test__start_subtest("execute_no_autoload"))
+ check_execution(NO_AUTOLOAD);
+ if (test__start_subtest("execute_no_autoattach"))
+ check_execution(NO_AUTOATTACH);
+ if (test__start_subtest("rollback"))
+ check_execution(ROLLBACK);
+}
diff --git a/tools/testing/selftests/bpf/progs/gen_loader_attach.c b/tools/testing/selftests/bpf/progs/gen_loader_attach.c
new file mode 100644
index 00000000000000..9a38fe4ac7bb70
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/gen_loader_attach.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Isovalent */
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+SEC("lsm/file_open")
+int lsm_open(void *ctx)
+{
+ return 0;
+}
+
+SEC("lsm/file_permission")
+int lsm_perm(void *ctx)
+{
+ return 0;
+}
+
+SEC("?socket")
+int socket(void *ctx)
+{
+ return 0;
+}
+
+SEC("?fentry/security_inode_getattr")
+int fentry(void *ctx)
+{
+ return 0;
+}
+
+SEC("?fexit/security_inode_getattr")
+int fexit(void *ctx)
+{
+ return 0;
+}
+
+SEC("?fmod_ret/security_inode_getattr")
+int fmod_ret(void *ctx)
+{
+ return 0;
+}
+
+SEC("?tp_btf/sys_enter")
+int tp_btf(void *ctx)
+{
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
|
| 3/2 | 2026/11/03 13:42 | llm | patch-evaluator |
3mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13339 output: 37 thoughts: 1075 Thoughts: **Patch Series Evaluation for Syzkaller Fuzzing** Okay, let's take a look at this patch series. My initial thought is to determine if this has any potential impact on syzkaller fuzzing. I'm seeing a substantial diff across a bunch of files. First step: dissecting the changes. Looks like this patch series touches: `tools/bpf/bpftool/*`, `tools/lib/bpf/*`, and `tools/testing/selftests/bpf/*`. Hmm, they're *all* within the `tools/` directory. That's a strong indicator. Now, I need to verify whether these changes actually affect the kernel image (`vmlinux`) or kernel modules. The instructions are pretty clear about that. We need to check if *any* of the modified code falls outside the "non-kernel and non-executable changes" category. This includes stuff in `Documentation/`, comments, user-space tools, self-tests, scripts, etc., that don't directly affect the compiled kernel. I need to make absolutely sure. Let's run a quick `git log -1 --stat` or double-check the diff itself to see if any non-`tools/` files were modified. It's a quick sanity check to be sure, and I just verified that all files are in `tools/`. Alright, the diff confirms it. Every single file is squarely within the `tools/` directory. But wait, `tools/lib/bpf` is a library, and `tools/bpf/bpftool` is a tool… could these potentially influence `vmlinux` even if they're in `tools/`? Let's think. During the kernel build, does `bpftool` generate anything that gets baked into `vmlinux`? Does `bpftool` or the `gen_loader` generate something during the kernel build that would be integrated into the kernel? I seem to remember `resolve_btfids` and `libbpf` being used to resolve BTF IDs *during* the build process… Does `bpftool gen skeleton` or `gen_loader` have any interaction with the `vmlinux` build? What about `kernel/bpf/preload`? This could be a sneaky point of integration! I need to quickly figure out if anything related to `kernel/bpf/preload` is leveraging `bpftool` or `gen_loader`. I need to rule out if this patch series makes any change to the kernel, by checking all the dependencies. |
| 4/2 | 2026/11/03 13:46 | tool | grepper |
0mArgs:{
"Expression": "gen_loader|gen skeleton|skel\\.h",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/preload/iterators/Makefile=46=iterators.lskel-%.h: $(OUTPUT)/%/iterators.bpf.o | $(BPFTOOL)\nkernel/bpf/preload/iterators/Makefile-47-\t$(call msg,GEN-SKEL,$@)\nkernel/bpf/preload/iterators/Makefile:48:\t$(Q)$(BPFTOOL) gen skeleton -L $\u003c \u003e $@\nkernel/bpf/preload/iterators/Makefile-49-\n"
} |
| 5/2 | 2026/11/03 13:46 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15131 output: 32 thoughts: 307 Thoughts: **Analyzing the bpf Skeleton Generation Process**
Okay, let's break this down. I'm looking at `kernel/bpf/preload/iterators/Makefile` and see that it uses `$(BPFTOOL) gen skeleton -L $< > $@`. My initial thought was whether this uses the `attach` functionality, which would be important. But no, it's just running `bpftool gen skeleton`.
I need to understand what changed in relation to the `attach` flag. So, I need to check `tools/bpf/bpftool/gen.c`. I see `static int do_skeleton(int argc, char **argv)`. Aha, there's a new check in there: `else if (is_prefix(*argv, "attach")) { gen_attach = true;}`. So, the `gen_attach` flag is only *enabled* if "attach" is specifically passed as an argument to `bpftool gen skeleton`. If "attach" is not passed, it defaults to false. This seems like expected behavior.
Now, let's look in `tools/lib/bpf/libbpf.c`, and confirm that the `opts.gen_attach` flag is only set if the caller sets it. And indeed, the default is false/0 if not set. I’m thinking the flag is handled correctly, now.
I should also check the preload iterators directory to confirm what it is.
|
| 6/2 | 2026/11/03 13:48 | tool | grepper |
0mArgs:{
"Expression": "iterators\\.lskel",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/preload/bpf_preload_kern.c-6-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\nkernel/bpf/preload/bpf_preload_kern.c:7:#include \"iterators/iterators.lskel-little-endian.h\"\nkernel/bpf/preload/bpf_preload_kern.c-8-#else\nkernel/bpf/preload/bpf_preload_kern.c:9:#include \"iterators/iterators.lskel-big-endian.h\"\nkernel/bpf/preload/bpf_preload_kern.c-10-#endif\n--\nkernel/bpf/preload/iterators/Makefile=32=endif\n--\nkernel/bpf/preload/iterators/Makefile-37-\nkernel/bpf/preload/iterators/Makefile:38:all: iterators.lskel-little-endian.h\nkernel/bpf/preload/iterators/Makefile-39-\nkernel/bpf/preload/iterators/Makefile:40:big: iterators.lskel-big-endian.h\nkernel/bpf/preload/iterators/Makefile-41-\nkernel/bpf/preload/iterators/Makefile=42=clean:\n--\nkernel/bpf/preload/iterators/Makefile-45-\nkernel/bpf/preload/iterators/Makefile:46:iterators.lskel-%.h: $(OUTPUT)/%/iterators.bpf.o | $(BPFTOOL)\nkernel/bpf/preload/iterators/Makefile-47-\t$(call msg,GEN-SKEL,$@)\n--\nkernel/bpf/preload/iterators/README=2=If you change \"iterators.bpf.c\" do \"make -j\" in this directory to\nkernel/bpf/preload/iterators/README:3:rebuild \"iterators.lskel-little-endian.h\". Then, on a big-endian\nkernel/bpf/preload/iterators/README-4-machine, do \"make -j big\" in this directory to rebuild\nkernel/bpf/preload/iterators/README:5:\"iterators.lskel-big-endian.h\". Commit both resulting headers.\nkernel/bpf/preload/iterators/README-6-Make sure to have clang 10 installed.\n"
} |
| 7/2 | 2026/11/03 13:48 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16343 output: 18 thoughts: 73 Thoughts: Here's my summary, as the expert: **Pre-Commit Check and Makefile Investigation for BPF Preload Iterators** Alright, so `kernel/bpf/preload/iterators/iterators.lskel-little-endian.h` is already sitting in the Git repository, which is good. That likely means the build process committed both generated headers. But the key here is: it's *not* generated as part of a standard kernel build. That's a point to remember for debugging or if there's ever a need to regenerate it. Now, the natural question is *how* that header is produced. My next move is to check the `kernel/bpf/preload/iterators/Makefile`. I need to confirm whether this Makefile is actually executed during the normal kernel build process. If it's not, we have to trace the process to understand the header generation. I suspect that might involve a specific build target or a separate script. We need to follow the trail. |
| 8/2 | 2026/11/03 13:51 | tool | grepper |
0mArgs:{
"Expression": "iterators/Makefile"
}Results: {
"Output": "no matches"
} |
| 9/2 | 2026/11/03 13:51 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16660 output: 106 thoughts: 916 Thoughts: **Analysis of Commit for Fuzzing Worthiness** Okay, so the commit's changes are confined to `tools/bpf/bpftool/Documentation/bpftool-gen.rst`, `tools/bpf/bpftool/bash-completion/bpftool`, `tools/bpf/bpftool/gen.c`, `tools/lib/bpf/bpf_gen_internal.h`, `tools/lib/bpf/gen_loader.c`, `tools/lib/bpf/libbpf.h`, `tools/lib/bpf/skel_internal.h`, `tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c` and `tools/testing/selftests/bpf/progs/gen_loader_attach.c`. I initially wanted to make sure no kernel headers or code were touched, and I can confirm that `kernel/bpf/preload/iterators/iterators.lskel-little-endian.h` was NOT modified. I checked; the kernel build doesn't link against `tools/lib/bpf` directly. That's a userspace library for tools like `bpftool`, `perf`, and the selftests. `vmlinux` and kernel modules are independent. While `tools/bpf/resolve_btfids` does link against `tools/lib/bpf` for BTF inspection, it only uses BTF parsing APIs and not the loader/skel code. So, the userspace tools are still userspace tools. `tools/bpf/bpftool` is a userspace tool, `tools/testing/selftests/bpf` are selftests, and those are userspace. Now, let's go back and examine the rules. The negative criteria says to return `WorthFuzzing=false` if *all* changes are in: * Non-kernel and non-executable changes * User-space directories, self-tests, samples, or scripts that do not affect the kernel image (vmlinux) or modules. * Purely decorative logging or tracepoints that do not alter control flow or data structures. * Build system or Kconfig changes that do not alter compiled C logic. All the modified files are strictly within `tools/`, and are userspace tools, libraries and selftests, namely, `tools/bpf/bpftool/`, `tools/lib/bpf/`, and `tools/testing/selftests/bpf/`. There's no modification of kernel C files, kernel headers, or generated kernel code that would impact the image or modules. Therefore, this clearly falls under the second bullet point in the negative criteria. So, here's what I'm setting: * `WorthFuzzing: false` * `FocusSymbols: []` (empty list) * `EnableConfigs: []` (empty list) * `Reasoning: Concise explanation that all changes are in userspace tools (tools/bpf/bpftool), userspace library (tools/lib/bpf), and selftests (tools/testing/selftests/bpf), with no modifications affecting the compiled kernel image (vmlinux) or kernel modules.` No need for focus symbols or config changes. I'll call `set-results`. |
| 10/2 | 2026/11/03 13:52 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "All changes in this patch series are restricted to user-space tools and libraries (tools/bpf/bpftool, tools/lib/bpf) and selftests (tools/testing/selftests/bpf). They do not affect the compiled kernel image (vmlinux) or kernel modules, and are therefore not suitable for kernel fuzzing.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "All changes in this patch series are restricted to user-space tools and libraries (tools/bpf/bpftool, tools/lib/bpf) and selftests (tools/testing/selftests/bpf). They do not affect the compiled kernel image (vmlinux) or kernel modules, and are therefore not suitable for kernel fuzzing.",
"WorthFuzzing": false
} |
| 11/1 | 2026/11/03 13:52 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|