| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/12 13:12 | flow | patch-triage |
5mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch series only updates user-space tooling/selftests (tools/lib/bpf and tools/testing/selftests) and adds purely decorative diagnostic verifier logging (bpf_log) to existing failure paths across BPF link attachment functions (cgroup_bpf_link_attach, bpf_tracing_prog_attach, bpf_iter_link_attach, and bpf_tracing_multi_attach). No kernel data structures, control flow, error returns, or runtime assertions are altered.",
"WorthFuzzing": false
} |
| 1/1 | 2026/11/12 13:12 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit b80013f59c32cfe5682c551a62b0a9a4b3f52bba\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Nov 12 13:12:00 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h\nindex 02ef7f899b3dee..ddcdd136fd495f 100644\n--- a/include/linux/bpf-cgroup.h\n+++ b/include/linux/bpf-cgroup.h\n@@ -4,6 +4,7 @@\n \n #include \u003clinux/bpf.h\u003e\n #include \u003clinux/bpf-cgroup-defs.h\u003e\n+#include \u003clinux/bpf_verifier.h\u003e\n #include \u003clinux/errno.h\u003e\n #include \u003clinux/jump_label.h\u003e\n #include \u003clinux/percpu.h\u003e\n@@ -425,7 +426,8 @@ int cgroup_bpf_prog_attach(const union bpf_attr *attr,\n \t\t\t enum bpf_prog_type ptype, struct bpf_prog *prog);\n int cgroup_bpf_prog_detach(const union bpf_attr *attr,\n \t\t\t enum bpf_prog_type ptype);\n-int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);\n+int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,\n+\t\t\t struct bpf_verifier_log *log);\n int cgroup_bpf_prog_query(const union bpf_attr *attr,\n \t\t\t union bpf_attr __user *uattr, u32 uattr_size);\n \n@@ -452,7 +454,8 @@ static inline int cgroup_bpf_prog_detach(const union bpf_attr *attr,\n }\n \n static inline int cgroup_bpf_link_attach(const union bpf_attr *attr,\n-\t\t\t\t\t struct bpf_prog *prog)\n+\t\t\t\t\t struct bpf_prog *prog,\n+\t\t\t\t\t struct bpf_verifier_log *log)\n {\n \treturn -EINVAL;\n }\ndiff --git a/include/linux/bpf.h b/include/linux/bpf.h\nindex 520fd72e21fd07..7ff256a5d98b62 100644\n--- a/include/linux/bpf.h\n+++ b/include/linux/bpf.h\n@@ -3276,7 +3276,8 @@ void bpf_iter_unreg_target(const struct bpf_iter_reg *reg_info);\n int bpf_iter_prog_supported(struct bpf_prog *prog);\n const struct bpf_func_proto *\n bpf_iter_get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog);\n-int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_prog *prog);\n+int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_prog *prog,\n+\t\t\t struct bpf_verifier_log *log);\n int bpf_iter_new_fd(struct bpf_link *link);\n bool bpf_link_is_iter(struct bpf_link *link);\n struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);\ndiff --git a/include/linux/trace_events.h b/include/linux/trace_events.h\nindex 321f2f3a6c8e8f..bb825ea5d09c44 100644\n--- a/include/linux/trace_events.h\n+++ b/include/linux/trace_events.h\n@@ -16,6 +16,7 @@ struct tracer;\n struct dentry;\n struct bpf_prog;\n union bpf_attr;\n+struct bpf_verifier_log;\n \n /* Used for event string fields when they are NULL */\n #define EVENT_NULL_STR\t\t\"(null)\"\n@@ -796,7 +797,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,\n \t\t\t unsigned long *missed);\n int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);\n int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);\n-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr);\n+int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,\n+\t\t\t struct bpf_verifier_log *log);\n #else\n static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)\n {\n@@ -855,7 +857,8 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n \treturn -EOPNOTSUPP;\n }\n static inline int\n-bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n+bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,\n+\t\t\t struct bpf_verifier_log *log)\n {\n \treturn -EOPNOTSUPP;\n }\ndiff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c\nindex f0b29a17093579..dfefa5579e0335 100644\n--- a/kernel/bpf/bpf_iter.c\n+++ b/kernel/bpf/bpf_iter.c\n@@ -5,6 +5,7 @@\n #include \u003clinux/anon_inodes.h\u003e\n #include \u003clinux/filter.h\u003e\n #include \u003clinux/bpf.h\u003e\n+#include \u003clinux/bpf_verifier.h\u003e\n #include \u003clinux/rcupdate_trace.h\u003e\n \n struct bpf_iter_target_info {\n@@ -528,7 +529,7 @@ bool bpf_link_is_iter(struct bpf_link *link)\n }\n \n int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,\n-\t\t\t struct bpf_prog *prog)\n+\t\t\t struct bpf_prog *prog, struct bpf_verifier_log *log)\n {\n \tstruct bpf_iter_target_info *tinfo = NULL, *iter;\n \tstruct bpf_link_primer link_primer;\n@@ -538,24 +539,36 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,\n \tbpfptr_t ulinfo;\n \tint err;\n \n-\tif (attr-\u003elink_create.target_fd || attr-\u003elink_create.flags)\n+\tif (attr-\u003elink_create.target_fd) {\n+\t\tbpf_log(log, \"Invalid target_fd.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\tif (attr-\u003elink_create.flags) {\n+\t\tbpf_log(log, \"Invalid flags.\\n\");\n \t\treturn -EINVAL;\n+\t}\n \n \tmemset(\u0026linfo, 0, sizeof(union bpf_iter_link_info));\n \n \tulinfo = make_bpfptr(attr-\u003elink_create.iter_info, uattr.is_kernel);\n \tlinfo_len = attr-\u003elink_create.iter_info_len;\n-\tif (bpfptr_is_null(ulinfo) ^ !linfo_len)\n+\tif (bpfptr_is_null(ulinfo) ^ !linfo_len) {\n+\t\tbpf_log(log, \"iter_info and iter_info_len must be both set or both unset.\\n\");\n \t\treturn -EINVAL;\n+\t}\n \n \tif (!bpfptr_is_null(ulinfo)) {\n \t\terr = bpf_check_uarg_tail_zero(ulinfo, sizeof(linfo),\n \t\t\t\t\t linfo_len);\n-\t\tif (err)\n+\t\tif (err) {\n+\t\t\tbpf_log(log, \"Invalid iter_info.\\n\");\n \t\t\treturn err;\n+\t\t}\n \t\tlinfo_len = min_t(u32, linfo_len, sizeof(linfo));\n-\t\tif (copy_from_bpfptr(\u0026linfo, ulinfo, linfo_len))\n+\t\tif (copy_from_bpfptr(\u0026linfo, ulinfo, linfo_len)) {\n+\t\t\tbpf_log(log, \"Invalid iter_info_len.\\n\");\n \t\t\treturn -EFAULT;\n+\t\t}\n \t}\n \n \tprog_btf_id = prog-\u003eaux-\u003eattach_btf_id;\n@@ -570,8 +583,10 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,\n \tif (!tinfo)\n \t\treturn -ENOENT;\n \n-\tif (!bpf_iter_target_support_prog(tinfo, prog))\n+\tif (!bpf_iter_target_support_prog(tinfo, prog)) {\n+\t\tbpf_log(log, \"The iter target does not support the bpf prog.\\n\");\n \t\treturn -EINVAL;\n+\t}\n \n \tlink = kzalloc_obj(*link, GFP_USER | __GFP_NOWARN);\n \tif (!link)\ndiff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c\nindex 57a785241d42fb..a4d49c4df712b4 100644\n--- a/kernel/bpf/cgroup.c\n+++ b/kernel/bpf/cgroup.c\n@@ -854,7 +854,8 @@ static struct bpf_prog *bpf_get_anchor_prog(u32 flags, u32 id_or_fd)\n }\n \n static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_prog *prog,\n-\t\t\t\t\t struct bpf_cgroup_link *link, u32 flags, u32 id_or_fd)\n+\t\t\t\t\t struct bpf_cgroup_link *link, u32 flags, u32 id_or_fd,\n+\t\t\t\t\t struct bpf_verifier_log *log)\n {\n \tbool is_link = flags \u0026 BPF_F_LINK, is_id = flags \u0026 BPF_F_ID;\n \tstruct bpf_prog_list *pltmp, *pl = ERR_PTR(-EINVAL);\n@@ -867,20 +868,30 @@ static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_\n \tis_after = flags \u0026 BPF_F_AFTER;\n \tif (is_link || is_id || id_or_fd) {\n \t\t/* flags must have either BPF_F_BEFORE or BPF_F_AFTER */\n-\t\tif (is_before == is_after)\n+\t\tif (is_before == is_after) {\n+\t\t\tbpf_log(log, \"Specify exactly one of BPF_F_BEFORE or BPF_F_AFTER.\\n\");\n \t\t\treturn ERR_PTR(-EINVAL);\n-\t\tif ((is_link \u0026\u0026 !link) || (!is_link \u0026\u0026 !prog))\n+\t\t}\n+\t\tif (is_link \u0026\u0026 !link)\n+\t\t\treturn ERR_PTR(-EINVAL);\n+\t\tif (!is_link \u0026\u0026 !prog) {\n+\t\t\tbpf_log(log, \"BPF_F_LINK is required for relative link attachment.\\n\");\n \t\t\treturn ERR_PTR(-EINVAL);\n+\t\t}\n \t} else if (!hlist_empty(progs)) {\n \t\t/* flags cannot have both BPF_F_BEFORE and BPF_F_AFTER */\n-\t\tif (is_before \u0026\u0026 is_after)\n+\t\tif (is_before \u0026\u0026 is_after) {\n+\t\t\tbpf_log(log, \"BPF_F_BEFORE and BPF_F_AFTER are mutually exclusive.\\n\");\n \t\t\treturn ERR_PTR(-EINVAL);\n+\t\t}\n \t}\n \n \tif (is_link) {\n \t\tanchor_link = bpf_get_anchor_link(flags, id_or_fd);\n-\t\tif (IS_ERR(anchor_link))\n+\t\tif (IS_ERR(anchor_link)) {\n+\t\t\tbpf_log(log, \"Invalid relative link %s.\\n\", is_id ? \"ID\" : \"FD\");\n \t\t\treturn ERR_CAST(anchor_link);\n+\t\t}\n \t} else if (is_id || id_or_fd) {\n \t\tanchor_prog = bpf_get_anchor_prog(flags, id_or_fd);\n \t\tif (IS_ERR(anchor_prog))\n@@ -905,13 +916,16 @@ static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_\n \thlist_for_each_entry(pltmp, progs, node) {\n \t\tif ((anchor_prog \u0026\u0026 anchor_prog == pltmp-\u003eprog) ||\n \t\t (anchor_link \u0026\u0026 anchor_link == \u0026pltmp-\u003elink-\u003elink)) {\n-\t\t\tif (!!(pltmp-\u003eflags \u0026 BPF_F_PREORDER) != preorder)\n+\t\t\tif (!!(pltmp-\u003eflags \u0026 BPF_F_PREORDER) != preorder) {\n+\t\t\t\tbpf_log(log, \"Relative attachment BPF_F_PREORDER mismatch.\\n\");\n \t\t\t\tgoto out;\n+\t\t\t}\n \t\t\tpl = pltmp;\n \t\t\tgoto out;\n \t\t}\n \t}\n \n+\tbpf_log(log, \"Relative attachment not found in target cgroup.\\n\");\n \tpl = ERR_PTR(-ENOENT);\n out:\n \tif (anchor_link)\n@@ -923,11 +937,11 @@ static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_\n \n static int insert_pl_to_hlist(struct bpf_prog_list *pl, struct hlist_head *progs,\n \t\t\t struct bpf_prog *prog, struct bpf_cgroup_link *link,\n-\t\t\t u32 flags, u32 id_or_fd)\n+\t\t\t u32 flags, u32 id_or_fd, struct bpf_verifier_log *log)\n {\n \tstruct bpf_prog_list *pltmp;\n \n-\tpltmp = get_prog_list(progs, prog, link, flags, id_or_fd);\n+\tpltmp = get_prog_list(progs, prog, link, flags, id_or_fd, log);\n \tif (IS_ERR(pltmp))\n \t\treturn PTR_ERR(pltmp);\n \n@@ -952,6 +966,7 @@ static int insert_pl_to_hlist(struct bpf_prog_list *pl, struct hlist_head *progs\n * @flags: Option flags\n * @id_or_fd: Relative prog id or fd\n * @revision: bpf_prog_list revision\n+ * @log: Optional log for attachment errors\n *\n * Exactly one of @prog or @link can be non-null.\n * Must be called with cgroup_mutex held.\n@@ -960,7 +975,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,\n \t\t\t struct bpf_prog *prog, struct bpf_prog *replace_prog,\n \t\t\t struct bpf_cgroup_link *link,\n \t\t\t enum bpf_attach_type type, u32 flags, u32 id_or_fd,\n-\t\t\t u64 revision)\n+\t\t\t u64 revision, struct bpf_verifier_log *log)\n {\n \tu32 saved_flags = (flags \u0026 (BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI));\n \tstruct bpf_prog *old_prog = NULL;\n@@ -991,23 +1006,33 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,\n \tatype = bpf_cgroup_atype_find(type, new_prog-\u003eaux-\u003eattach_btf_id);\n \tif (atype \u003c 0)\n \t\treturn -EINVAL;\n-\tif (revision \u0026\u0026 revision != cgrp-\u003ebpf.revisions[atype])\n+\tif (revision \u0026\u0026 revision != cgrp-\u003ebpf.revisions[atype]) {\n+\t\tbpf_log(log, \"Cgroup revision mismatch: expected %llu, actual %llu.\\n\",\n+\t\t\trevision, cgrp-\u003ebpf.revisions[atype]);\n \t\treturn -ESTALE;\n+\t}\n \n \tprogs = \u0026cgrp-\u003ebpf.progs[atype];\n \n-\tif (!hierarchy_allows_attach(cgrp, atype))\n+\tif (!hierarchy_allows_attach(cgrp, atype)) {\n+\t\tbpf_log(log, \"Cgroup hierarchy does not allow attachment.\\n\");\n \t\treturn -EPERM;\n+\t}\n \n-\tif (!hlist_empty(progs) \u0026\u0026 cgrp-\u003ebpf.flags[atype] != saved_flags)\n+\tif (!hlist_empty(progs) \u0026\u0026 cgrp-\u003ebpf.flags[atype] != saved_flags) {\n \t\t/* Disallow attaching non-overridable on top\n \t\t * of existing overridable in this cgroup.\n \t\t * Disallow attaching multi-prog if overridable or none\n \t\t */\n+\t\tbpf_log(log, \"Attachment flags conflict with existing flags.\\n\");\n \t\treturn -EPERM;\n+\t}\n \n-\tif (prog_list_length(progs, NULL) \u003e= BPF_CGROUP_MAX_PROGS)\n+\tif (prog_list_length(progs, NULL) \u003e= BPF_CGROUP_MAX_PROGS) {\n+\t\tbpf_log(log, \"Too many programs attached to cgroup (limit %u).\\n\",\n+\t\t\tBPF_CGROUP_MAX_PROGS);\n \t\treturn -E2BIG;\n+\t}\n \n \tpl = find_attach_entry(progs, prog, link, replace_prog,\n \t\t\t flags \u0026 BPF_F_ALLOW_MULTI);\n@@ -1029,7 +1054,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,\n \t\t\treturn -ENOMEM;\n \t\t}\n \n-\t\terr = insert_pl_to_hlist(pl, progs, prog, link, flags, id_or_fd);\n+\t\terr = insert_pl_to_hlist(pl, progs, prog, link, flags, id_or_fd, log);\n \t\tif (err) {\n \t\t\tkfree(pl);\n \t\t\tbpf_cgroup_storages_free(new_storage);\n@@ -1089,13 +1114,14 @@ static int cgroup_bpf_attach(struct cgroup *cgrp,\n \t\t\t struct bpf_prog *prog, struct bpf_prog *replace_prog,\n \t\t\t struct bpf_cgroup_link *link,\n \t\t\t enum bpf_attach_type type,\n-\t\t\t u32 flags, u32 id_or_fd, u64 revision)\n+\t\t\t u32 flags, u32 id_or_fd, u64 revision,\n+\t\t\t struct bpf_verifier_log *log)\n {\n \tint ret;\n \n \tcgroup_lock();\n \tret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags,\n-\t\t\t\t id_or_fd, revision);\n+\t\t\t\t id_or_fd, revision, log);\n \tcgroup_unlock();\n \treturn ret;\n }\n@@ -1572,7 +1598,7 @@ int cgroup_bpf_prog_attach(const union bpf_attr *attr,\n \n \tret = cgroup_bpf_attach(cgrp, prog, replace_prog, NULL,\n \t\t\t\tattr-\u003eattach_type, attr-\u003eattach_flags,\n-\t\t\t\tattr-\u003erelative_fd, attr-\u003eexpected_revision);\n+\t\t\t\tattr-\u003erelative_fd, attr-\u003eexpected_revision, NULL);\n \n \tif (replace_prog)\n \t\tbpf_prog_put(replace_prog);\n@@ -1702,19 +1728,24 @@ static const struct bpf_link_ops bpf_cgroup_link_lops = {\n \t BPF_F_PREORDER |\t\\\n \t BPF_F_LINK)\n \n-int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n+int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,\n+\t\t\t struct bpf_verifier_log *log)\n {\n \tstruct bpf_link_primer link_primer;\n \tstruct bpf_cgroup_link *link;\n \tstruct cgroup *cgrp;\n \tint err;\n \n-\tif (attr-\u003elink_create.flags \u0026 (~BPF_F_LINK_ATTACH_MASK))\n+\tif (attr-\u003elink_create.flags \u0026 (~BPF_F_LINK_ATTACH_MASK)) {\n+\t\tbpf_log(log, \"Invalid flags.\\n\");\n \t\treturn -EINVAL;\n+\t}\n \n \tcgrp = cgroup_get_from_fd(attr-\u003elink_create.target_fd);\n-\tif (IS_ERR(cgrp))\n+\tif (IS_ERR(cgrp)) {\n+\t\tbpf_log(log, \"Invalid target_fd.\\n\");\n \t\treturn PTR_ERR(cgrp);\n+\t}\n \n \tlink = kzalloc_obj(*link, GFP_USER);\n \tif (!link) {\n@@ -1734,7 +1765,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n \terr = cgroup_bpf_attach(cgrp, NULL, NULL, link,\n \t\t\t\tlink-\u003elink.attach_type, BPF_F_ALLOW_MULTI | attr-\u003elink_create.flags,\n \t\t\t\tattr-\u003elink_create.cgroup.relative_fd,\n-\t\t\t\tattr-\u003elink_create.cgroup.expected_revision);\n+\t\t\t\tattr-\u003elink_create.cgroup.expected_revision, log);\n \tif (err) {\n \t\tbpf_link_cleanup(\u0026link_primer);\n \t\tgoto out_put_cgroup;\n@@ -3184,7 +3215,8 @@ int cgroup_bpf_struct_ops_attach(struct bpf_map *map, const union bpf_attr *attr\n \tcgrp-\u003ebpf.flags[atype] = BPF_F_ALLOW_MULTI;\n \n \terr = insert_pl_to_hlist(pl, progs, NULL, link,\n-\t\t\t\t flags | BPF_F_ALLOW_MULTI, attr-\u003elink_create.cgroup.relative_fd);\n+\t\t\t\t flags | BPF_F_ALLOW_MULTI,\n+\t\t\t\t attr-\u003elink_create.cgroup.relative_fd, NULL);\n \tif (err)\n \t\tgoto unlock;\n \ndiff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c\nindex 9004f2673ccf96..43417824d85109 100644\n--- a/kernel/bpf/syscall.c\n+++ b/kernel/bpf/syscall.c\n@@ -3674,7 +3674,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n \t\t\t\t int tgt_prog_fd,\n \t\t\t\t u32 btf_id,\n \t\t\t\t u64 bpf_cookie,\n-\t\t\t\t enum bpf_attach_type attach_type)\n+\t\t\t\t enum bpf_attach_type attach_type,\n+\t\t\t\t struct bpf_verifier_log *log)\n {\n \tstruct bpf_link_primer link_primer;\n \tstruct bpf_prog *tgt_prog = NULL;\n@@ -3711,6 +3712,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n \t}\n \n \tif (!!tgt_prog_fd != !!btf_id) {\n+\t\tbpf_log(log, \"tgt_prog_fd and btf_id must be both set or both unset.\\n\");\n \t\terr = -EINVAL;\n \t\tgoto out_put_prog;\n \t}\n@@ -3723,12 +3725,14 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n \t\t * attach_tracing_prog flag is set.\n \t\t */\n \t\tif (prog-\u003etype != BPF_PROG_TYPE_EXT) {\n+\t\t\tbpf_log(log, \"tgt_prog_fd is only allowed for freplace prog.\\n\");\n \t\t\terr = -EINVAL;\n \t\t\tgoto out_put_prog;\n \t\t}\n \n \t\ttgt_prog = bpf_prog_get(tgt_prog_fd);\n \t\tif (IS_ERR(tgt_prog)) {\n+\t\t\tbpf_log(log, \"Invalid tgt_prog_fd.\\n\");\n \t\t\terr = PTR_ERR(tgt_prog);\n \t\t\ttgt_prog = NULL;\n \t\t\tgoto out_put_prog;\n@@ -3783,11 +3787,13 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n \t\t */\n \t\tif (prog-\u003etype != BPF_PROG_TYPE_TRACING \u0026\u0026\n \t\t prog-\u003etype != BPF_PROG_TYPE_LSM) {\n+\t\t\tbpf_log(log, \"Only allow re-attach for tracing and lsm progs.\\n\");\n \t\t\terr = -EINVAL;\n \t\t\tgoto out_unlock;\n \t\t}\n \t\t/* We can allow re-attach only if we have valid attach_btf. */\n \t\tif (!prog-\u003eaux-\u003eattach_btf) {\n+\t\t\tbpf_log(log, \"Invalid attach_btf.\\n\");\n \t\t\terr = -EINVAL;\n \t\t\tgoto out_unlock;\n \t\t}\n@@ -3803,7 +3809,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n \t\t */\n \t\tstruct bpf_attach_target_info tgt_info = {};\n \n-\t\terr = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,\n+\t\terr = bpf_check_attach_target(log, prog, tgt_prog, btf_id,\n \t\t\t\t\t \u0026tgt_info);\n \t\tif (err)\n \t\t\tgoto out_unlock;\n@@ -3843,6 +3849,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n \t */\n \tif (prog-\u003etype == BPF_PROG_TYPE_EXT \u0026\u0026\n \t prog-\u003eaux-\u003ekprobe_write_ctx != tgt_prog-\u003eaux-\u003ekprobe_write_ctx) {\n+\t\tbpf_log(log, \"Invalid kprobe_write_ctx.\\n\");\n \t\terr = -EINVAL;\n \t\tgoto out_unlock;\n \t}\n@@ -4374,7 +4381,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog,\n \t\t\ttp_name = prog-\u003eaux-\u003eattach_func_name;\n \t\t\tbreak;\n \t\t}\n-\t\treturn bpf_tracing_prog_attach(prog, 0, 0, 0, attach_type);\n+\t\treturn bpf_tracing_prog_attach(prog, 0, 0, 0, attach_type, NULL);\n \tcase BPF_PROG_TYPE_RAW_TRACEPOINT:\n \tcase BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:\n \t\tif (strncpy_from_user(buf, user_tp_name, sizeof(buf) - 1) \u003c 0)\n@@ -5900,18 +5907,20 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a\n \tcase BPF_PROG_TYPE_CGROUP_DEVICE:\n \tcase BPF_PROG_TYPE_CGROUP_SYSCTL:\n \tcase BPF_PROG_TYPE_CGROUP_SOCKOPT:\n-\t\tret = cgroup_bpf_link_attach(attr, prog);\n+\t\tret = cgroup_bpf_link_attach(attr, prog, log);\n \t\tbreak;\n \tcase BPF_PROG_TYPE_EXT:\n \t\tret = bpf_tracing_prog_attach(prog,\n \t\t\t\t\t attr-\u003elink_create.target_fd,\n \t\t\t\t\t attr-\u003elink_create.target_btf_id,\n \t\t\t\t\t attr-\u003elink_create.tracing.cookie,\n-\t\t\t\t\t attr-\u003elink_create.attach_type);\n+\t\t\t\t\t attr-\u003elink_create.attach_type,\n+\t\t\t\t\t log);\n \t\tbreak;\n \tcase BPF_PROG_TYPE_LSM:\n \tcase BPF_PROG_TYPE_TRACING:\n \t\tif (attr-\u003elink_create.attach_type != prog-\u003eexpected_attach_type) {\n+\t\t\tbpf_log(log, \"Invalid attach_type.\\n\");\n \t\t\tret = -EINVAL;\n \t\t\tgoto out;\n \t\t}\n@@ -5919,17 +5928,18 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a\n \t\t\tret = bpf_raw_tp_link_attach(prog, NULL, attr-\u003elink_create.tracing.cookie,\n \t\t\t\t\t\t attr-\u003elink_create.attach_type);\n \t\telse if (prog-\u003eexpected_attach_type == BPF_TRACE_ITER)\n-\t\t\tret = bpf_iter_link_attach(attr, uattr, prog);\n+\t\t\tret = bpf_iter_link_attach(attr, uattr, prog, log);\n \t\telse if (prog-\u003eexpected_attach_type == BPF_LSM_CGROUP)\n-\t\t\tret = cgroup_bpf_link_attach(attr, prog);\n+\t\t\tret = cgroup_bpf_link_attach(attr, prog, log);\n \t\telse if (is_tracing_multi(prog-\u003eexpected_attach_type))\n-\t\t\tret = bpf_tracing_multi_attach(prog, attr);\n+\t\t\tret = bpf_tracing_multi_attach(prog, attr, log);\n \t\telse\n \t\t\tret = bpf_tracing_prog_attach(prog,\n \t\t\t\t\t\t attr-\u003elink_create.target_fd,\n \t\t\t\t\t\t attr-\u003elink_create.target_btf_id,\n \t\t\t\t\t\t attr-\u003elink_create.tracing.cookie,\n-\t\t\t\t\t\t attr-\u003elink_create.attach_type);\n+\t\t\t\t\t\t attr-\u003elink_create.attach_type,\n+\t\t\t\t\t\t log);\n \t\tbreak;\n \tcase BPF_PROG_TYPE_FLOW_DISSECTOR:\n \tcase BPF_PROG_TYPE_SK_LOOKUP:\ndiff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c\nindex 2aec56d7f3d3ef..352a1cd0c863a1 100644\n--- a/kernel/trace/bpf_trace.c\n+++ b/kernel/trace/bpf_trace.c\n@@ -3861,7 +3861,8 @@ static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)\n \treturn err;\n }\n \n-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n+int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,\n+\t\t\t struct bpf_verifier_log *log)\n {\n \tstruct bpf_tracing_multi_link *link = NULL;\n \tstruct bpf_tramp_node *fexits = NULL;\n@@ -3875,12 +3876,26 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n \tuids = u64_to_user_ptr(attr-\u003elink_create.tracing_multi.ids);\n \tcnt = attr-\u003elink_create.tracing_multi.cnt;\n \n-\tif (!cnt || !uids)\n+\tif (!cnt) {\n+\t\tbpf_log(log, \"tracing_multi.cnt cannot be zero.\\n\");\n \t\treturn -EINVAL;\n-\tif (cnt \u003e MAX_TRACING_MULTI_CNT)\n+\t}\n+\tif (!uids) {\n+\t\tbpf_log(log, \"tracing_multi.ids must be set.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\tif (cnt \u003e MAX_TRACING_MULTI_CNT) {\n+\t\tbpf_log(log, \"tracing_multi.cnt is too large.\\n\");\n \t\treturn -E2BIG;\n-\tif (attr-\u003elink_create.flags || attr-\u003elink_create.target_fd)\n+\t}\n+\tif (attr-\u003elink_create.flags) {\n+\t\tbpf_log(log, \"Invalid flags.\\n\");\n \t\treturn -EINVAL;\n+\t}\n+\tif (attr-\u003elink_create.target_fd) {\n+\t\tbpf_log(log, \"Invalid target_fd.\\n\");\n+\t\treturn -EINVAL;\n+\t}\n \n \tids = kvmalloc_objs(*ids, cnt);\n \tif (!ids)\n@@ -3951,7 +3966,8 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n \n #else\n \n-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)\n+int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,\n+\t\t\t struct bpf_verifier_log *log)\n {\n \treturn -EOPNOTSUPP;\n }\ndiff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c\nindex 38dcb31e8c0ed1..174a8bfaf66382 100644\n--- a/tools/lib/bpf/bpf.c\n+++ b/tools/lib/bpf/bpf.c\n@@ -808,11 +808,6 @@ int bpf_link_create(int prog_fd, int target_fd,\n \tif (iter_info_len \u0026\u0026 attach_type != BPF_TRACE_ITER)\n \t\treturn libbpf_err(-EINVAL);\n \n-\tif (iter_info_len)\n-\t\titer_info = OPTS_GET(opts, iter_info, (void *)0);\n-\telse\n-\t\tlog_opts = OPTS_GET(opts, log_opts, (void *)0);\n-\n \t/* validate we don't have unexpected combinations of non-zero fields */\n \tif (iter_info_len || target_btf_id) {\n \t\tif (iter_info_len \u0026\u0026 target_btf_id)\n@@ -821,6 +816,16 @@ int bpf_link_create(int prog_fd, int target_fd,\n \t\t\treturn libbpf_err(-EINVAL);\n \t}\n \n+\tif (iter_info_len) {\n+\t\tif (OPTS_GET(opts, iter.len, 0))\n+\t\t\treturn libbpf_err(-EINVAL);\n+\t\titer_info = OPTS_GET(opts, iter_info, (void *)0);\n+\t} else {\n+\t\tlog_opts = OPTS_GET(opts, log_opts, (void *)0);\n+\t\titer_info = OPTS_GET(opts, iter.info, (void *)0);\n+\t\titer_info_len = OPTS_GET(opts, iter.len, 0);\n+\t}\n+\n \tmemset(\u0026attr, 0, attr_sz);\n \tattr.link_create.prog_fd = prog_fd;\n \tattr.link_create.target_fd = target_fd;\n@@ -970,7 +975,7 @@ int bpf_link_create(int prog_fd, int target_fd,\n \t\t\treturn libbpf_err(-EINVAL);\n \t\tbreak;\n \tdefault:\n-\t\tif (!OPTS_ZEROED(opts, iter_info_len))\n+\t\tif (!OPTS_ZEROED(opts, log_opts))\n \t\t\treturn libbpf_err(-EINVAL);\n \t\tbreak;\n \t}\ndiff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h\nindex fe3b7fd8512bdb..2ac143fd1102ed 100644\n--- a/tools/lib/bpf/bpf.h\n+++ b/tools/lib/bpf/bpf.h\n@@ -422,6 +422,10 @@ union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */\n struct bpf_link_create_opts {\n \tsize_t sz; /* size of this struct for forward/backward compatibility */\n \t__u32 flags;\n+\t/*\n+\t * iter_info and iter_info_len are deprecated, use iter.info and\n+\t * iter.len instead.\n+\t */\n \tunion {\n \t\tunion bpf_iter_link_info *iter_info;\n \t\tstruct bpf_log_opts *log_opts;\n@@ -478,6 +482,10 @@ struct bpf_link_create_opts {\n \t\t\tconst __u64 *cookies;\n \t\t\t__u32 cnt;\n \t\t} tracing_multi;\n+\t\tstruct {\n+\t\t\tunion bpf_iter_link_info *info;\n+\t\t\t__u32 len;\n+\t\t} iter;\n \t};\n \tsize_t :0;\n };\ndiff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_link.c b/tools/testing/selftests/bpf/prog_tests/cgroup_link.c\nindex 15093a69510eba..5a27d3a6a26c77 100644\n--- a/tools/testing/selftests/bpf/prog_tests/cgroup_link.c\n+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_link.c\n@@ -253,3 +253,327 @@ void serial_test_cgroup_link(void)\n \t}\n \tcleanup_cgroup_environment();\n }\n+\n+static void check_cgroup_link_create_log(int prog_fd, int target_fd,\n+\t\t\t\t\t struct bpf_link_create_opts *opts,\n+\t\t\t\t\t int err_exp, const char *msg)\n+{\n+\tchar log_buf[128] = {};\n+\tLIBBPF_OPTS(bpf_log_opts, log_opts,\n+\t\t .buf = log_buf,\n+\t\t .size = sizeof(log_buf),\n+\t\t .level = 1,\n+\t);\n+\tint fd;\n+\n+\topts-\u003elog_opts = \u0026log_opts;\n+\tfd = bpf_link_create(prog_fd, target_fd, BPF_CGROUP_INET_EGRESS, opts);\n+\tif (!ASSERT_LT(fd, 0, \"bpf_link_create\")) {\n+\t\tclose(fd);\n+\t\treturn;\n+\t}\n+\n+\tASSERT_EQ(fd, err_exp, \"err\");\n+\tASSERT_STREQ(log_buf, msg, \"log_buf\");\n+\tASSERT_EQ(log_opts.true_size, strlen(msg) + 1, \"log_size\");\n+}\n+\n+static void test_cgroup_link_create_log(int target_fd, __u32 flags, int err_exp, const char *msg)\n+{\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = flags,\n+\t);\n+\tstruct test_cgroup_link *skel;\n+\n+\tskel = test_cgroup_link__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"test_cgroup_link__open_and_load\"))\n+\t\treturn;\n+\n+\tcheck_cgroup_link_create_log(bpf_program__fd(skel-\u003eprogs.egress), target_fd, \u0026opts,\n+\t\t\t\t err_exp, msg);\n+\n+\ttest_cgroup_link__destroy(skel);\n+}\n+\n+static void test_log_invalid_flags(void)\n+{\n+\tconst char *msg = \"Invalid flags.\\n\";\n+\n+\ttest_cgroup_link_create_log(-1, BPF_F_ALLOW_OVERRIDE, -EINVAL, msg);\n+}\n+\n+static void test_log_invalid_target_fd(void)\n+{\n+\tconst char *msg = \"Invalid target_fd.\\n\";\n+\n+\ttest_cgroup_link_create_log(-1, 0, -EBADF, msg);\n+}\n+\n+static void test_log_cgroup_attach(struct bpf_link_create_opts *opts,\n+\t\t\t\t int err_exp, const char *msg)\n+{\n+\tstruct test_cgroup_link *skel;\n+\tint cg;\n+\n+\tcg = test__join_cgroup(\"/cgroup_link_log_attach\");\n+\tif (!ASSERT_GE(cg, 0, \"join_cgroup\"))\n+\t\treturn;\n+\n+\tskel = test_cgroup_link__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"test_cgroup_link__open_and_load\"))\n+\t\tgoto out;\n+\n+\tcheck_cgroup_link_create_log(bpf_program__fd(skel-\u003eprogs.egress), cg, opts, err_exp, msg);\n+\ttest_cgroup_link__destroy(skel);\n+\n+out:\n+\tclose(cg);\n+}\n+\n+static void test_log_relative_without_order(void)\n+{\n+\tconst char *msg = \"Specify exactly one of BPF_F_BEFORE or BPF_F_AFTER.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = BPF_F_LINK,\n+\t);\n+\n+\ttest_log_cgroup_attach(\u0026opts, -EINVAL, msg);\n+}\n+\n+static void test_log_relative_both_orders(void)\n+{\n+\tconst char *msg = \"Specify exactly one of BPF_F_BEFORE or BPF_F_AFTER.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = BPF_F_LINK | BPF_F_BEFORE | BPF_F_AFTER,\n+\t);\n+\n+\ttest_log_cgroup_attach(\u0026opts, -EINVAL, msg);\n+}\n+\n+static void test_log_relative_type_mismatch(void)\n+{\n+\tconst char *msg = \"BPF_F_LINK is required for relative link attachment.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = BPF_F_BEFORE,\n+\t\t .cgroup.relative_fd = -1,\n+\t);\n+\n+\ttest_log_cgroup_attach(\u0026opts, -EINVAL, msg);\n+}\n+\n+static void test_log_invalid_relative_link_fd(void)\n+{\n+\tconst char *msg = \"Invalid relative link FD.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = BPF_F_LINK | BPF_F_BEFORE,\n+\t\t .cgroup.relative_fd = -1,\n+\t);\n+\n+\ttest_log_cgroup_attach(\u0026opts, -EBADF, msg);\n+}\n+\n+static void test_log_invalid_relative_link_id(void)\n+{\n+\tconst char *msg = \"Invalid relative link ID.\\n\";\n+\t/* Link ID zero cannot identify a link. */\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = BPF_F_LINK | BPF_F_ID | BPF_F_BEFORE,\n+\t);\n+\n+\ttest_log_cgroup_attach(\u0026opts, -ENOENT, msg);\n+}\n+\n+static void test_log_relative_anchor(__u32 flags, bool other_cgroup, int err_exp, const char *msg)\n+{\n+\tint cg, other_cg = -1, anchor_fd = -1, prog_fd;\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = flags,\n+\t);\n+\tstruct test_cgroup_link *skel;\n+\n+\tcg = test__join_cgroup(\"/cgroup_link_log_relative\");\n+\tif (!ASSERT_GE(cg, 0, \"join_cgroup\"))\n+\t\treturn;\n+\n+\tif (other_cgroup) {\n+\t\tother_cg = test__join_cgroup(\"/cgroup_link_log_other\");\n+\t\tif (!ASSERT_GE(other_cg, 0, \"join_cgroup other\"))\n+\t\t\tgoto cleanup;\n+\t}\n+\n+\tskel = test_cgroup_link__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"test_cgroup_link__open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.egress);\n+\tanchor_fd = bpf_link_create(prog_fd, cg, BPF_CGROUP_INET_EGRESS, NULL);\n+\tif (!ASSERT_GE(anchor_fd, 0, \"bpf_link_create\"))\n+\t\tgoto destroy;\n+\n+\tif (flags \u0026 BPF_F_LINK)\n+\t\topts.cgroup.relative_fd = anchor_fd;\n+\tcheck_cgroup_link_create_log(prog_fd, other_cgroup ? other_cg : cg, \u0026opts, err_exp, msg);\n+\n+\tclose(anchor_fd);\n+\n+destroy:\n+\ttest_cgroup_link__destroy(skel);\n+cleanup:\n+\tif (other_cg \u003e= 0)\n+\t\tclose(other_cg);\n+\tclose(cg);\n+}\n+\n+static void test_log_both_orders(void)\n+{\n+\tconst char *msg = \"BPF_F_BEFORE and BPF_F_AFTER are mutually exclusive.\\n\";\n+\n+\ttest_log_relative_anchor(BPF_F_BEFORE | BPF_F_AFTER, false, -EINVAL, msg);\n+}\n+\n+static void test_log_relative_preorder_mismatch(void)\n+{\n+\tconst char *msg = \"Relative attachment BPF_F_PREORDER mismatch.\\n\";\n+\n+\ttest_log_relative_anchor(BPF_F_LINK | BPF_F_BEFORE | BPF_F_PREORDER, false, -EINVAL, msg);\n+}\n+\n+static void test_log_relative_not_in_cgroup(void)\n+{\n+\tconst char *msg = \"Relative attachment not found in target cgroup.\\n\";\n+\n+\ttest_log_relative_anchor(BPF_F_LINK | BPF_F_BEFORE, true, -ENOENT, msg);\n+}\n+\n+static void test_log_revision_mismatch(void)\n+{\n+\tconst char *msg = \"Cgroup revision mismatch: expected 2, actual 1.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .cgroup.expected_revision = 2,\n+\t);\n+\n+\ttest_log_cgroup_attach(\u0026opts, -ESTALE, msg);\n+}\n+\n+static void test_log_exclusive_attach(bool child, const char *msg)\n+{\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts);\n+\tint cg, child_cg = -1, prog_fd, err;\n+\tstruct test_cgroup_link *skel;\n+\n+\tcg = test__join_cgroup(\"/cgroup_link_log_exclusive\");\n+\tif (!ASSERT_GE(cg, 0, \"join_cgroup\"))\n+\t\treturn;\n+\n+\tif (child) {\n+\t\tchild_cg = test__join_cgroup(\"/cgroup_link_log_exclusive/child\");\n+\t\tif (!ASSERT_GE(child_cg, 0, \"join_child_cgroup\"))\n+\t\t\tgoto cleanup;\n+\t}\n+\n+\tskel = test_cgroup_link__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"test_cgroup_link__open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.egress);\n+\n+\terr = bpf_prog_attach(prog_fd, cg, BPF_CGROUP_INET_EGRESS, 0);\n+\tif (!ASSERT_OK(err, \"bpf_prog_attach\"))\n+\t\tgoto destroy;\n+\n+\tcheck_cgroup_link_create_log(prog_fd, child ? child_cg : cg, \u0026opts, -EPERM, msg);\n+\n+\terr = bpf_prog_detach2(prog_fd, cg, BPF_CGROUP_INET_EGRESS);\n+\tASSERT_OK(err, \"bpf_prog_detach2\");\n+\n+destroy:\n+\ttest_cgroup_link__destroy(skel);\n+cleanup:\n+\tif (child_cg \u003e= 0)\n+\t\tclose(child_cg);\n+\tclose(cg);\n+}\n+\n+static void test_log_attachment_flags_conflict(void)\n+{\n+\tconst char *msg = \"Attachment flags conflict with existing flags.\\n\";\n+\n+\ttest_log_exclusive_attach(false, msg);\n+}\n+\n+static void test_log_hierarchy_disallows_attach(void)\n+{\n+\tconst char *msg = \"Cgroup hierarchy does not allow attachment.\\n\";\n+\n+\ttest_log_exclusive_attach(true, msg);\n+}\n+\n+#define BPF_CGROUP_MAX_PROGS 64\n+\n+static void test_log_too_many_programs(void)\n+{\n+\tconst char *msg = \"Too many programs attached to cgroup (limit 64).\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts);\n+\tint cg, prog_fd, err, i, nr_links = 0;\n+\tint link_fds[BPF_CGROUP_MAX_PROGS];\n+\tstruct test_cgroup_link *skel;\n+\n+\tcg = test__join_cgroup(\"/cgroup_link_log_limit\");\n+\tif (!ASSERT_GE(cg, 0, \"join_cgroup\"))\n+\t\treturn;\n+\n+\tskel = test_cgroup_link__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"test_cgroup_link__open_and_load\"))\n+\t\tgoto cleanup;\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.egress);\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(link_fds); i++) {\n+\t\terr = bpf_link_create(prog_fd, cg, BPF_CGROUP_INET_EGRESS, NULL);\n+\t\tif (!ASSERT_GE(err, 0, \"bpf_link_create\"))\n+\t\t\tgoto destroy;\n+\n+\t\tlink_fds[nr_links++] = err;\n+\t}\n+\n+\tcheck_cgroup_link_create_log(prog_fd, cg, \u0026opts, -E2BIG, msg);\n+\n+destroy:\n+\tfor (i = 0; i \u003c nr_links; i++)\n+\t\tclose(link_fds[i]);\n+\ttest_cgroup_link__destroy(skel);\n+cleanup:\n+\tclose(cg);\n+}\n+\n+void test_cgroup_link_log(void)\n+{\n+\tif (test__start_subtest(\"invalid_flags\"))\n+\t\ttest_log_invalid_flags();\n+\tif (test__start_subtest(\"invalid_target_fd\"))\n+\t\ttest_log_invalid_target_fd();\n+\tif (test__start_subtest(\"relative_without_order\"))\n+\t\ttest_log_relative_without_order();\n+\tif (test__start_subtest(\"relative_both_orders\"))\n+\t\ttest_log_relative_both_orders();\n+\tif (test__start_subtest(\"relative_type_mismatch\"))\n+\t\ttest_log_relative_type_mismatch();\n+\tif (test__start_subtest(\"invalid_relative_link_fd\"))\n+\t\ttest_log_invalid_relative_link_fd();\n+\tif (test__start_subtest(\"invalid_relative_link_id\"))\n+\t\ttest_log_invalid_relative_link_id();\n+\tif (test__start_subtest(\"both_orders\"))\n+\t\ttest_log_both_orders();\n+\tif (test__start_subtest(\"relative_preorder_mismatch\"))\n+\t\ttest_log_relative_preorder_mismatch();\n+\tif (test__start_subtest(\"relative_not_in_cgroup\"))\n+\t\ttest_log_relative_not_in_cgroup();\n+\tif (test__start_subtest(\"revision_mismatch\"))\n+\t\ttest_log_revision_mismatch();\n+\tif (test__start_subtest(\"attachment_flags_conflict\"))\n+\t\ttest_log_attachment_flags_conflict();\n+\tif (test__start_subtest(\"hierarchy_disallows_attach\"))\n+\t\ttest_log_hierarchy_disallows_attach();\n+\tif (test__start_subtest(\"too_many_programs\"))\n+\t\ttest_log_too_many_programs();\n+}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/iter_link.c b/tools/testing/selftests/bpf/prog_tests/iter_link.c\nnew file mode 100644\nindex 00000000000000..c684a109091ac5\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/iter_link.c\n@@ -0,0 +1,132 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003ctest_progs.h\u003e\n+#include \"bpf_iter_bpf_map.skel.h\"\n+\n+static void test_iter_link_create_log(int target_fd, struct bpf_link_create_opts *opts,\n+\t\t\t\t __u64 flags, int err_exp, const char *msg)\n+{\n+\tstruct bpf_iter_bpf_map *skel;\n+\tchar log_buf[128] = {};\n+\tint err, fd, prog_fd;\n+\tLIBBPF_OPTS(bpf_log_opts, log_opts,\n+\t\t.buf = log_buf,\n+\t\t.size = sizeof(log_buf),\n+\t\t.level = 1,\n+\t);\n+\n+\tskel = bpf_iter_bpf_map__open();\n+\tif (!ASSERT_OK_PTR(skel, \"bpf_iter_bpf_map__open\"))\n+\t\treturn;\n+\n+\terr = bpf_program__set_flags(skel-\u003eprogs.dump_bpf_map, flags);\n+\tif (!ASSERT_OK(err, \"bpf_program__set_flags\"))\n+\t\tgoto out;\n+\n+\terr = bpf_iter_bpf_map__load(skel);\n+\tif (!ASSERT_OK(err, \"bpf_iter_bpf_map__load\"))\n+\t\tgoto out;\n+\n+\topts-\u003elog_opts = \u0026log_opts;\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.dump_bpf_map);\n+\tfd = bpf_link_create(prog_fd, target_fd, BPF_TRACE_ITER, opts);\n+\tif (!ASSERT_LT(fd, 0, \"bpf_link_create\")) {\n+\t\tclose(fd);\n+\t\tgoto out;\n+\t}\n+\n+\tASSERT_EQ(fd, err_exp, \"err\");\n+\tASSERT_STREQ(log_buf, msg, \"log_buf\");\n+\tASSERT_EQ(log_opts.true_size, strlen(msg) + 1, \"log_size\");\n+\n+out:\n+\tbpf_iter_bpf_map__destroy(skel);\n+}\n+\n+static void test_log_invalid_target_fd(void)\n+{\n+\tconst char *msg = \"Invalid target_fd.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts);\n+\n+\ttest_iter_link_create_log(-1, \u0026opts, 0, -EINVAL, msg);\n+}\n+\n+static void test_log_invalid_flags(void)\n+{\n+\tconst char *msg = \"Invalid flags.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .flags = 1,\n+\t);\n+\n+\ttest_iter_link_create_log(0, \u0026opts, 0, -EINVAL, msg);\n+}\n+\n+static void test_log_iter_info_only(void)\n+{\n+\tconst char *msg = \"iter_info and iter_info_len must be both set or both unset.\\n\";\n+\tunion bpf_iter_link_info info = {};\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .iter.info = \u0026info,\n+\t);\n+\n+\ttest_iter_link_create_log(0, \u0026opts, 0, -EINVAL, msg);\n+}\n+\n+static void test_log_iter_info_len_only(void)\n+{\n+\tconst char *msg = \"iter_info and iter_info_len must be both set or both unset.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .iter.len = sizeof(union bpf_iter_link_info),\n+\t);\n+\n+\ttest_iter_link_create_log(0, \u0026opts, 0, -EINVAL, msg);\n+}\n+\n+static void test_log_invalid_iter_info(void)\n+{\n+\tunsigned char info[sizeof(union bpf_iter_link_info) + 1] = {};\n+\tconst char *msg = \"Invalid iter_info.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .iter.info = (union bpf_iter_link_info *)info,\n+\t\t .iter.len = sizeof(info),\n+\t);\n+\n+\tinfo[sizeof(info) - 1] = 1;\n+\ttest_iter_link_create_log(0, \u0026opts, 0, -E2BIG, msg);\n+}\n+\n+static void test_log_invalid_iter_info_len(void)\n+{\n+\tconst char *msg = \"Invalid iter_info_len.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .iter.info = (union bpf_iter_link_info *)1,\n+\t\t .iter.len = sizeof(union bpf_iter_link_info),\n+\t);\n+\n+\ttest_iter_link_create_log(0, \u0026opts, 0, -EFAULT, msg);\n+}\n+\n+static void test_log_invalid_prog(void)\n+{\n+\tconst char *msg = \"The iter target does not support the bpf prog.\\n\";\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts);\n+\n+\ttest_iter_link_create_log(0, \u0026opts, BPF_F_SLEEPABLE, -EINVAL, msg);\n+}\n+\n+void test_iter_link_log(void)\n+{\n+\tif (test__start_subtest(\"invalid_target_fd\"))\n+\t\ttest_log_invalid_target_fd();\n+\tif (test__start_subtest(\"invalid_flags\"))\n+\t\ttest_log_invalid_flags();\n+\tif (test__start_subtest(\"iter_info_only\"))\n+\t\ttest_log_iter_info_only();\n+\tif (test__start_subtest(\"iter_info_len_only\"))\n+\t\ttest_log_iter_info_len_only();\n+\tif (test__start_subtest(\"invalid_iter_info\"))\n+\t\ttest_log_invalid_iter_info();\n+\tif (test__start_subtest(\"invalid_iter_info_len\"))\n+\t\ttest_log_invalid_iter_info_len();\n+\tif (test__start_subtest(\"invalid_prog\"))\n+\t\ttest_log_invalid_prog();\n+}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/tracing_link.c b/tools/testing/selftests/bpf/prog_tests/tracing_link.c\nnew file mode 100644\nindex 00000000000000..6f22a21be946aa\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/tracing_link.c\n@@ -0,0 +1,377 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003ctest_progs.h\u003e\n+#include \u003cbpf/btf.h\u003e\n+#include \"fentry_recursive.skel.h\"\n+#include \"priv_freplace_prog.skel.h\"\n+#include \"xdp_dummy.skel.h\"\n+#include \"kprobe_write_ctx.skel.h\"\n+#include \"tracing_multi_fail.skel.h\"\n+\n+static void test_fentry_link_create_log(int target_fd, __u32 target_btf_id, int cookie,\n+\t\t\t\t\tenum bpf_attach_type attach_type,\n+\t\t\t\t\tbool reattach, const char *msg)\n+{\n+\tstruct fentry_recursive *skel = NULL;\n+\tstruct xdp_dummy *target;\n+\tchar log_buf[128] = {};\n+\tint err, fd, prog_fd;\n+\tLIBBPF_OPTS(bpf_log_opts, log_opts,\n+\t\t .buf = log_buf,\n+\t\t .size = sizeof(log_buf),\n+\t\t .level = 1,\n+\t);\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .log_opts = \u0026log_opts,\n+\t\t .target_btf_id = target_btf_id,\n+\t\t .tracing.cookie = cookie,\n+\t);\n+\n+\ttarget = xdp_dummy__open_and_load();\n+\tif (!ASSERT_OK_PTR(target, \"xdp_dummy__open_and_load\"))\n+\t\treturn;\n+\n+\tskel = fentry_recursive__open();\n+\tif (!ASSERT_OK_PTR(skel, \"fentry_recursive__open\"))\n+\t\tgoto out;\n+\n+\terr = bpf_program__set_attach_target(skel-\u003eprogs.recursive_attach,\n+\t\t\t\t\t bpf_program__fd(target-\u003eprogs.xdp_dummy_prog),\n+\t\t\t\t\t \"xdp_dummy_prog\");\n+\tif (!ASSERT_OK(err, \"bpf_program__set_attach_target\"))\n+\t\tgoto out;\n+\n+\terr = fentry_recursive__load(skel);\n+\tif (!ASSERT_OK(err, \"fentry_recursive__load\"))\n+\t\tgoto out;\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.recursive_attach);\n+\tif (reattach) {\n+\t\t/* Consume the initial target saved when the program was loaded. */\n+\t\tfd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY, \u0026opts);\n+\t\tif (!ASSERT_GE(fd, 0, \"bpf_link_create first\"))\n+\t\t\tgoto out;\n+\n+\t\tclose(fd);\n+\t\tmemset(log_buf, 0, sizeof(log_buf));\n+\t\tlog_opts.true_size = 0;\n+\t}\n+\n+\tfd = bpf_link_create(prog_fd, target_fd, attach_type, \u0026opts);\n+\tif (!ASSERT_LT(fd, 0, \"bpf_link_create\")) {\n+\t\tclose(fd);\n+\t\tgoto out;\n+\t}\n+\n+\tASSERT_EQ(fd, -EINVAL, \"err\");\n+\tASSERT_STREQ(log_buf, msg, \"log_buf\");\n+\tASSERT_EQ(log_opts.true_size, strlen(msg) + 1, \"log_size\");\n+\n+out:\n+\tfentry_recursive__destroy(skel);\n+\txdp_dummy__destroy(target);\n+}\n+\n+static void test_log_invalid_attach_type(void)\n+{\n+\tconst char *msg = \"Invalid attach_type.\\n\";\n+\n+\ttest_fentry_link_create_log(0, 0, 0, BPF_XDP, false, msg);\n+}\n+\n+static void test_log_tgt_prog_fd_only(void)\n+{\n+\tconst char *msg = \"tgt_prog_fd and btf_id must be both set or both unset.\\n\";\n+\n+\ttest_fentry_link_create_log(-1, 0, 1, BPF_TRACE_FENTRY, false, msg);\n+}\n+\n+static void test_log_tgt_prog_fd_disallowed(void)\n+{\n+\tconst char *msg = \"tgt_prog_fd is only allowed for freplace prog.\\n\";\n+\n+\ttest_fentry_link_create_log(-1, 1, 0, BPF_TRACE_FENTRY, false, msg);\n+}\n+\n+static void test_log_invalid_attach_btf(void)\n+{\n+\tconst char *msg = \"Invalid attach_btf.\\n\";\n+\n+\ttest_fentry_link_create_log(0, 0, 1, BPF_TRACE_FENTRY, true, msg);\n+}\n+\n+static void test_freplace_link_create_log(int target_fd, __u32 target_btf_id, int err_exp,\n+\t\t\t\t\t bool reattach, const char *msg)\n+{\n+\tstruct priv_freplace_prog *skel = NULL;\n+\tchar log_buf[256] = {};\n+\tstruct xdp_dummy *xdp;\n+\tint err, fd, prog_fd;\n+\tLIBBPF_OPTS(bpf_log_opts, log_opts,\n+\t\t .buf = log_buf,\n+\t\t .size = sizeof(log_buf),\n+\t\t .level = 1,\n+\t);\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .log_opts = \u0026log_opts,\n+\t\t .target_btf_id = target_btf_id,\n+\t);\n+\n+\txdp = xdp_dummy__open_and_load();\n+\tif (!ASSERT_OK_PTR(xdp, \"xdp_dummy__open_and_load\"))\n+\t\treturn;\n+\n+\tskel = priv_freplace_prog__open();\n+\tif (!ASSERT_OK_PTR(skel, \"priv_freplace_prog__open\"))\n+\t\tgoto out;\n+\n+\terr = bpf_program__set_attach_target(skel-\u003eprogs.new_xdp_prog2,\n+\t\t\t\t\t bpf_program__fd(xdp-\u003eprogs.xdp_dummy_prog),\n+\t\t\t\t\t \"xdp_dummy_prog\");\n+\tif (!ASSERT_OK(err, \"bpf_program__set_attach_target\"))\n+\t\tgoto out;\n+\n+\terr = priv_freplace_prog__load(skel);\n+\tif (!ASSERT_OK(err, \"priv_freplace_prog__load\"))\n+\t\tgoto out;\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.new_xdp_prog2);\n+\tif (reattach) {\n+\t\t/* Consume the initial target saved when the program was loaded. */\n+\t\tfd = bpf_link_create(prog_fd, 0, 0, \u0026opts);\n+\t\tif (!ASSERT_GE(fd, 0, \"bpf_link_create first\"))\n+\t\t\tgoto out;\n+\n+\t\tclose(fd);\n+\t\tmemset(log_buf, 0, sizeof(log_buf));\n+\t\tlog_opts.true_size = 0;\n+\t}\n+\n+\tif (!target_fd \u0026\u0026 target_btf_id)\n+\t\ttarget_fd = bpf_program__fd(xdp-\u003eprogs.xdp_dummy_prog);\n+\n+\tfd = bpf_link_create(prog_fd, target_fd, 0, \u0026opts);\n+\tif (!ASSERT_LT(fd, 0, \"bpf_link_create\")) {\n+\t\tclose(fd);\n+\t\tgoto out;\n+\t}\n+\n+\tASSERT_EQ(fd, err_exp, \"err\");\n+\tASSERT_STREQ(log_buf, msg, \"log_buf\");\n+\tASSERT_EQ(log_opts.true_size, strlen(msg) + 1, \"log_size\");\n+\n+out:\n+\tpriv_freplace_prog__destroy(skel);\n+\txdp_dummy__destroy(xdp);\n+}\n+\n+static void test_log_invalid_target_fd(void)\n+{\n+\tconst char *msg = \"Invalid tgt_prog_fd.\\n\";\n+\n+\ttest_freplace_link_create_log(-1, 1, -EBADF, false, msg);\n+}\n+\n+static void test_log_reattach_without_target(void)\n+{\n+\tconst char *msg = \"Only allow re-attach for tracing and lsm progs.\\n\";\n+\n+\ttest_freplace_link_create_log(0, 0, -EINVAL, true, msg);\n+}\n+\n+static void test_log_invalid_target_btf_id(void)\n+{\n+\tconst char *msg = \"attach_btf_id 4294967295 is invalid\\n\";\n+\n+\ttest_freplace_link_create_log(0, ~0U, -EINVAL, false, msg);\n+}\n+\n+#ifdef __x86_64__\n+static void test_log_invalid_kprobe_write_ctx(void)\n+{\n+\tstruct kprobe_write_ctx *skel_kprobe, *skel_freplace = NULL;\n+\tstruct bpf_program *prog_kprobe, *prog_freplace;\n+\tconst char *msg = \"Invalid kprobe_write_ctx.\\n\";\n+\tint err, prog_fd, btf_id, fd;\n+\tchar log_buf[128] = {};\n+\tLIBBPF_OPTS(bpf_log_opts, log_opts,\n+\t\t .buf = log_buf,\n+\t\t .size = sizeof(log_buf),\n+\t\t .level = 1,\n+\t);\n+\tLIBBPF_OPTS(bpf_link_create_opts, link_opts,\n+\t\t .log_opts = \u0026log_opts,\n+\t);\n+\n+\tskel_kprobe = kprobe_write_ctx__open();\n+\tif (!ASSERT_OK_PTR(skel_kprobe, \"kprobe_write_ctx__open kprobe\"))\n+\t\treturn;\n+\n+\tprog_kprobe = skel_kprobe-\u003eprogs.kprobe_dummy;\n+\tbpf_program__set_autoload(prog_kprobe, true);\n+\n+\terr = kprobe_write_ctx__load(skel_kprobe);\n+\tif (!ASSERT_OK(err, \"kprobe_write_ctx__load kprobe\"))\n+\t\tgoto out;\n+\n+\tskel_freplace = kprobe_write_ctx__open();\n+\tif (!ASSERT_OK_PTR(skel_freplace, \"kprobe_write_ctx__open freplace\"))\n+\t\tgoto out;\n+\n+\tprog_freplace = skel_freplace-\u003eprogs.freplace_kprobe;\n+\tbpf_program__set_autoload(prog_freplace, true);\n+\n+\tprog_fd = bpf_program__fd(skel_kprobe-\u003eprogs.kprobe_write_ctx);\n+\tbpf_program__set_attach_target(prog_freplace, prog_fd, \"kprobe_write_ctx\");\n+\n+\terr = kprobe_write_ctx__load(skel_freplace);\n+\tif (!ASSERT_OK(err, \"kprobe_write_ctx__load freplace\"))\n+\t\tgoto out;\n+\n+\tprog_fd = bpf_program__fd(prog_kprobe);\n+\tbtf_id = btf__find_by_name_kind(bpf_object__btf(skel_kprobe-\u003eobj), \"kprobe_dummy\",\n+\t\t\t\t\tBTF_KIND_FUNC);\n+\tif (!ASSERT_GT(btf_id, 0, \"btf__find_by_name_kind\"))\n+\t\tgoto out;\n+\n+\tlink_opts.target_btf_id = btf_id;\n+\tfd = bpf_link_create(bpf_program__fd(prog_freplace), prog_fd, 0, \u0026link_opts);\n+\tif (!ASSERT_LT(fd, 0, \"bpf_link_create\")) {\n+\t\tclose(fd);\n+\t\tgoto out;\n+\t}\n+\n+\tASSERT_EQ(fd, -EINVAL, \"err\");\n+\tASSERT_STREQ(log_buf, msg, \"log_buf\");\n+\tASSERT_EQ(log_opts.true_size, strlen(msg) + 1, \"log_size\");\n+\n+out:\n+\tkprobe_write_ctx__destroy(skel_freplace);\n+\tkprobe_write_ctx__destroy(skel_kprobe);\n+}\n+#else\n+static void test_log_invalid_kprobe_write_ctx(void)\n+{\n+\ttest__skip();\n+}\n+#endif\n+\n+void test_tracing_link_log(void)\n+{\n+\tif (test__start_subtest(\"invalid_attach_type\"))\n+\t\ttest_log_invalid_attach_type();\n+\tif (test__start_subtest(\"tgt_prog_fd_only\"))\n+\t\ttest_log_tgt_prog_fd_only();\n+\tif (test__start_subtest(\"tgt_prog_fd_disallowed\"))\n+\t\ttest_log_tgt_prog_fd_disallowed();\n+\tif (test__start_subtest(\"invalid_attach_btf\"))\n+\t\ttest_log_invalid_attach_btf();\n+\tif (test__start_subtest(\"invalid_target_fd\"))\n+\t\ttest_log_invalid_target_fd();\n+\tif (test__start_subtest(\"reattach_without_target\"))\n+\t\ttest_log_reattach_without_target();\n+\tif (test__start_subtest(\"invalid_target_btf_id\"))\n+\t\ttest_log_invalid_target_btf_id();\n+\tif (test__start_subtest(\"invalid_kprobe_write_ctx\"))\n+\t\ttest_log_invalid_kprobe_write_ctx();\n+}\n+\n+static void test_tracing_multi_link_create_log(int target_fd, __u32 flags, const __u32 *ids,\n+\t\t\t\t\t __u32 cnt, int err_exp, const char *msg)\n+{\n+\tstruct tracing_multi_fail *skel;\n+\tchar log_buf[128] = {};\n+\tint err, fd, prog_fd;\n+\tLIBBPF_OPTS(bpf_log_opts, log_opts,\n+\t\t .buf = log_buf,\n+\t\t .size = sizeof(log_buf),\n+\t\t .level = 1,\n+\t);\n+\tLIBBPF_OPTS(bpf_link_create_opts, opts,\n+\t\t .log_opts = \u0026log_opts,\n+\t\t .flags = flags,\n+\t\t .tracing_multi.ids = ids,\n+\t\t .tracing_multi.cnt = cnt,\n+\t);\n+\n+\tskel = tracing_multi_fail__open();\n+\tif (!ASSERT_OK_PTR(skel, \"tracing_multi_fail__open\"))\n+\t\treturn;\n+\n+\tbpf_program__set_autoload(skel-\u003eprogs.test_fentry_s, false);\n+\terr = tracing_multi_fail__load(skel);\n+\tif (!ASSERT_OK(err, \"tracing_multi_fail__load\"))\n+\t\tgoto out;\n+\n+\tprog_fd = bpf_program__fd(skel-\u003eprogs.test_fentry);\n+\tfd = bpf_link_create(prog_fd, target_fd, BPF_TRACE_FENTRY_MULTI, \u0026opts);\n+\tif (!ASSERT_LT(fd, 0, \"bpf_link_create\")) {\n+\t\tclose(fd);\n+\t\tgoto out;\n+\t}\n+\n+\tASSERT_EQ(fd, err_exp, \"err\");\n+\tASSERT_STREQ(log_buf, msg, \"log_buf\");\n+\tASSERT_EQ(log_opts.true_size, strlen(msg) + 1, \"log_size\");\n+\n+out:\n+\ttracing_multi_fail__destroy(skel);\n+}\n+\n+static void test_multi_log_zero_count(void)\n+{\n+\tconst char *msg = \"tracing_multi.cnt cannot be zero.\\n\";\n+\t__u32 id = 0;\n+\n+\ttest_tracing_multi_link_create_log(0, 0, \u0026id, 0, -EINVAL, msg);\n+}\n+\n+static void test_multi_log_missing_ids(void)\n+{\n+\tconst char *msg = \"tracing_multi.ids must be set.\\n\";\n+\n+\ttest_tracing_multi_link_create_log(0, 0, NULL, 1, -EINVAL, msg);\n+}\n+\n+static void test_multi_log_excessive_count(void)\n+{\n+\tconst char *msg = \"tracing_multi.cnt is too large.\\n\";\n+\t__u32 id = 0;\n+\n+\ttest_tracing_multi_link_create_log(0, 0, \u0026id, INT_MAX, -E2BIG, msg);\n+}\n+\n+static void test_multi_log_invalid_flags(void)\n+{\n+\tconst char *msg = \"Invalid flags.\\n\";\n+\t__u32 id = 0;\n+\n+\ttest_tracing_multi_link_create_log(0, 1, \u0026id, 1, -EINVAL, msg);\n+}\n+\n+static void test_multi_log_invalid_target_fd(void)\n+{\n+\tconst char *msg = \"Invalid target_fd.\\n\";\n+\t__u32 id = 0;\n+\n+\ttest_tracing_multi_link_create_log(-1, 0, \u0026id, 1, -EINVAL, msg);\n+}\n+\n+void test_tracing_multi_link_log(void)\n+{\n+#ifndef __x86_64__\n+\ttest__skip();\n+\treturn;\n+#endif\n+\n+\tif (test__start_subtest(\"zero_count\"))\n+\t\ttest_multi_log_zero_count();\n+\tif (test__start_subtest(\"missing_ids\"))\n+\t\ttest_multi_log_missing_ids();\n+\tif (test__start_subtest(\"excessive_count\"))\n+\t\ttest_multi_log_excessive_count();\n+\tif (test__start_subtest(\"invalid_flags\"))\n+\t\ttest_multi_log_invalid_flags();\n+\tif (test__start_subtest(\"invalid_target_fd\"))\n+\t\ttest_multi_log_invalid_target_fd();\n+}\n+\n"
} |
| 2/1 | 2026/11/12 13:12 | agent | patch-evaluator |
5mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch series only updates user-space tooling/selftests (tools/lib/bpf and tools/testing/selftests) and adds purely decorative diagnostic verifier logging (bpf_log) to existing failure paths across BPF link attachment functions (cgroup_bpf_link_attach, bpf_tracing_prog_attach, bpf_iter_link_attach, and bpf_tracing_multi_attach). No kernel data structures, control flow, error returns, or runtime assertions are altered.",
"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 b80013f59c32cfe5682c551a62b0a9a4b3f52bba
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Nov 12 13:12:00 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 02ef7f899b3dee..ddcdd136fd495f 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -4,6 +4,7 @@
#include <linux/bpf.h>
#include <linux/bpf-cgroup-defs.h>
+#include <linux/bpf_verifier.h>
#include <linux/errno.h>
#include <linux/jump_label.h>
#include <linux/percpu.h>
@@ -425,7 +426,8 @@ int cgroup_bpf_prog_attach(const union bpf_attr *attr,
enum bpf_prog_type ptype, struct bpf_prog *prog);
int cgroup_bpf_prog_detach(const union bpf_attr *attr,
enum bpf_prog_type ptype);
-int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
+int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log);
int cgroup_bpf_prog_query(const union bpf_attr *attr,
union bpf_attr __user *uattr, u32 uattr_size);
@@ -452,7 +454,8 @@ static inline int cgroup_bpf_prog_detach(const union bpf_attr *attr,
}
static inline int cgroup_bpf_link_attach(const union bpf_attr *attr,
- struct bpf_prog *prog)
+ struct bpf_prog *prog,
+ struct bpf_verifier_log *log)
{
return -EINVAL;
}
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 520fd72e21fd07..7ff256a5d98b62 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3276,7 +3276,8 @@ void bpf_iter_unreg_target(const struct bpf_iter_reg *reg_info);
int bpf_iter_prog_supported(struct bpf_prog *prog);
const struct bpf_func_proto *
bpf_iter_get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog);
-int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_prog *prog);
+int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log);
int bpf_iter_new_fd(struct bpf_link *link);
bool bpf_link_is_iter(struct bpf_link *link);
struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 321f2f3a6c8e8f..bb825ea5d09c44 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -16,6 +16,7 @@ struct tracer;
struct dentry;
struct bpf_prog;
union bpf_attr;
+struct bpf_verifier_log;
/* Used for event string fields when they are NULL */
#define EVENT_NULL_STR "(null)"
@@ -796,7 +797,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
unsigned long *missed);
int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr);
+int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
+ struct bpf_verifier_log *log);
#else
static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
{
@@ -855,7 +857,8 @@ bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
return -EOPNOTSUPP;
}
static inline int
-bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
+bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
+ struct bpf_verifier_log *log)
{
return -EOPNOTSUPP;
}
diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index f0b29a17093579..dfefa5579e0335 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -5,6 +5,7 @@
#include <linux/anon_inodes.h>
#include <linux/filter.h>
#include <linux/bpf.h>
+#include <linux/bpf_verifier.h>
#include <linux/rcupdate_trace.h>
struct bpf_iter_target_info {
@@ -528,7 +529,7 @@ bool bpf_link_is_iter(struct bpf_link *link)
}
int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
- struct bpf_prog *prog)
+ struct bpf_prog *prog, struct bpf_verifier_log *log)
{
struct bpf_iter_target_info *tinfo = NULL, *iter;
struct bpf_link_primer link_primer;
@@ -538,24 +539,36 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
bpfptr_t ulinfo;
int err;
- if (attr->link_create.target_fd || attr->link_create.flags)
+ if (attr->link_create.target_fd) {
+ bpf_log(log, "Invalid target_fd.\n");
+ return -EINVAL;
+ }
+ if (attr->link_create.flags) {
+ bpf_log(log, "Invalid flags.\n");
return -EINVAL;
+ }
memset(&linfo, 0, sizeof(union bpf_iter_link_info));
ulinfo = make_bpfptr(attr->link_create.iter_info, uattr.is_kernel);
linfo_len = attr->link_create.iter_info_len;
- if (bpfptr_is_null(ulinfo) ^ !linfo_len)
+ if (bpfptr_is_null(ulinfo) ^ !linfo_len) {
+ bpf_log(log, "iter_info and iter_info_len must be both set or both unset.\n");
return -EINVAL;
+ }
if (!bpfptr_is_null(ulinfo)) {
err = bpf_check_uarg_tail_zero(ulinfo, sizeof(linfo),
linfo_len);
- if (err)
+ if (err) {
+ bpf_log(log, "Invalid iter_info.\n");
return err;
+ }
linfo_len = min_t(u32, linfo_len, sizeof(linfo));
- if (copy_from_bpfptr(&linfo, ulinfo, linfo_len))
+ if (copy_from_bpfptr(&linfo, ulinfo, linfo_len)) {
+ bpf_log(log, "Invalid iter_info_len.\n");
return -EFAULT;
+ }
}
prog_btf_id = prog->aux->attach_btf_id;
@@ -570,8 +583,10 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
if (!tinfo)
return -ENOENT;
- if (!bpf_iter_target_support_prog(tinfo, prog))
+ if (!bpf_iter_target_support_prog(tinfo, prog)) {
+ bpf_log(log, "The iter target does not support the bpf prog.\n");
return -EINVAL;
+ }
link = kzalloc_obj(*link, GFP_USER | __GFP_NOWARN);
if (!link)
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 57a785241d42fb..a4d49c4df712b4 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -854,7 +854,8 @@ static struct bpf_prog *bpf_get_anchor_prog(u32 flags, u32 id_or_fd)
}
static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_prog *prog,
- struct bpf_cgroup_link *link, u32 flags, u32 id_or_fd)
+ struct bpf_cgroup_link *link, u32 flags, u32 id_or_fd,
+ struct bpf_verifier_log *log)
{
bool is_link = flags & BPF_F_LINK, is_id = flags & BPF_F_ID;
struct bpf_prog_list *pltmp, *pl = ERR_PTR(-EINVAL);
@@ -867,20 +868,30 @@ static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_
is_after = flags & BPF_F_AFTER;
if (is_link || is_id || id_or_fd) {
/* flags must have either BPF_F_BEFORE or BPF_F_AFTER */
- if (is_before == is_after)
+ if (is_before == is_after) {
+ bpf_log(log, "Specify exactly one of BPF_F_BEFORE or BPF_F_AFTER.\n");
return ERR_PTR(-EINVAL);
- if ((is_link && !link) || (!is_link && !prog))
+ }
+ if (is_link && !link)
+ return ERR_PTR(-EINVAL);
+ if (!is_link && !prog) {
+ bpf_log(log, "BPF_F_LINK is required for relative link attachment.\n");
return ERR_PTR(-EINVAL);
+ }
} else if (!hlist_empty(progs)) {
/* flags cannot have both BPF_F_BEFORE and BPF_F_AFTER */
- if (is_before && is_after)
+ if (is_before && is_after) {
+ bpf_log(log, "BPF_F_BEFORE and BPF_F_AFTER are mutually exclusive.\n");
return ERR_PTR(-EINVAL);
+ }
}
if (is_link) {
anchor_link = bpf_get_anchor_link(flags, id_or_fd);
- if (IS_ERR(anchor_link))
+ if (IS_ERR(anchor_link)) {
+ bpf_log(log, "Invalid relative link %s.\n", is_id ? "ID" : "FD");
return ERR_CAST(anchor_link);
+ }
} else if (is_id || id_or_fd) {
anchor_prog = bpf_get_anchor_prog(flags, id_or_fd);
if (IS_ERR(anchor_prog))
@@ -905,13 +916,16 @@ static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_
hlist_for_each_entry(pltmp, progs, node) {
if ((anchor_prog && anchor_prog == pltmp->prog) ||
(anchor_link && anchor_link == &pltmp->link->link)) {
- if (!!(pltmp->flags & BPF_F_PREORDER) != preorder)
+ if (!!(pltmp->flags & BPF_F_PREORDER) != preorder) {
+ bpf_log(log, "Relative attachment BPF_F_PREORDER mismatch.\n");
goto out;
+ }
pl = pltmp;
goto out;
}
}
+ bpf_log(log, "Relative attachment not found in target cgroup.\n");
pl = ERR_PTR(-ENOENT);
out:
if (anchor_link)
@@ -923,11 +937,11 @@ static struct bpf_prog_list *get_prog_list(struct hlist_head *progs, struct bpf_
static int insert_pl_to_hlist(struct bpf_prog_list *pl, struct hlist_head *progs,
struct bpf_prog *prog, struct bpf_cgroup_link *link,
- u32 flags, u32 id_or_fd)
+ u32 flags, u32 id_or_fd, struct bpf_verifier_log *log)
{
struct bpf_prog_list *pltmp;
- pltmp = get_prog_list(progs, prog, link, flags, id_or_fd);
+ pltmp = get_prog_list(progs, prog, link, flags, id_or_fd, log);
if (IS_ERR(pltmp))
return PTR_ERR(pltmp);
@@ -952,6 +966,7 @@ static int insert_pl_to_hlist(struct bpf_prog_list *pl, struct hlist_head *progs
* @flags: Option flags
* @id_or_fd: Relative prog id or fd
* @revision: bpf_prog_list revision
+ * @log: Optional log for attachment errors
*
* Exactly one of @prog or @link can be non-null.
* Must be called with cgroup_mutex held.
@@ -960,7 +975,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
struct bpf_prog *prog, struct bpf_prog *replace_prog,
struct bpf_cgroup_link *link,
enum bpf_attach_type type, u32 flags, u32 id_or_fd,
- u64 revision)
+ u64 revision, struct bpf_verifier_log *log)
{
u32 saved_flags = (flags & (BPF_F_ALLOW_OVERRIDE | BPF_F_ALLOW_MULTI));
struct bpf_prog *old_prog = NULL;
@@ -991,23 +1006,33 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
atype = bpf_cgroup_atype_find(type, new_prog->aux->attach_btf_id);
if (atype < 0)
return -EINVAL;
- if (revision && revision != cgrp->bpf.revisions[atype])
+ if (revision && revision != cgrp->bpf.revisions[atype]) {
+ bpf_log(log, "Cgroup revision mismatch: expected %llu, actual %llu.\n",
+ revision, cgrp->bpf.revisions[atype]);
return -ESTALE;
+ }
progs = &cgrp->bpf.progs[atype];
- if (!hierarchy_allows_attach(cgrp, atype))
+ if (!hierarchy_allows_attach(cgrp, atype)) {
+ bpf_log(log, "Cgroup hierarchy does not allow attachment.\n");
return -EPERM;
+ }
- if (!hlist_empty(progs) && cgrp->bpf.flags[atype] != saved_flags)
+ if (!hlist_empty(progs) && cgrp->bpf.flags[atype] != saved_flags) {
/* Disallow attaching non-overridable on top
* of existing overridable in this cgroup.
* Disallow attaching multi-prog if overridable or none
*/
+ bpf_log(log, "Attachment flags conflict with existing flags.\n");
return -EPERM;
+ }
- if (prog_list_length(progs, NULL) >= BPF_CGROUP_MAX_PROGS)
+ if (prog_list_length(progs, NULL) >= BPF_CGROUP_MAX_PROGS) {
+ bpf_log(log, "Too many programs attached to cgroup (limit %u).\n",
+ BPF_CGROUP_MAX_PROGS);
return -E2BIG;
+ }
pl = find_attach_entry(progs, prog, link, replace_prog,
flags & BPF_F_ALLOW_MULTI);
@@ -1029,7 +1054,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
return -ENOMEM;
}
- err = insert_pl_to_hlist(pl, progs, prog, link, flags, id_or_fd);
+ err = insert_pl_to_hlist(pl, progs, prog, link, flags, id_or_fd, log);
if (err) {
kfree(pl);
bpf_cgroup_storages_free(new_storage);
@@ -1089,13 +1114,14 @@ static int cgroup_bpf_attach(struct cgroup *cgrp,
struct bpf_prog *prog, struct bpf_prog *replace_prog,
struct bpf_cgroup_link *link,
enum bpf_attach_type type,
- u32 flags, u32 id_or_fd, u64 revision)
+ u32 flags, u32 id_or_fd, u64 revision,
+ struct bpf_verifier_log *log)
{
int ret;
cgroup_lock();
ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags,
- id_or_fd, revision);
+ id_or_fd, revision, log);
cgroup_unlock();
return ret;
}
@@ -1572,7 +1598,7 @@ int cgroup_bpf_prog_attach(const union bpf_attr *attr,
ret = cgroup_bpf_attach(cgrp, prog, replace_prog, NULL,
attr->attach_type, attr->attach_flags,
- attr->relative_fd, attr->expected_revision);
+ attr->relative_fd, attr->expected_revision, NULL);
if (replace_prog)
bpf_prog_put(replace_prog);
@@ -1702,19 +1728,24 @@ static const struct bpf_link_ops bpf_cgroup_link_lops = {
BPF_F_PREORDER | \
BPF_F_LINK)
-int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
+int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog,
+ struct bpf_verifier_log *log)
{
struct bpf_link_primer link_primer;
struct bpf_cgroup_link *link;
struct cgroup *cgrp;
int err;
- if (attr->link_create.flags & (~BPF_F_LINK_ATTACH_MASK))
+ if (attr->link_create.flags & (~BPF_F_LINK_ATTACH_MASK)) {
+ bpf_log(log, "Invalid flags.\n");
return -EINVAL;
+ }
cgrp = cgroup_get_from_fd(attr->link_create.target_fd);
- if (IS_ERR(cgrp))
+ if (IS_ERR(cgrp)) {
+ bpf_log(log, "Invalid target_fd.\n");
return PTR_ERR(cgrp);
+ }
link = kzalloc_obj(*link, GFP_USER);
if (!link) {
@@ -1734,7 +1765,7 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
err = cgroup_bpf_attach(cgrp, NULL, NULL, link,
link->link.attach_type, BPF_F_ALLOW_MULTI | attr->link_create.flags,
attr->link_create.cgroup.relative_fd,
- attr->link_create.cgroup.expected_revision);
+ attr->link_create.cgroup.expected_revision, log);
if (err) {
bpf_link_cleanup(&link_primer);
goto out_put_cgroup;
@@ -3184,7 +3215,8 @@ int cgroup_bpf_struct_ops_attach(struct bpf_map *map, const union bpf_attr *attr
cgrp->bpf.flags[atype] = BPF_F_ALLOW_MULTI;
err = insert_pl_to_hlist(pl, progs, NULL, link,
- flags | BPF_F_ALLOW_MULTI, attr->link_create.cgroup.relative_fd);
+ flags | BPF_F_ALLOW_MULTI,
+ attr->link_create.cgroup.relative_fd, NULL);
if (err)
goto unlock;
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 9004f2673ccf96..43417824d85109 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -3674,7 +3674,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
int tgt_prog_fd,
u32 btf_id,
u64 bpf_cookie,
- enum bpf_attach_type attach_type)
+ enum bpf_attach_type attach_type,
+ struct bpf_verifier_log *log)
{
struct bpf_link_primer link_primer;
struct bpf_prog *tgt_prog = NULL;
@@ -3711,6 +3712,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
}
if (!!tgt_prog_fd != !!btf_id) {
+ bpf_log(log, "tgt_prog_fd and btf_id must be both set or both unset.\n");
err = -EINVAL;
goto out_put_prog;
}
@@ -3723,12 +3725,14 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
* attach_tracing_prog flag is set.
*/
if (prog->type != BPF_PROG_TYPE_EXT) {
+ bpf_log(log, "tgt_prog_fd is only allowed for freplace prog.\n");
err = -EINVAL;
goto out_put_prog;
}
tgt_prog = bpf_prog_get(tgt_prog_fd);
if (IS_ERR(tgt_prog)) {
+ bpf_log(log, "Invalid tgt_prog_fd.\n");
err = PTR_ERR(tgt_prog);
tgt_prog = NULL;
goto out_put_prog;
@@ -3783,11 +3787,13 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
*/
if (prog->type != BPF_PROG_TYPE_TRACING &&
prog->type != BPF_PROG_TYPE_LSM) {
+ bpf_log(log, "Only allow re-attach for tracing and lsm progs.\n");
err = -EINVAL;
goto out_unlock;
}
/* We can allow re-attach only if we have valid attach_btf. */
if (!prog->aux->attach_btf) {
+ bpf_log(log, "Invalid attach_btf.\n");
err = -EINVAL;
goto out_unlock;
}
@@ -3803,7 +3809,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
*/
struct bpf_attach_target_info tgt_info = {};
- err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
+ err = bpf_check_attach_target(log, prog, tgt_prog, btf_id,
&tgt_info);
if (err)
goto out_unlock;
@@ -3843,6 +3849,7 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
*/
if (prog->type == BPF_PROG_TYPE_EXT &&
prog->aux->kprobe_write_ctx != tgt_prog->aux->kprobe_write_ctx) {
+ bpf_log(log, "Invalid kprobe_write_ctx.\n");
err = -EINVAL;
goto out_unlock;
}
@@ -4374,7 +4381,7 @@ static int bpf_raw_tp_link_attach(struct bpf_prog *prog,
tp_name = prog->aux->attach_func_name;
break;
}
- return bpf_tracing_prog_attach(prog, 0, 0, 0, attach_type);
+ return bpf_tracing_prog_attach(prog, 0, 0, 0, attach_type, NULL);
case BPF_PROG_TYPE_RAW_TRACEPOINT:
case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
if (strncpy_from_user(buf, user_tp_name, sizeof(buf) - 1) < 0)
@@ -5900,18 +5907,20 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a
case BPF_PROG_TYPE_CGROUP_DEVICE:
case BPF_PROG_TYPE_CGROUP_SYSCTL:
case BPF_PROG_TYPE_CGROUP_SOCKOPT:
- ret = cgroup_bpf_link_attach(attr, prog);
+ ret = cgroup_bpf_link_attach(attr, prog, log);
break;
case BPF_PROG_TYPE_EXT:
ret = bpf_tracing_prog_attach(prog,
attr->link_create.target_fd,
attr->link_create.target_btf_id,
attr->link_create.tracing.cookie,
- attr->link_create.attach_type);
+ attr->link_create.attach_type,
+ log);
break;
case BPF_PROG_TYPE_LSM:
case BPF_PROG_TYPE_TRACING:
if (attr->link_create.attach_type != prog->expected_attach_type) {
+ bpf_log(log, "Invalid attach_type.\n");
ret = -EINVAL;
goto out;
}
@@ -5919,17 +5928,18 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a
ret = bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.cookie,
attr->link_create.attach_type);
else if (prog->expected_attach_type == BPF_TRACE_ITER)
- ret = bpf_iter_link_attach(attr, uattr, prog);
+ ret = bpf_iter_link_attach(attr, uattr, prog, log);
else if (prog->expected_attach_type == BPF_LSM_CGROUP)
- ret = cgroup_bpf_link_attach(attr, prog);
+ ret = cgroup_bpf_link_attach(attr, prog, log);
else if (is_tracing_multi(prog->expected_attach_type))
- ret = bpf_tracing_multi_attach(prog, attr);
+ ret = bpf_tracing_multi_attach(prog, attr, log);
else
ret = bpf_tracing_prog_attach(prog,
attr->link_create.target_fd,
attr->link_create.target_btf_id,
attr->link_create.tracing.cookie,
- attr->link_create.attach_type);
+ attr->link_create.attach_type,
+ log);
break;
case BPF_PROG_TYPE_FLOW_DISSECTOR:
case BPF_PROG_TYPE_SK_LOOKUP:
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2aec56d7f3d3ef..352a1cd0c863a1 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3861,7 +3861,8 @@ static int check_dup_ids(u32 *ids, u64 *cookies, u32 cnt)
return err;
}
-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
+int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
+ struct bpf_verifier_log *log)
{
struct bpf_tracing_multi_link *link = NULL;
struct bpf_tramp_node *fexits = NULL;
@@ -3875,12 +3876,26 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
uids = u64_to_user_ptr(attr->link_create.tracing_multi.ids);
cnt = attr->link_create.tracing_multi.cnt;
- if (!cnt || !uids)
+ if (!cnt) {
+ bpf_log(log, "tracing_multi.cnt cannot be zero.\n");
return -EINVAL;
- if (cnt > MAX_TRACING_MULTI_CNT)
+ }
+ if (!uids) {
+ bpf_log(log, "tracing_multi.ids must be set.\n");
+ return -EINVAL;
+ }
+ if (cnt > MAX_TRACING_MULTI_CNT) {
+ bpf_log(log, "tracing_multi.cnt is too large.\n");
return -E2BIG;
- if (attr->link_create.flags || attr->link_create.target_fd)
+ }
+ if (attr->link_create.flags) {
+ bpf_log(log, "Invalid flags.\n");
return -EINVAL;
+ }
+ if (attr->link_create.target_fd) {
+ bpf_log(log, "Invalid target_fd.\n");
+ return -EINVAL;
+ }
ids = kvmalloc_objs(*ids, cnt);
if (!ids)
@@ -3951,7 +3966,8 @@ int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
#else
-int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr)
+int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr,
+ struct bpf_verifier_log *log)
{
return -EOPNOTSUPP;
}
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 38dcb31e8c0ed1..174a8bfaf66382 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -808,11 +808,6 @@ int bpf_link_create(int prog_fd, int target_fd,
if (iter_info_len && attach_type != BPF_TRACE_ITER)
return libbpf_err(-EINVAL);
- if (iter_info_len)
- iter_info = OPTS_GET(opts, iter_info, (void *)0);
- else
- log_opts = OPTS_GET(opts, log_opts, (void *)0);
-
/* validate we don't have unexpected combinations of non-zero fields */
if (iter_info_len || target_btf_id) {
if (iter_info_len && target_btf_id)
@@ -821,6 +816,16 @@ int bpf_link_create(int prog_fd, int target_fd,
return libbpf_err(-EINVAL);
}
+ if (iter_info_len) {
+ if (OPTS_GET(opts, iter.len, 0))
+ return libbpf_err(-EINVAL);
+ iter_info = OPTS_GET(opts, iter_info, (void *)0);
+ } else {
+ log_opts = OPTS_GET(opts, log_opts, (void *)0);
+ iter_info = OPTS_GET(opts, iter.info, (void *)0);
+ iter_info_len = OPTS_GET(opts, iter.len, 0);
+ }
+
memset(&attr, 0, attr_sz);
attr.link_create.prog_fd = prog_fd;
attr.link_create.target_fd = target_fd;
@@ -970,7 +975,7 @@ int bpf_link_create(int prog_fd, int target_fd,
return libbpf_err(-EINVAL);
break;
default:
- if (!OPTS_ZEROED(opts, iter_info_len))
+ if (!OPTS_ZEROED(opts, log_opts))
return libbpf_err(-EINVAL);
break;
}
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index fe3b7fd8512bdb..2ac143fd1102ed 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -422,6 +422,10 @@ union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */
struct bpf_link_create_opts {
size_t sz; /* size of this struct for forward/backward compatibility */
__u32 flags;
+ /*
+ * iter_info and iter_info_len are deprecated, use iter.info and
+ * iter.len instead.
+ */
union {
union bpf_iter_link_info *iter_info;
struct bpf_log_opts *log_opts;
@@ -478,6 +482,10 @@ struct bpf_link_create_opts {
const __u64 *cookies;
__u32 cnt;
} tracing_multi;
+ struct {
+ union bpf_iter_link_info *info;
+ __u32 len;
+ } iter;
};
size_t :0;
};
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_link.c b/tools/testing/selftests/bpf/prog_tests/cgroup_link.c
index 15093a69510eba..5a27d3a6a26c77 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_link.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_link.c
@@ -253,3 +253,327 @@ void serial_test_cgroup_link(void)
}
cleanup_cgroup_environment();
}
+
+static void check_cgroup_link_create_log(int prog_fd, int target_fd,
+ struct bpf_link_create_opts *opts,
+ int err_exp, const char *msg)
+{
+ char log_buf[128] = {};
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+ int fd;
+
+ opts->log_opts = &log_opts;
+ fd = bpf_link_create(prog_fd, target_fd, BPF_CGROUP_INET_EGRESS, opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ return;
+ }
+
+ ASSERT_EQ(fd, err_exp, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+}
+
+static void test_cgroup_link_create_log(int target_fd, __u32 flags, int err_exp, const char *msg)
+{
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = flags,
+ );
+ struct test_cgroup_link *skel;
+
+ skel = test_cgroup_link__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "test_cgroup_link__open_and_load"))
+ return;
+
+ check_cgroup_link_create_log(bpf_program__fd(skel->progs.egress), target_fd, &opts,
+ err_exp, msg);
+
+ test_cgroup_link__destroy(skel);
+}
+
+static void test_log_invalid_flags(void)
+{
+ const char *msg = "Invalid flags.\n";
+
+ test_cgroup_link_create_log(-1, BPF_F_ALLOW_OVERRIDE, -EINVAL, msg);
+}
+
+static void test_log_invalid_target_fd(void)
+{
+ const char *msg = "Invalid target_fd.\n";
+
+ test_cgroup_link_create_log(-1, 0, -EBADF, msg);
+}
+
+static void test_log_cgroup_attach(struct bpf_link_create_opts *opts,
+ int err_exp, const char *msg)
+{
+ struct test_cgroup_link *skel;
+ int cg;
+
+ cg = test__join_cgroup("/cgroup_link_log_attach");
+ if (!ASSERT_GE(cg, 0, "join_cgroup"))
+ return;
+
+ skel = test_cgroup_link__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "test_cgroup_link__open_and_load"))
+ goto out;
+
+ check_cgroup_link_create_log(bpf_program__fd(skel->progs.egress), cg, opts, err_exp, msg);
+ test_cgroup_link__destroy(skel);
+
+out:
+ close(cg);
+}
+
+static void test_log_relative_without_order(void)
+{
+ const char *msg = "Specify exactly one of BPF_F_BEFORE or BPF_F_AFTER.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = BPF_F_LINK,
+ );
+
+ test_log_cgroup_attach(&opts, -EINVAL, msg);
+}
+
+static void test_log_relative_both_orders(void)
+{
+ const char *msg = "Specify exactly one of BPF_F_BEFORE or BPF_F_AFTER.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = BPF_F_LINK | BPF_F_BEFORE | BPF_F_AFTER,
+ );
+
+ test_log_cgroup_attach(&opts, -EINVAL, msg);
+}
+
+static void test_log_relative_type_mismatch(void)
+{
+ const char *msg = "BPF_F_LINK is required for relative link attachment.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = BPF_F_BEFORE,
+ .cgroup.relative_fd = -1,
+ );
+
+ test_log_cgroup_attach(&opts, -EINVAL, msg);
+}
+
+static void test_log_invalid_relative_link_fd(void)
+{
+ const char *msg = "Invalid relative link FD.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = BPF_F_LINK | BPF_F_BEFORE,
+ .cgroup.relative_fd = -1,
+ );
+
+ test_log_cgroup_attach(&opts, -EBADF, msg);
+}
+
+static void test_log_invalid_relative_link_id(void)
+{
+ const char *msg = "Invalid relative link ID.\n";
+ /* Link ID zero cannot identify a link. */
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = BPF_F_LINK | BPF_F_ID | BPF_F_BEFORE,
+ );
+
+ test_log_cgroup_attach(&opts, -ENOENT, msg);
+}
+
+static void test_log_relative_anchor(__u32 flags, bool other_cgroup, int err_exp, const char *msg)
+{
+ int cg, other_cg = -1, anchor_fd = -1, prog_fd;
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = flags,
+ );
+ struct test_cgroup_link *skel;
+
+ cg = test__join_cgroup("/cgroup_link_log_relative");
+ if (!ASSERT_GE(cg, 0, "join_cgroup"))
+ return;
+
+ if (other_cgroup) {
+ other_cg = test__join_cgroup("/cgroup_link_log_other");
+ if (!ASSERT_GE(other_cg, 0, "join_cgroup other"))
+ goto cleanup;
+ }
+
+ skel = test_cgroup_link__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "test_cgroup_link__open_and_load"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(skel->progs.egress);
+ anchor_fd = bpf_link_create(prog_fd, cg, BPF_CGROUP_INET_EGRESS, NULL);
+ if (!ASSERT_GE(anchor_fd, 0, "bpf_link_create"))
+ goto destroy;
+
+ if (flags & BPF_F_LINK)
+ opts.cgroup.relative_fd = anchor_fd;
+ check_cgroup_link_create_log(prog_fd, other_cgroup ? other_cg : cg, &opts, err_exp, msg);
+
+ close(anchor_fd);
+
+destroy:
+ test_cgroup_link__destroy(skel);
+cleanup:
+ if (other_cg >= 0)
+ close(other_cg);
+ close(cg);
+}
+
+static void test_log_both_orders(void)
+{
+ const char *msg = "BPF_F_BEFORE and BPF_F_AFTER are mutually exclusive.\n";
+
+ test_log_relative_anchor(BPF_F_BEFORE | BPF_F_AFTER, false, -EINVAL, msg);
+}
+
+static void test_log_relative_preorder_mismatch(void)
+{
+ const char *msg = "Relative attachment BPF_F_PREORDER mismatch.\n";
+
+ test_log_relative_anchor(BPF_F_LINK | BPF_F_BEFORE | BPF_F_PREORDER, false, -EINVAL, msg);
+}
+
+static void test_log_relative_not_in_cgroup(void)
+{
+ const char *msg = "Relative attachment not found in target cgroup.\n";
+
+ test_log_relative_anchor(BPF_F_LINK | BPF_F_BEFORE, true, -ENOENT, msg);
+}
+
+static void test_log_revision_mismatch(void)
+{
+ const char *msg = "Cgroup revision mismatch: expected 2, actual 1.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .cgroup.expected_revision = 2,
+ );
+
+ test_log_cgroup_attach(&opts, -ESTALE, msg);
+}
+
+static void test_log_exclusive_attach(bool child, const char *msg)
+{
+ LIBBPF_OPTS(bpf_link_create_opts, opts);
+ int cg, child_cg = -1, prog_fd, err;
+ struct test_cgroup_link *skel;
+
+ cg = test__join_cgroup("/cgroup_link_log_exclusive");
+ if (!ASSERT_GE(cg, 0, "join_cgroup"))
+ return;
+
+ if (child) {
+ child_cg = test__join_cgroup("/cgroup_link_log_exclusive/child");
+ if (!ASSERT_GE(child_cg, 0, "join_child_cgroup"))
+ goto cleanup;
+ }
+
+ skel = test_cgroup_link__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "test_cgroup_link__open_and_load"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(skel->progs.egress);
+
+ err = bpf_prog_attach(prog_fd, cg, BPF_CGROUP_INET_EGRESS, 0);
+ if (!ASSERT_OK(err, "bpf_prog_attach"))
+ goto destroy;
+
+ check_cgroup_link_create_log(prog_fd, child ? child_cg : cg, &opts, -EPERM, msg);
+
+ err = bpf_prog_detach2(prog_fd, cg, BPF_CGROUP_INET_EGRESS);
+ ASSERT_OK(err, "bpf_prog_detach2");
+
+destroy:
+ test_cgroup_link__destroy(skel);
+cleanup:
+ if (child_cg >= 0)
+ close(child_cg);
+ close(cg);
+}
+
+static void test_log_attachment_flags_conflict(void)
+{
+ const char *msg = "Attachment flags conflict with existing flags.\n";
+
+ test_log_exclusive_attach(false, msg);
+}
+
+static void test_log_hierarchy_disallows_attach(void)
+{
+ const char *msg = "Cgroup hierarchy does not allow attachment.\n";
+
+ test_log_exclusive_attach(true, msg);
+}
+
+#define BPF_CGROUP_MAX_PROGS 64
+
+static void test_log_too_many_programs(void)
+{
+ const char *msg = "Too many programs attached to cgroup (limit 64).\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts);
+ int cg, prog_fd, err, i, nr_links = 0;
+ int link_fds[BPF_CGROUP_MAX_PROGS];
+ struct test_cgroup_link *skel;
+
+ cg = test__join_cgroup("/cgroup_link_log_limit");
+ if (!ASSERT_GE(cg, 0, "join_cgroup"))
+ return;
+
+ skel = test_cgroup_link__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "test_cgroup_link__open_and_load"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(skel->progs.egress);
+
+ for (i = 0; i < ARRAY_SIZE(link_fds); i++) {
+ err = bpf_link_create(prog_fd, cg, BPF_CGROUP_INET_EGRESS, NULL);
+ if (!ASSERT_GE(err, 0, "bpf_link_create"))
+ goto destroy;
+
+ link_fds[nr_links++] = err;
+ }
+
+ check_cgroup_link_create_log(prog_fd, cg, &opts, -E2BIG, msg);
+
+destroy:
+ for (i = 0; i < nr_links; i++)
+ close(link_fds[i]);
+ test_cgroup_link__destroy(skel);
+cleanup:
+ close(cg);
+}
+
+void test_cgroup_link_log(void)
+{
+ if (test__start_subtest("invalid_flags"))
+ test_log_invalid_flags();
+ if (test__start_subtest("invalid_target_fd"))
+ test_log_invalid_target_fd();
+ if (test__start_subtest("relative_without_order"))
+ test_log_relative_without_order();
+ if (test__start_subtest("relative_both_orders"))
+ test_log_relative_both_orders();
+ if (test__start_subtest("relative_type_mismatch"))
+ test_log_relative_type_mismatch();
+ if (test__start_subtest("invalid_relative_link_fd"))
+ test_log_invalid_relative_link_fd();
+ if (test__start_subtest("invalid_relative_link_id"))
+ test_log_invalid_relative_link_id();
+ if (test__start_subtest("both_orders"))
+ test_log_both_orders();
+ if (test__start_subtest("relative_preorder_mismatch"))
+ test_log_relative_preorder_mismatch();
+ if (test__start_subtest("relative_not_in_cgroup"))
+ test_log_relative_not_in_cgroup();
+ if (test__start_subtest("revision_mismatch"))
+ test_log_revision_mismatch();
+ if (test__start_subtest("attachment_flags_conflict"))
+ test_log_attachment_flags_conflict();
+ if (test__start_subtest("hierarchy_disallows_attach"))
+ test_log_hierarchy_disallows_attach();
+ if (test__start_subtest("too_many_programs"))
+ test_log_too_many_programs();
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/iter_link.c b/tools/testing/selftests/bpf/prog_tests/iter_link.c
new file mode 100644
index 00000000000000..c684a109091ac5
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/iter_link.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "bpf_iter_bpf_map.skel.h"
+
+static void test_iter_link_create_log(int target_fd, struct bpf_link_create_opts *opts,
+ __u64 flags, int err_exp, const char *msg)
+{
+ struct bpf_iter_bpf_map *skel;
+ char log_buf[128] = {};
+ int err, fd, prog_fd;
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+
+ skel = bpf_iter_bpf_map__open();
+ if (!ASSERT_OK_PTR(skel, "bpf_iter_bpf_map__open"))
+ return;
+
+ err = bpf_program__set_flags(skel->progs.dump_bpf_map, flags);
+ if (!ASSERT_OK(err, "bpf_program__set_flags"))
+ goto out;
+
+ err = bpf_iter_bpf_map__load(skel);
+ if (!ASSERT_OK(err, "bpf_iter_bpf_map__load"))
+ goto out;
+
+ opts->log_opts = &log_opts;
+ prog_fd = bpf_program__fd(skel->progs.dump_bpf_map);
+ fd = bpf_link_create(prog_fd, target_fd, BPF_TRACE_ITER, opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, err_exp, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ bpf_iter_bpf_map__destroy(skel);
+}
+
+static void test_log_invalid_target_fd(void)
+{
+ const char *msg = "Invalid target_fd.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts);
+
+ test_iter_link_create_log(-1, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_invalid_flags(void)
+{
+ const char *msg = "Invalid flags.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .flags = 1,
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_iter_info_only(void)
+{
+ const char *msg = "iter_info and iter_info_len must be both set or both unset.\n";
+ union bpf_iter_link_info info = {};
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.info = &info,
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_iter_info_len_only(void)
+{
+ const char *msg = "iter_info and iter_info_len must be both set or both unset.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.len = sizeof(union bpf_iter_link_info),
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EINVAL, msg);
+}
+
+static void test_log_invalid_iter_info(void)
+{
+ unsigned char info[sizeof(union bpf_iter_link_info) + 1] = {};
+ const char *msg = "Invalid iter_info.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.info = (union bpf_iter_link_info *)info,
+ .iter.len = sizeof(info),
+ );
+
+ info[sizeof(info) - 1] = 1;
+ test_iter_link_create_log(0, &opts, 0, -E2BIG, msg);
+}
+
+static void test_log_invalid_iter_info_len(void)
+{
+ const char *msg = "Invalid iter_info_len.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .iter.info = (union bpf_iter_link_info *)1,
+ .iter.len = sizeof(union bpf_iter_link_info),
+ );
+
+ test_iter_link_create_log(0, &opts, 0, -EFAULT, msg);
+}
+
+static void test_log_invalid_prog(void)
+{
+ const char *msg = "The iter target does not support the bpf prog.\n";
+ LIBBPF_OPTS(bpf_link_create_opts, opts);
+
+ test_iter_link_create_log(0, &opts, BPF_F_SLEEPABLE, -EINVAL, msg);
+}
+
+void test_iter_link_log(void)
+{
+ if (test__start_subtest("invalid_target_fd"))
+ test_log_invalid_target_fd();
+ if (test__start_subtest("invalid_flags"))
+ test_log_invalid_flags();
+ if (test__start_subtest("iter_info_only"))
+ test_log_iter_info_only();
+ if (test__start_subtest("iter_info_len_only"))
+ test_log_iter_info_len_only();
+ if (test__start_subtest("invalid_iter_info"))
+ test_log_invalid_iter_info();
+ if (test__start_subtest("invalid_iter_info_len"))
+ test_log_invalid_iter_info_len();
+ if (test__start_subtest("invalid_prog"))
+ test_log_invalid_prog();
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_link.c b/tools/testing/selftests/bpf/prog_tests/tracing_link.c
new file mode 100644
index 00000000000000..6f22a21be946aa
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_link.c
@@ -0,0 +1,377 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <bpf/btf.h>
+#include "fentry_recursive.skel.h"
+#include "priv_freplace_prog.skel.h"
+#include "xdp_dummy.skel.h"
+#include "kprobe_write_ctx.skel.h"
+#include "tracing_multi_fail.skel.h"
+
+static void test_fentry_link_create_log(int target_fd, __u32 target_btf_id, int cookie,
+ enum bpf_attach_type attach_type,
+ bool reattach, const char *msg)
+{
+ struct fentry_recursive *skel = NULL;
+ struct xdp_dummy *target;
+ char log_buf[128] = {};
+ int err, fd, prog_fd;
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .log_opts = &log_opts,
+ .target_btf_id = target_btf_id,
+ .tracing.cookie = cookie,
+ );
+
+ target = xdp_dummy__open_and_load();
+ if (!ASSERT_OK_PTR(target, "xdp_dummy__open_and_load"))
+ return;
+
+ skel = fentry_recursive__open();
+ if (!ASSERT_OK_PTR(skel, "fentry_recursive__open"))
+ goto out;
+
+ err = bpf_program__set_attach_target(skel->progs.recursive_attach,
+ bpf_program__fd(target->progs.xdp_dummy_prog),
+ "xdp_dummy_prog");
+ if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
+ goto out;
+
+ err = fentry_recursive__load(skel);
+ if (!ASSERT_OK(err, "fentry_recursive__load"))
+ goto out;
+
+ prog_fd = bpf_program__fd(skel->progs.recursive_attach);
+ if (reattach) {
+ /* Consume the initial target saved when the program was loaded. */
+ fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FENTRY, &opts);
+ if (!ASSERT_GE(fd, 0, "bpf_link_create first"))
+ goto out;
+
+ close(fd);
+ memset(log_buf, 0, sizeof(log_buf));
+ log_opts.true_size = 0;
+ }
+
+ fd = bpf_link_create(prog_fd, target_fd, attach_type, &opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, -EINVAL, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ fentry_recursive__destroy(skel);
+ xdp_dummy__destroy(target);
+}
+
+static void test_log_invalid_attach_type(void)
+{
+ const char *msg = "Invalid attach_type.\n";
+
+ test_fentry_link_create_log(0, 0, 0, BPF_XDP, false, msg);
+}
+
+static void test_log_tgt_prog_fd_only(void)
+{
+ const char *msg = "tgt_prog_fd and btf_id must be both set or both unset.\n";
+
+ test_fentry_link_create_log(-1, 0, 1, BPF_TRACE_FENTRY, false, msg);
+}
+
+static void test_log_tgt_prog_fd_disallowed(void)
+{
+ const char *msg = "tgt_prog_fd is only allowed for freplace prog.\n";
+
+ test_fentry_link_create_log(-1, 1, 0, BPF_TRACE_FENTRY, false, msg);
+}
+
+static void test_log_invalid_attach_btf(void)
+{
+ const char *msg = "Invalid attach_btf.\n";
+
+ test_fentry_link_create_log(0, 0, 1, BPF_TRACE_FENTRY, true, msg);
+}
+
+static void test_freplace_link_create_log(int target_fd, __u32 target_btf_id, int err_exp,
+ bool reattach, const char *msg)
+{
+ struct priv_freplace_prog *skel = NULL;
+ char log_buf[256] = {};
+ struct xdp_dummy *xdp;
+ int err, fd, prog_fd;
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .log_opts = &log_opts,
+ .target_btf_id = target_btf_id,
+ );
+
+ xdp = xdp_dummy__open_and_load();
+ if (!ASSERT_OK_PTR(xdp, "xdp_dummy__open_and_load"))
+ return;
+
+ skel = priv_freplace_prog__open();
+ if (!ASSERT_OK_PTR(skel, "priv_freplace_prog__open"))
+ goto out;
+
+ err = bpf_program__set_attach_target(skel->progs.new_xdp_prog2,
+ bpf_program__fd(xdp->progs.xdp_dummy_prog),
+ "xdp_dummy_prog");
+ if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
+ goto out;
+
+ err = priv_freplace_prog__load(skel);
+ if (!ASSERT_OK(err, "priv_freplace_prog__load"))
+ goto out;
+
+ prog_fd = bpf_program__fd(skel->progs.new_xdp_prog2);
+ if (reattach) {
+ /* Consume the initial target saved when the program was loaded. */
+ fd = bpf_link_create(prog_fd, 0, 0, &opts);
+ if (!ASSERT_GE(fd, 0, "bpf_link_create first"))
+ goto out;
+
+ close(fd);
+ memset(log_buf, 0, sizeof(log_buf));
+ log_opts.true_size = 0;
+ }
+
+ if (!target_fd && target_btf_id)
+ target_fd = bpf_program__fd(xdp->progs.xdp_dummy_prog);
+
+ fd = bpf_link_create(prog_fd, target_fd, 0, &opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, err_exp, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ priv_freplace_prog__destroy(skel);
+ xdp_dummy__destroy(xdp);
+}
+
+static void test_log_invalid_target_fd(void)
+{
+ const char *msg = "Invalid tgt_prog_fd.\n";
+
+ test_freplace_link_create_log(-1, 1, -EBADF, false, msg);
+}
+
+static void test_log_reattach_without_target(void)
+{
+ const char *msg = "Only allow re-attach for tracing and lsm progs.\n";
+
+ test_freplace_link_create_log(0, 0, -EINVAL, true, msg);
+}
+
+static void test_log_invalid_target_btf_id(void)
+{
+ const char *msg = "attach_btf_id 4294967295 is invalid\n";
+
+ test_freplace_link_create_log(0, ~0U, -EINVAL, false, msg);
+}
+
+#ifdef __x86_64__
+static void test_log_invalid_kprobe_write_ctx(void)
+{
+ struct kprobe_write_ctx *skel_kprobe, *skel_freplace = NULL;
+ struct bpf_program *prog_kprobe, *prog_freplace;
+ const char *msg = "Invalid kprobe_write_ctx.\n";
+ int err, prog_fd, btf_id, fd;
+ char log_buf[128] = {};
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+ LIBBPF_OPTS(bpf_link_create_opts, link_opts,
+ .log_opts = &log_opts,
+ );
+
+ skel_kprobe = kprobe_write_ctx__open();
+ if (!ASSERT_OK_PTR(skel_kprobe, "kprobe_write_ctx__open kprobe"))
+ return;
+
+ prog_kprobe = skel_kprobe->progs.kprobe_dummy;
+ bpf_program__set_autoload(prog_kprobe, true);
+
+ err = kprobe_write_ctx__load(skel_kprobe);
+ if (!ASSERT_OK(err, "kprobe_write_ctx__load kprobe"))
+ goto out;
+
+ skel_freplace = kprobe_write_ctx__open();
+ if (!ASSERT_OK_PTR(skel_freplace, "kprobe_write_ctx__open freplace"))
+ goto out;
+
+ prog_freplace = skel_freplace->progs.freplace_kprobe;
+ bpf_program__set_autoload(prog_freplace, true);
+
+ prog_fd = bpf_program__fd(skel_kprobe->progs.kprobe_write_ctx);
+ bpf_program__set_attach_target(prog_freplace, prog_fd, "kprobe_write_ctx");
+
+ err = kprobe_write_ctx__load(skel_freplace);
+ if (!ASSERT_OK(err, "kprobe_write_ctx__load freplace"))
+ goto out;
+
+ prog_fd = bpf_program__fd(prog_kprobe);
+ btf_id = btf__find_by_name_kind(bpf_object__btf(skel_kprobe->obj), "kprobe_dummy",
+ BTF_KIND_FUNC);
+ if (!ASSERT_GT(btf_id, 0, "btf__find_by_name_kind"))
+ goto out;
+
+ link_opts.target_btf_id = btf_id;
+ fd = bpf_link_create(bpf_program__fd(prog_freplace), prog_fd, 0, &link_opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, -EINVAL, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ kprobe_write_ctx__destroy(skel_freplace);
+ kprobe_write_ctx__destroy(skel_kprobe);
+}
+#else
+static void test_log_invalid_kprobe_write_ctx(void)
+{
+ test__skip();
+}
+#endif
+
+void test_tracing_link_log(void)
+{
+ if (test__start_subtest("invalid_attach_type"))
+ test_log_invalid_attach_type();
+ if (test__start_subtest("tgt_prog_fd_only"))
+ test_log_tgt_prog_fd_only();
+ if (test__start_subtest("tgt_prog_fd_disallowed"))
+ test_log_tgt_prog_fd_disallowed();
+ if (test__start_subtest("invalid_attach_btf"))
+ test_log_invalid_attach_btf();
+ if (test__start_subtest("invalid_target_fd"))
+ test_log_invalid_target_fd();
+ if (test__start_subtest("reattach_without_target"))
+ test_log_reattach_without_target();
+ if (test__start_subtest("invalid_target_btf_id"))
+ test_log_invalid_target_btf_id();
+ if (test__start_subtest("invalid_kprobe_write_ctx"))
+ test_log_invalid_kprobe_write_ctx();
+}
+
+static void test_tracing_multi_link_create_log(int target_fd, __u32 flags, const __u32 *ids,
+ __u32 cnt, int err_exp, const char *msg)
+{
+ struct tracing_multi_fail *skel;
+ char log_buf[128] = {};
+ int err, fd, prog_fd;
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .log_opts = &log_opts,
+ .flags = flags,
+ .tracing_multi.ids = ids,
+ .tracing_multi.cnt = cnt,
+ );
+
+ skel = tracing_multi_fail__open();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi_fail__open"))
+ return;
+
+ bpf_program__set_autoload(skel->progs.test_fentry_s, false);
+ err = tracing_multi_fail__load(skel);
+ if (!ASSERT_OK(err, "tracing_multi_fail__load"))
+ goto out;
+
+ prog_fd = bpf_program__fd(skel->progs.test_fentry);
+ fd = bpf_link_create(prog_fd, target_fd, BPF_TRACE_FENTRY_MULTI, &opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, err_exp, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ tracing_multi_fail__destroy(skel);
+}
+
+static void test_multi_log_zero_count(void)
+{
+ const char *msg = "tracing_multi.cnt cannot be zero.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(0, 0, &id, 0, -EINVAL, msg);
+}
+
+static void test_multi_log_missing_ids(void)
+{
+ const char *msg = "tracing_multi.ids must be set.\n";
+
+ test_tracing_multi_link_create_log(0, 0, NULL, 1, -EINVAL, msg);
+}
+
+static void test_multi_log_excessive_count(void)
+{
+ const char *msg = "tracing_multi.cnt is too large.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(0, 0, &id, INT_MAX, -E2BIG, msg);
+}
+
+static void test_multi_log_invalid_flags(void)
+{
+ const char *msg = "Invalid flags.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(0, 1, &id, 1, -EINVAL, msg);
+}
+
+static void test_multi_log_invalid_target_fd(void)
+{
+ const char *msg = "Invalid target_fd.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(-1, 0, &id, 1, -EINVAL, msg);
+}
+
+void test_tracing_multi_link_log(void)
+{
+#ifndef __x86_64__
+ test__skip();
+ return;
+#endif
+
+ if (test__start_subtest("zero_count"))
+ test_multi_log_zero_count();
+ if (test__start_subtest("missing_ids"))
+ test_multi_log_missing_ids();
+ if (test__start_subtest("excessive_count"))
+ test_multi_log_excessive_count();
+ if (test__start_subtest("invalid_flags"))
+ test_multi_log_invalid_flags();
+ if (test__start_subtest("invalid_target_fd"))
+ test_multi_log_invalid_target_fd();
+}
+
|
| 3/2 | 2026/11/12 13:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23112 output: 38 thoughts: 1587 Thoughts: **Analyzing the Patch for Fuzzing Potential** Okay, let's break this patch down and figure out if it's syzkaller-worthy. Following the triage philosophy, reachability is the primary concern, so we're looking at code in the QEMU/standard environment. I need to avoid blindly trusting "no functional change" claims, especially in refactoring cases. New or modified assertions in reachable code are definitely on the radar. I'll only mark this as WorthFuzzing=false if all changes fall into the negative criteria, specifically things that don't affect kernel execution. First, I need to understand what the patch *actually* changed. Let's look closely at the diff. The primary changes seem to involve adding `struct bpf_verifier_log *log` as a parameter to a bunch of BPF functions: `cgroup_bpf_link_attach`, `bpf_iter_link_attach`, and `bpf_tracing_multi_attach` in various header files. This change is propagated to the implementation files. This is my starting point: function prototypes are being changed, I need to understand the impact of this change. In `kernel/bpf/bpf_iter.c`, I see `bpf_log(log, ...)` being added around error returns, essentially for logging invalid `target_fd` or `flags` in `bpf_iter_link_attach`. This smells like an assertion change, or, at least, added observability of error cases. `kernel/bpf/cgroup.c` is also modified, with `bpf_log(log, ...)` being added before existing error returns in several functions. Furthermore, there's a specific section of control flow logic that's been slightly tweaked, although the core logic appears to remain the same. The change introduces additional error checks related to the use of `BPF_F_BEFORE` and `BPF_F_AFTER` flags. While the control flow itself is the same, now the code provides more granular error messages via `bpf_log`. In `kernel/bpf/syscall.c`, `bpf_tracing_prog_attach` now takes the `log` parameter, and also calls `bpf_log` on error checks. Crucially, the patch now passes `log` to `bpf_check_attach_target`, where previously it was passing `NULL`. So this change introduces more observability and validation of potential BPF attach targets. In `link_create` function, `log` is being passed into various other BPF attach functions, which is where the `log` is propagated. `kernel/trace/bpf_trace.c` is similar, adding the `log` parameter and `bpf_log` on error conditions. Finally, there are changes in `tools/lib/bpf/bpf.c`, `tools/lib/bpf/bpf.h` and selftests. These are likely to be related to the tooling that's used by user-space, which aren't as important. Now, the critical question: Is this all purely decorative logging, or does it *do* something? The addition of more logging on error returns hints at a more complex purpose. This change appears to increase the strictness and granularity of the error messages, but not modify control flow in a meaningful way. Now I need to understand what `bpf_log` actually *does* and where that `log` comes from in the `link_create` function to determine its impact. It seems the code is not decorative, and instead making error messages more descriptive, by adding extra BPF logging. The change to `bpf_check_attach_target` is a signal, this will require some careful thought. |
| 4/2 | 2026/11/12 13:12 | tool | grepper |
0mArgs:{
"Expression": "struct bpf_verifier_log .*log",
"PathPrefixes": [
"kernel/bpf/syscall.c"
]
}Results: {
"Output": "kernel/bpf/syscall.c=1268=static int map_check_btf(struct bpf_map *map, struct bpf_token *token,\n--\nkernel/bpf/syscall.c-1400-/* called via syscall */\nkernel/bpf/syscall.c:1401:static int map_create_alloc(union bpf_attr *attr, bpfptr_t uattr, struct bpf_verifier_log *log,\nkernel/bpf/syscall.c-1402-\t\t\t struct bpf_map **mapp, struct bpf_token **tokenp)\n--\nkernel/bpf/syscall.c=1649=static int map_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_attr *attr_common,\n--\nkernel/bpf/syscall.c-1652-\tstruct bpf_token *token = NULL;\nkernel/bpf/syscall.c:1653:\tstruct bpf_verifier_log *log;\nkernel/bpf/syscall.c-1654-\tstruct bpf_log_attr attr_log;\n--\nkernel/bpf/syscall.c=3673=static int bpf_tracing_prog_attach(struct bpf_prog *prog,\n--\nkernel/bpf/syscall.c-3677-\t\t\t\t enum bpf_attach_type attach_type,\nkernel/bpf/syscall.c:3678:\t\t\t\t struct bpf_verifier_log *log)\nkernel/bpf/syscall.c-3679-{\n--\nkernel/bpf/syscall.c=5868=static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_attr *attr_common,\n--\nkernel/bpf/syscall.c-5871-\tstruct netlink_ext_ack extack = {};\nkernel/bpf/syscall.c:5872:\tstruct bpf_verifier_log *log;\nkernel/bpf/syscall.c-5873-\tstruct bpf_log_attr attr_log;\n"
} |
| 5/2 | 2026/11/12 13:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26073 output: 37 thoughts: 31 Thoughts: Okay, here's the summary, expressed as though I'm the one thinking it: **Diving into `syscall.c` and Line 5868** Alright, let's get down to brass tacks. I need to understand what's been happening with this BPF stuff in the kernel. Specifically, I'm thinking I should start digging into `kernel/bpf/syscall.c`, and that line 5868 seems like a likely place to start. I'm going to scan the code around that line; I need to see the context. What's the existing code like? What's the established logic in that area? Then, the critical question, what *changed*? I need to quickly identify the modifications, what was added or altered, and the intent behind those changes. I'm after the "why" and "how" of this particular part of the BPF implementation. |
| 6/2 | 2026/11/12 13:13 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/syscall.c",
"FirstLine": 5868,
"LineCount": 50
}Results: {
"Contents": "5868:\tstatic int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_attr *attr_common,\n5869:\t\t\t bpfptr_t uattr_common, u32 size_common)\n5870:\t{\n5871:\t\tstruct netlink_ext_ack extack = {};\n5872:\t\tstruct bpf_verifier_log *log;\n5873:\t\tstruct bpf_log_attr attr_log;\n5874:\t\tstruct bpf_prog *prog;\n5875:\t\tint ret;\n5876:\t\n5877:\t\tif (CHECK_ATTR(BPF_LINK_CREATE))\n5878:\t\t\treturn -EINVAL;\n5879:\t\n5880:\t\tif (attr-\u003elink_create.attach_type == BPF_STRUCT_OPS)\n5881:\t\t\treturn bpf_struct_ops_link_create(attr);\n5882:\t\n5883:\t\tlog = bpf_log_attr_create_vlog(\u0026attr_log, attr_common, uattr_common, size_common);\n5884:\t\tif (IS_ERR(log))\n5885:\t\t\treturn PTR_ERR(log);\n5886:\t\n5887:\t\tprog = bpf_prog_get(attr-\u003elink_create.prog_fd);\n5888:\t\tif (IS_ERR(prog)) {\n5889:\t\t\tbpf_log(log, \"Invalid prog_fd.\\n\");\n5890:\t\t\tret = PTR_ERR(prog);\n5891:\t\t\tprog = NULL;\n5892:\t\t\tgoto out;\n5893:\t\t}\n5894:\t\n5895:\t\tret = bpf_prog_attach_check_attach_type(prog,\n5896:\t\t\t\t\t\t\tattr-\u003elink_create.attach_type);\n5897:\t\tif (ret) {\n5898:\t\t\tbpf_log(log, \"Invalid attach_type.\\n\");\n5899:\t\t\tgoto out;\n5900:\t\t}\n5901:\t\n5902:\t\tswitch (prog-\u003etype) {\n5903:\t\tcase BPF_PROG_TYPE_CGROUP_SKB:\n5904:\t\tcase BPF_PROG_TYPE_CGROUP_SOCK:\n5905:\t\tcase BPF_PROG_TYPE_CGROUP_SOCK_ADDR:\n5906:\t\tcase BPF_PROG_TYPE_SOCK_OPS:\n5907:\t\tcase BPF_PROG_TYPE_CGROUP_DEVICE:\n5908:\t\tcase BPF_PROG_TYPE_CGROUP_SYSCTL:\n5909:\t\tcase BPF_PROG_TYPE_CGROUP_SOCKOPT:\n5910:\t\t\tret = cgroup_bpf_link_attach(attr, prog, log);\n5911:\t\t\tbreak;\n5912:\t\tcase BPF_PROG_TYPE_EXT:\n5913:\t\t\tret = bpf_tracing_prog_attach(prog,\n5914:\t\t\t\t\t\t attr-\u003elink_create.target_fd,\n5915:\t\t\t\t\t\t attr-\u003elink_create.target_btf_id,\n5916:\t\t\t\t\t\t attr-\u003elink_create.tracing.cookie,\n5917:\t\t\t\t\t\t attr-\u003elink_create.attach_type,\n"
} |
| 7/2 | 2026/11/12 13:13 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27210 output: 35 thoughts: 428 Thoughts: **Analyzing the Recent Code Changes** Okay, here's what I'm seeing: The `bpf_log_attr_create_vlog` function and the `log` variable were already present within `link_create`. Additionally, the code already checked for a valid `prog_fd` and `attach_type` before the changes. This is important context. Now, let's zero in on the patch. It seems that the `log` variable, which is a verifier log, is now being propagated down into multiple functions within `link_create`: `cgroup_bpf_link_attach`, `bpf_tracing_prog_attach`, `bpf_iter_link_attach`, and `bpf_tracing_multi_attach`. This is a significant change, I'd say. The really interesting bit is that it's also being passed into `bpf_check_attach_target`. Wait a second… isn't `bpf_check_attach_target`'s first argument `struct bpf_verifier_log *log`? Yes, confirmed. Now, I should probably inspect `bpf_check_attach_target` in `kernel/bpf/verifier.c` in more detail. Let's see how that log is actually being used in there now. |
| 8/2 | 2026/11/12 13:13 | tool | grepper |
0mArgs:{
"Expression": "int bpf_check_attach_target",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/verifier.c=23972=static int check_ext_args(struct bpf_verifier_log *log, const struct bpf_prog *prog,\n--\nkernel/bpf/verifier.c-23994-\nkernel/bpf/verifier.c:23995:int bpf_check_attach_target(struct bpf_verifier_log *log,\nkernel/bpf/verifier.c-23996-\t\t\t const struct bpf_prog *prog,\n"
} |
| 9/2 | 2026/11/12 13:13 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28090 output: 39 thoughts: 145 Thoughts: **Investigating `bpf_check_attach_target` and the Role of `bpf_log`** Okay, so I'm looking at this code and something's caught my eye. Specifically, I'm focusing on `bpf_check_attach_target`. I'm seeing that within `bpf_tracing_prog_attach()`, the argument being passed has changed; it used to be `NULL` and now it's `log`. Interesting. Also, I'm noticing that the error paths within functions like `cgroup_bpf_link_attach()`, `bpf_iter_link_attach()`, `bpf_tracing_multi_attach()`, and `bpf_tracing_prog_attach()` now include a call to `bpf_log(log, "...")`. This is prompting a few questions. Primarily, I need to understand the implications of this change. Is this just logging, or does `bpf_log` actually *do* something more significant? Does it alter control flow? Does it modify data structures? I need to be sure; if it does, this change could be substantial. To do that, I'm going to have to dive deeper and figure out what exactly `bpf_log` *is*. Let's go check that out. |
| 10/2 | 2026/11/12 13:13 | tool | grepper |
0mArgs:{
"Expression": "void bpf_log\\(",
"PathPrefixes": [
"kernel/bpf/",
"include/linux/"
]
}Results: {
"Output": "include/linux/bpf_verifier.h=1413=__printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,\ninclude/linux/bpf_verifier.h-1414-\t\t\t\t\t const char *fmt, ...);\ninclude/linux/bpf_verifier.h:1415:__printf(2, 3) void bpf_log(struct bpf_verifier_log *log,\ninclude/linux/bpf_verifier.h-1416-\t\t\t const char *fmt, ...);\n--\nkernel/bpf/log.c=363=EXPORT_SYMBOL_GPL(bpf_verifier_log_write);\nkernel/bpf/log.c-364-\nkernel/bpf/log.c:365:__printf(2, 3) void bpf_log(struct bpf_verifier_log *log,\nkernel/bpf/log.c-366-\t\t\t const char *fmt, ...)\n"
} |
| 11/2 | 2026/11/12 13:13 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28810 output: 36 thoughts: 31 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Diving into `bpf_log` Implementation** Alright, I'm thinking I need to understand the logging behavior within the BPF subsystem, specifically the details of `bpf_log`. I'll want to check out the source code, targeting the `kernel/bpf/log.c` file. Given the context, line 365 looks like a promising starting point for understanding how this logging mechanism is implemented. I'm assuming that line number is likely the start of the `bpf_log` function's body, or at least a significant part of it. My goal is to quickly grasp the core mechanics and any potentially relevant details for future investigation. |
| 12/2 | 2026/11/12 13:13 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/log.c",
"FirstLine": 360,
"LineCount": 40
}Results: {
"Contents": " 360:\t\tbpf_verifier_vlog(\u0026env-\u003elog, fmt, args);\n 361:\t\tva_end(args);\n 362:\t}\n 363:\tEXPORT_SYMBOL_GPL(bpf_verifier_log_write);\n 364:\t\n 365:\t__printf(2, 3) void bpf_log(struct bpf_verifier_log *log,\n 366:\t\t\t\t const char *fmt, ...)\n 367:\t{\n 368:\t\tva_list args;\n 369:\t\n 370:\t\tif (!bpf_verifier_log_needed(log))\n 371:\t\t\treturn;\n 372:\t\n 373:\t\tva_start(args, fmt);\n 374:\t\tbpf_verifier_vlog(log, fmt, args);\n 375:\t\tva_end(args);\n 376:\t}\n 377:\tEXPORT_SYMBOL_GPL(bpf_log);\n 378:\t\n 379:\tstatic const char *ltrim(const char *s)\n 380:\t{\n 381:\t\twhile (isspace(*s))\n 382:\t\t\ts++;\n 383:\t\n 384:\t\treturn s;\n 385:\t}\n 386:\t\n 387:\t__printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,\n 388:\t\t\t\t\t u32 insn_off,\n 389:\t\t\t\t\t const char *prefix_fmt, ...)\n 390:\t{\n 391:\t\tconst struct bpf_line_info *linfo, *prev_linfo;\n 392:\t\tconst struct btf *btf;\n 393:\t\tconst char *s, *fname;\n 394:\t\n 395:\t\tif (!bpf_verifier_log_needed(\u0026env-\u003elog))\n 396:\t\t\treturn;\n 397:\t\n 398:\t\tprev_linfo = env-\u003eprev_linfo;\n 399:\t\tlinfo = bpf_find_linfo(env-\u003eprog, insn_off);\n"
} |
| 13/2 | 2026/11/12 13:13 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29623 output: 33 thoughts: 304 Thoughts: **Analyzing the Fuzzing Criteria** Okay, let's break this down. Section 2 is crucial here, specifically the negative criteria – when we *don't* fuzz. The instructions clearly state that we should return `WorthFuzzing=false` only if *all* the modified code fits *strictly* within the defined categories. Right, so we need to be very precise. Let's read the list again: Non-kernel and non-executable changes, which includes things like documentation, user-space tools, and *purely decorative logging*. This "purely decorative logging" bit is where the question arises... The specific case, `bpf_log`, is the important point. The question: Does `bpf_log` qualify as "purely decorative logging"? Now the critical thinking begins! I know that `bpf_log` seems to be writing to a log buffer. It uses `bpf_verifier_vlog(log, fmt, args)`, which writes to a user-supplied buffer. The pertinent question becomes: Does writing to a log buffer alter control flow or data structures? That is the crux of the matter. Let's consult the code for `bpf_verifier_vlog` to confirm. |
| 14/2 | 2026/11/12 13:14 | tool | grepper |
0mArgs:{
"Expression": "bpf_verifier_vlog",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/btf.c=1564=__printf(2, 3) static void __btf_verifier_log(struct bpf_verifier_log *log,\n--\nkernel/bpf/btf.c-1569-\tva_start(args, fmt);\nkernel/bpf/btf.c:1570:\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/btf.c-1571-\tva_end(args);\n--\nkernel/bpf/btf.c=1574=__printf(2, 3) static void btf_verifier_log(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-1583-\tva_start(args, fmt);\nkernel/bpf/btf.c:1584:\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/btf.c-1585-\tva_end(args);\n--\nkernel/bpf/btf.c=1588=__printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-1624-\t\tva_start(args, fmt);\nkernel/bpf/btf.c:1625:\t\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/btf.c-1626-\t\tva_end(args);\n--\nkernel/bpf/btf.c=1638=static void btf_verifier_log_member(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-1682-\t\tva_start(args, fmt);\nkernel/bpf/btf.c:1683:\t\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/btf.c-1684-\t\tva_end(args);\n--\nkernel/bpf/btf.c=1691=static void btf_verifier_log_vsi(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-1710-\t\tva_start(args, fmt);\nkernel/bpf/btf.c:1711:\t\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/btf.c-1712-\t\tva_end(args);\n--\nkernel/bpf/btf.c=4992=static void btf_verifier_log_loc(struct btf_verifier_env *env,\n--\nkernel/bpf/btf.c-5011-\t\tva_start(args, fmt);\nkernel/bpf/btf.c:5012:\t\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/btf.c-5013-\t\tva_end(args);\n--\nkernel/bpf/diagnostics.c=371=static void diag_write(struct bpf_verifier_env *env, const char *fmt, ...)\n--\nkernel/bpf/diagnostics.c-378-\tva_start(args, fmt);\nkernel/bpf/diagnostics.c:379:\tbpf_verifier_vlog(\u0026env-\u003elog, fmt, args);\nkernel/bpf/diagnostics.c-380-\tva_end(args);\n--\nkernel/bpf/log.c=45=static void bpf_vlog_update_len_max(struct bpf_verifier_log *log, u32 add_len)\n--\nkernel/bpf/log.c-59-\nkernel/bpf/log.c:60:void bpf_verifier_vlog(struct bpf_verifier_log *log, const char *fmt,\nkernel/bpf/log.c-61-\t\t va_list args)\n--\nkernel/bpf/log.c=351=__printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,\n--\nkernel/bpf/log.c-359-\tva_start(args, fmt);\nkernel/bpf/log.c:360:\tbpf_verifier_vlog(\u0026env-\u003elog, fmt, args);\nkernel/bpf/log.c-361-\tva_end(args);\n--\nkernel/bpf/log.c=365=__printf(2, 3) void bpf_log(struct bpf_verifier_log *log,\n--\nkernel/bpf/log.c-373-\tva_start(args, fmt);\nkernel/bpf/log.c:374:\tbpf_verifier_vlog(log, fmt, args);\nkernel/bpf/log.c-375-\tva_end(args);\n--\nkernel/bpf/log.c=387=__printf(3, 4) void verbose_linfo(struct bpf_verifier_env *env,\n--\nkernel/bpf/log.c-418-\t\tva_start(args, prefix_fmt);\nkernel/bpf/log.c:419:\t\tbpf_verifier_vlog(\u0026env-\u003elog, prefix_fmt, args);\nkernel/bpf/log.c-420-\t\tva_end(args);\n--\nkernel/bpf/verifier.c=317=__printf(2, 3) static void verbose(void *private_data, const char *fmt, ...)\n--\nkernel/bpf/verifier.c-325-\tva_start(args, fmt);\nkernel/bpf/verifier.c:326:\tbpf_verifier_vlog(\u0026env-\u003elog, fmt, args);\nkernel/bpf/verifier.c-327-\tva_end(args);\n"
} |
| 15/2 | 2026/11/12 13:14 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31691 output: 43 thoughts: 142 Thoughts: Okay, let's break this down. **Analyzing `bpf_verifier_vlog` and Logging Practices** Alright, I need to understand this `bpf_verifier_vlog` function. Seems straightforward: it formats a string and writes it to a log buffer, either user-space or kernel-space, but only if `bpf_verifier_log_needed(log)` returns true. That's the basic mechanics. But hold on a second... what kind of logging are we talking about here? I need to clarify whether `bpf_log` is merely "decorative logging". Ah, got it. Decorative logging means it's for informational purposes – things like error messages from `pr_err`, `printk`, `dev_info`, or tracepoints that *don't* change how the code flows or affect data structures. That's important context. Now, I really need the broader picture. What's the *purpose* of this specific patch? I can't just look at the individual function without understanding the bigger goal. I'll need to go back and investigate the commit message. A quick `git log -1 HEAD` should give me the most recent commit and its description. Understanding the "why" of the change is crucial to properly assess its impact and the intended behavior. |
| 16/2 | 2026/11/12 13:14 | tool | grepper |
0mArgs:{
"Expression": ".*",
"PathPrefixes": [
"tools/testing/selftests/bpf/prog_tests/cgroup_link.c"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 579 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (1 files in total):\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:579\n\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:1:// SPDX-License-Identifier: GPL-2.0\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:2:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:3:#include \u003ctest_progs.h\u003e\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:4:#include \"cgroup_helpers.h\"\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:5:#include \"testing_helpers.h\"\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:6:#include \"test_cgroup_link.skel.h\"\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:7:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:8:static __u32 duration = 0;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:9:#define PING_CMD\t\"ping -q -c1 -w1 127.0.0.1 \u003e /dev/null\"\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:10:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:11:static struct test_cgroup_link *skel = NULL;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:12:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:13:int ping_and_check(int exp_calls, int exp_alt_calls)\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:14:{\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:15:\tskel-\u003ebss-\u003ecalls = 0;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:16:\tskel-\u003ebss-\u003ealt_calls = 0;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:17:\tCHECK_FAIL(system(PING_CMD));\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:18:\tif (CHECK(skel-\u003ebss-\u003ecalls != exp_calls, \"call_cnt\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:19:\t\t \"exp %d, got %d\\n\", exp_calls, skel-\u003ebss-\u003ecalls))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:20:\t\treturn -EINVAL;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:21:\tif (CHECK(skel-\u003ebss-\u003ealt_calls != exp_alt_calls, \"alt_call_cnt\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:22:\t\t \"exp %d, got %d\\n\", exp_alt_calls, skel-\u003ebss-\u003ealt_calls))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:23:\t\treturn -EINVAL;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:24:\treturn 0;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:25:}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:26:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:27:void serial_test_cgroup_link(void)\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:28:{\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:29:\tstruct {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:30:\t\tconst char *path;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:31:\t\tint fd;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:32:\t} cgs[] = {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:33:\t\t{ \"/cg1\" },\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:34:\t\t{ \"/cg1/cg2\" },\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:35:\t\t{ \"/cg1/cg2/cg3\" },\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:36:\t\t{ \"/cg1/cg2/cg3/cg4\" },\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:37:\t};\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:38:\tint last_cg = ARRAY_SIZE(cgs) - 1, cg_nr = ARRAY_SIZE(cgs);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:39:\tDECLARE_LIBBPF_OPTS(bpf_link_update_opts, link_upd_opts);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:40:\tstruct bpf_link *links[ARRAY_SIZE(cgs)] = {}, *tmp_link;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:41:\t__u32 prog_ids[ARRAY_SIZE(cgs)], prog_cnt = 0, attach_flags, prog_id;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:42:\tstruct bpf_link_info info;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:43:\tint i = 0, err, prog_fd;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:44:\tbool detach_legacy = false;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:45:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:46:\tskel = test_cgroup_link__open_and_load();\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:47:\tif (CHECK(!skel, \"skel_open_load\", \"failed to open/load skeleton\\n\"))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:48:\t\treturn;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:49:\tprog_fd = bpf_program__fd(skel-\u003eprogs.egress);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:50:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:51:\terr = setup_cgroup_environment();\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:52:\tif (CHECK(err, \"cg_init\", \"failed: %d\\n\", err))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:53:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:54:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:55:\tfor (i = 0; i \u003c cg_nr; i++) {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:56:\t\tcgs[i].fd = create_and_get_cgroup(cgs[i].path);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:57:\t\tif (!ASSERT_GE(cgs[i].fd, 0, \"cg_create\"))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:58:\t\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:59:\t}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:60:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:61:\terr = join_cgroup(cgs[last_cg].path);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:62:\tif (CHECK(err, \"cg_join\", \"fail: %d\\n\", err))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:63:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:64:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:65:\tfor (i = 0; i \u003c cg_nr; i++) {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:66:\t\tlinks[i] = bpf_program__attach_cgroup(skel-\u003eprogs.egress,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:67:\t\t\t\t\t\t cgs[i].fd);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:68:\t\tif (!ASSERT_OK_PTR(links[i], \"cg_attach\"))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:69:\t\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:70:\t}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:71:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:72:\tping_and_check(cg_nr, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:73:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:74:\t/* query the number of attached progs and attach flags in root cg */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:75:\terr = bpf_prog_query(cgs[0].fd, BPF_CGROUP_INET_EGRESS,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:76:\t\t\t 0, \u0026attach_flags, NULL, \u0026prog_cnt);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:77:\tCHECK_FAIL(err);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:78:\tCHECK_FAIL(attach_flags != BPF_F_ALLOW_MULTI);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:79:\tif (CHECK(prog_cnt != 1, \"effect_cnt\", \"exp %d, got %d\\n\", 1, prog_cnt))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:80:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:81:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:82:\t/* query the number of effective progs in last cg */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:83:\terr = bpf_prog_query(cgs[last_cg].fd, BPF_CGROUP_INET_EGRESS,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:84:\t\t\t BPF_F_QUERY_EFFECTIVE, NULL, NULL,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:85:\t\t\t \u0026prog_cnt);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:86:\tCHECK_FAIL(err);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:87:\tif (CHECK(prog_cnt != cg_nr, \"effect_cnt\", \"exp %d, got %d\\n\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:88:\t\t cg_nr, prog_cnt))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:89:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:90:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:91:\t/* query the effective prog IDs in last cg */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:92:\terr = bpf_prog_query(cgs[last_cg].fd, BPF_CGROUP_INET_EGRESS,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:93:\t\t\t BPF_F_QUERY_EFFECTIVE, NULL, prog_ids,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:94:\t\t\t \u0026prog_cnt);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:95:\tCHECK_FAIL(err);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:96:\tif (CHECK(prog_cnt != cg_nr, \"effect_cnt\", \"exp %d, got %d\\n\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:97:\t\t cg_nr, prog_cnt))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:98:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:99:\tfor (i = 1; i \u003c prog_cnt; i++) {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:100:\t\tCHECK(prog_ids[i - 1] != prog_ids[i], \"prog_id_check\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:101:\t\t \"idx %d, prev id %d, cur id %d\\n\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:102:\t\t i, prog_ids[i - 1], prog_ids[i]);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:103:\t}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:104:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:105:\t/* detach bottom program and ping again */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:106:\tbpf_link__destroy(links[last_cg]);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:107:\tlinks[last_cg] = NULL;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:108:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:109:\tping_and_check(cg_nr - 1, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:110:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:111:\t/* mix in with non link-based multi-attachments */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:112:\terr = bpf_prog_attach(prog_fd, cgs[last_cg].fd,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:113:\t\t\t BPF_CGROUP_INET_EGRESS, BPF_F_ALLOW_MULTI);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:114:\tif (CHECK(err, \"cg_attach_legacy\", \"errno=%d\\n\", errno))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:115:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:116:\tdetach_legacy = true;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:117:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:118:\tlinks[last_cg] = bpf_program__attach_cgroup(skel-\u003eprogs.egress,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:119:\t\t\t\t\t\t cgs[last_cg].fd);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:120:\tif (!ASSERT_OK_PTR(links[last_cg], \"cg_attach\"))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:121:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:122:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:123:\tping_and_check(cg_nr + 1, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:124:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:125:\t/* detach link */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:126:\tbpf_link__destroy(links[last_cg]);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:127:\tlinks[last_cg] = NULL;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:128:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:129:\t/* detach legacy */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:130:\terr = bpf_prog_detach2(prog_fd, cgs[last_cg].fd, BPF_CGROUP_INET_EGRESS);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:131:\tif (CHECK(err, \"cg_detach_legacy\", \"errno=%d\\n\", errno))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:132:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:133:\tdetach_legacy = false;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:134:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:135:\t/* attach legacy exclusive prog attachment */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:136:\terr = bpf_prog_attach(prog_fd, cgs[last_cg].fd,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:137:\t\t\t BPF_CGROUP_INET_EGRESS, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:138:\tif (CHECK(err, \"cg_attach_exclusive\", \"errno=%d\\n\", errno))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:139:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:140:\tdetach_legacy = true;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:141:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:142:\t/* attempt to mix in with multi-attach bpf_link */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:143:\ttmp_link = bpf_program__attach_cgroup(skel-\u003eprogs.egress,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:144:\t\t\t\t\t cgs[last_cg].fd);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:145:\tif (!ASSERT_ERR_PTR(tmp_link, \"cg_attach_fail\")) {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:146:\t\tbpf_link__destroy(tmp_link);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:147:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:148:\t}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:149:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:150:\tping_and_check(cg_nr, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:151:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:152:\t/* detach */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:153:\terr = bpf_prog_detach2(prog_fd, cgs[last_cg].fd, BPF_CGROUP_INET_EGRESS);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:154:\tif (CHECK(err, \"cg_detach_legacy\", \"errno=%d\\n\", errno))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:155:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:156:\tdetach_legacy = false;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:157:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:158:\tping_and_check(cg_nr - 1, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:159:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:160:\t/* attach back link-based one */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:161:\tlinks[last_cg] = bpf_program__attach_cgroup(skel-\u003eprogs.egress,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:162:\t\t\t\t\t\t cgs[last_cg].fd);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:163:\tif (!ASSERT_OK_PTR(links[last_cg], \"cg_attach\"))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:164:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:165:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:166:\tping_and_check(cg_nr, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:167:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:168:\t/* check legacy exclusive prog can't be attached */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:169:\terr = bpf_prog_attach(prog_fd, cgs[last_cg].fd,\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:170:\t\t\t BPF_CGROUP_INET_EGRESS, 0);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:171:\tif (CHECK(!err, \"cg_attach_exclusive\", \"unexpected success\")) {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:172:\t\tbpf_prog_detach2(prog_fd, cgs[last_cg].fd, BPF_CGROUP_INET_EGRESS);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:173:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:174:\t}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:175:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:176:\t/* replace BPF programs inside their links for all but first link */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:177:\tfor (i = 1; i \u003c cg_nr; i++) {\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:178:\t\terr = bpf_link__update_program(links[i], skel-\u003eprogs.egress_alt);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:179:\t\tif (CHECK(err, \"prog_upd\", \"link #%d\\n\", i))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:180:\t\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:181:\t}\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:182:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:183:\tping_and_check(1, cg_nr - 1);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:184:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:185:\t/* Attempt program update with wrong expected BPF program */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:186:\tlink_upd_opts.old_prog_fd = bpf_program__fd(skel-\u003eprogs.egress_alt);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:187:\tlink_upd_opts.flags = BPF_F_REPLACE;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:188:\terr = bpf_link_update(bpf_link__fd(links[0]),\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:189:\t\t\t bpf_program__fd(skel-\u003eprogs.egress_alt),\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:190:\t\t\t \u0026link_upd_opts);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:191:\tif (CHECK(err == 0 || errno != EPERM, \"prog_cmpxchg1\",\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:192:\t\t \"unexpectedly succeeded, err %d, errno %d\\n\", err, -errno))\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:193:\t\tgoto cleanup;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:194:\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:195:\t/* Compare-exchange single link program from egress to egress_alt */\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:196:\tlink_upd_opts.old_prog_fd = bpf_program__fd(skel-\u003eprogs.egress);\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:197:\tlink_upd_opts.flags = BPF_F_REPLACE;\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:198:\terr = bpf_link_update(bpf_link__fd(links[0]),\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:199:\t\t\t bpf_program__fd(skel-\u003eprogs.egress_alt),\ntools/testing/selftests/bpf/prog_tests/cgroup_link.c:200:\t\t\t \u0026link_upd_opts);\n\n"
} |
| 17/2 | 2026/11/12 13:14 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39952 output: 37 thoughts: 266 Thoughts: **Analyzing the bpf_link_create Test and Log Handling**
Okay, let's dive into these new tests: `test_cgroup_link_log`, `test_iter_link_log`, and `test_tracing_link_log`. The core concept here seems to be verifying that `bpf_link_create` is properly generating informative verifier log messages and pushing them into the provided user-space log buffer.
Now, I need to understand the specifics of how the logging mechanism works within `bpf_link_create`. Specifically, how does it handle the `log` argument?
Time to look at the source! I'll read the code of `link_create` to identify where and how the `log` is allocated and then used.
Okay, in `kernel/bpf/syscall.c`, lines 5872-5885, I see:
struct bpf_verifier_log *log;
struct bpf_log_attr attr_log;
...
log = bpf_log_attr_create_vlog(&attr_log, attr_common, uattr_common, size_common);
if (IS_ERR(log))
return PTR_ERR(log);
So, it looks like a `bpf_verifier_log` is created using `bpf_log_attr_create_vlog`. I need to figure out what happens with the `log` variable, after this. I will look at the end of the `link_create` function to understand where the variable is cleaned up.
|
| 18/2 | 2026/11/12 13:15 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/syscall.c",
"FirstLine": 5950,
"LineCount": 40
}Results: {
"Contents": "5950:\t\t\tret = sock_map_link_create(attr, prog);\n5951:\t\t\tbreak;\n5952:\t#ifdef CONFIG_NET\n5953:\t\tcase BPF_PROG_TYPE_XDP:\n5954:\t\t\tret = bpf_xdp_link_attach(attr, prog, \u0026extack);\n5955:\t\t\tbreak;\n5956:\t\tcase BPF_PROG_TYPE_SCHED_CLS:\n5957:\t\t\tif (attr-\u003elink_create.attach_type == BPF_TCX_INGRESS ||\n5958:\t\t\t attr-\u003elink_create.attach_type == BPF_TCX_EGRESS)\n5959:\t\t\t\tret = tcx_link_attach(attr, prog);\n5960:\t\t\telse\n5961:\t\t\t\tret = netkit_link_attach(attr, prog);\n5962:\t\t\tbreak;\n5963:\t\tcase BPF_PROG_TYPE_NETFILTER:\n5964:\t\t\tret = bpf_nf_link_attach(attr, prog);\n5965:\t\t\tbreak;\n5966:\t#endif\n5967:\t\tcase BPF_PROG_TYPE_PERF_EVENT:\n5968:\t\tcase BPF_PROG_TYPE_TRACEPOINT:\n5969:\t\t\tret = bpf_perf_link_attach(attr, prog);\n5970:\t\t\tbreak;\n5971:\t\tcase BPF_PROG_TYPE_KPROBE:\n5972:\t\t\tif (attr-\u003elink_create.attach_type == BPF_PERF_EVENT)\n5973:\t\t\t\tret = bpf_perf_link_attach(attr, prog);\n5974:\t\t\telse if (attr-\u003elink_create.attach_type == BPF_TRACE_KPROBE_MULTI ||\n5975:\t\t\t\t attr-\u003elink_create.attach_type == BPF_TRACE_KPROBE_SESSION)\n5976:\t\t\t\tret = bpf_kprobe_multi_link_attach(attr, prog);\n5977:\t\t\telse if (attr-\u003elink_create.attach_type == BPF_TRACE_UPROBE_MULTI ||\n5978:\t\t\t\t attr-\u003elink_create.attach_type == BPF_TRACE_UPROBE_SESSION)\n5979:\t\t\t\tret = bpf_uprobe_multi_link_attach(attr, prog);\n5980:\t\t\tbreak;\n5981:\t\tdefault:\n5982:\t\t\tbpf_log(log, \"Invalid prog type.\\n\");\n5983:\t\t\tret = -EINVAL;\n5984:\t\t}\n5985:\t\n5986:\tout:\n5987:\t\tif (ret \u003c 0) {\n5988:\t\t\tint err;\n5989:\t\n"
} |
| 19/2 | 2026/11/12 13:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41312 output: 37 thoughts: 26 Thoughts: Okay, here's my interpretation of what's going on, thinking through those lines in `kernel/bpf/syscall.c`. **Diving into `kernel/bpf/syscall.c` - Lines 5986-6010** Alright, let's zero in on those specific lines: 5986 through 6010. Immediately, I'm expecting to see a section dealing with the BPF (Berkeley Packet Filter) subsystem, given the file name. The `syscall.c` part tells me this is likely related to how BPF interacts with system calls, which is a crucial interface. So, I'm anticipating some crucial work concerning how the kernel handles requests, likely from user-space, that involve BPF programs. I'm probably looking at function calls involved in the *execution*, rather than the creation or loading, of BPF programs here. Could be context switching, handling arguments passed to BPF functions, error checking at execution time or maybe related to BPF programs related to system calls. I'm keen to spot the key structures being manipulated, probably things like `bpf_prog`, `bpf_insn` or relevant data structures describing the BPF program itself, or its execution state. Maybe also something about how BPF programs interact with other kernel subsystems or the underlying hardware - and potential security implications. I need to keep an eye out for potential performance bottlenecks or security vulnerabilities as well. BPF is powerful, but it's also a gateway into the kernel, so there's always the risk of malicious programs. I'll be particularly watchful for any checks around program verifier, resource limits, and potentially dangerous instructions. This section is likely crucial in the system and I'll need to absorb how this part of the code handles system calls and passes data or results between user-space and the kernel. |
| 20/2 | 2026/11/12 13:15 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/syscall.c",
"FirstLine": 5986,
"LineCount": 30
}Results: {
"Contents": "5986:\tout:\n5987:\t\tif (ret \u003c 0) {\n5988:\t\t\tint err;\n5989:\t\n5990:\t\t\tif (extack._msg)\n5991:\t\t\t\tbpf_log(log, \"%s\\n\", extack._msg);\n5992:\t\n5993:\t\t\terr = bpf_log_attr_finalize(\u0026attr_log, log);\n5994:\t\t\tret = err ? err : ret;\n5995:\t\t\tif (prog)\n5996:\t\t\t\tbpf_prog_put(prog);\n5997:\t\t}\n5998:\t\tkfree(log);\n5999:\t\treturn ret;\n6000:\t}\n6001:\t\n6002:\tstatic int link_update_map(struct bpf_link *link, union bpf_attr *attr)\n6003:\t{\n6004:\t\tstruct bpf_map *new_map, *old_map = NULL;\n6005:\t\tint ret;\n6006:\t\n6007:\t\tnew_map = bpf_map_get(attr-\u003elink_update.new_map_fd);\n6008:\t\tif (IS_ERR(new_map))\n6009:\t\t\treturn PTR_ERR(new_map);\n6010:\t\n6011:\t\tif (attr-\u003elink_update.flags \u0026 BPF_F_REPLACE) {\n6012:\t\t\told_map = bpf_map_get(attr-\u003elink_update.old_map_fd);\n6013:\t\t\tif (IS_ERR(old_map)) {\n6014:\t\t\t\tret = PTR_ERR(old_map);\n6015:\t\t\t\tgoto out_put;\n"
} |
| 21/2 | 2026/11/12 13:15 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42234 output: 35 thoughts: 2537 Thoughts: **Analyzing the Impact of `bpf_log` Additions** Okay, so I need to determine if these changes warrant fuzzing. The key is whether the modifications fall into one of the "non-fuzzable" categories. Specifically, I'm focused on whether the added `bpf_log` calls are "purely decorative logging... that do not alter control flow or data structures." That's the crucial question. My initial thought is that `bpf_log` is a diagnostic tool, like a more specialized version of `pr_err` or `printk`, specifically for BPF link creation. It seems designed to provide *information* about why a link creation might fail, not to fundamentally *change* how the code functions. The core logic remains. Let's dissect this, line by line. * **`cgroup_bpf_link_attach`, `bpf_iter_link_attach`, `bpf_tracing_prog_attach`, and `bpf_tracing_multi_attach`**: In each, the `log` parameter is added, and the code now includes `bpf_log` calls *before* existing `return` statements. My intuition is that these calls are used to log messages to provide more context regarding why an error occurred. The original error conditions (and therefore control flow) remain the same. The return values (e.g., `-EINVAL`) haven't changed. The only modification is the addition of logging *before* the function exits due to a known error. * **`__cgroup_bpf_attach`**: Here, I'm checking for cgroup revision mismatches, hierarchy attachment constraints, attachment flag conflicts, and program count limits. The new `bpf_log` calls are added inside the `if` conditions, but the *conditions* (control flow) are already there. The log message provides an explanation when one of these conditions is true. * **`get_prog_list`**: The changes are similar, and `bpf_log` calls are added for error conditions to provide more context and explain why errors happened. * **`link_create`**: The existing code checks for an invalid attachment type. The added `bpf_log` call provides additional details *before* the existing error return. In every case, the `bpf_log` calls seem to function as enhanced error messages. The `return` statements are still the same. The control flow is *not* being altered, only augmented with informative logging. The `bpf_log` calls seem to align with the "decorative logging" criteria. The code in `tools/` looks like user-space support for the logging functionality, and tests for the log messages. Thus, this also appears to be for user-space, and not within the kernel control flow, so I do not believe this is cause for concern. Based on this analysis, my *opinion* is that the addition of `bpf_log` calls, in this context, falls under "purely decorative logging." The code structure and execution path are *not* being fundamentally changed. The core logic around error detection and handling remains the same. Thus, my *conclusion* is that the addition of `bpf_log` calls should not disqualify this change from fuzzing, because it doesn't change control flow. |
| 22/2 | 2026/11/12 13:16 | tool | grepper |
0mArgs:{
"Expression": "bpf_log\\(log",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "kernel/bpf/verifier.c=2871=static const struct btf_type *find_kfunc_impl_proto(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-2881-\tif (len \u003c 0 || len \u003e= sizeof(buf)) {\nkernel/bpf/verifier.c:2882:\t\tbpf_log(log, \"function name %s%s is too long\\n\",\nkernel/bpf/verifier.c-2883-\t\t\tfunc_name, KF_IMPL_SUFFIX);\n--\nkernel/bpf/verifier.c-2888-\tif (impl_id \u003c= 0) {\nkernel/bpf/verifier.c:2889:\t\tbpf_log(log, \"cannot find function %s in BTF\\n\", buf);\nkernel/bpf/verifier.c-2890-\t\treturn NULL;\n--\nkernel/bpf/verifier.c=23839=btf_attach_func_proto(struct bpf_verifier_log *log, struct btf *btf, u32 func_id)\n--\nkernel/bpf/verifier.c-23864-\tif (implicit == -EINVAL) {\nkernel/bpf/verifier.c:23865:\t\tbpf_log(log, \"kfunc %s has inconsistent KF_IMPLICIT_ARGS\\n\", name);\nkernel/bpf/verifier.c-23866-\t\treturn NULL;\n--\nkernel/bpf/verifier.c=23893=static int flatten_bpf_func_model(struct bpf_verifier_log *log, const char *tname,\n--\nkernel/bpf/verifier.c-23900-\tif (nslots \u003e MAX_BPF_FUNC_ARGS) {\nkernel/bpf/verifier.c:23901:\t\tbpf_log(log, \"The function %s has %u argument slots. Too many.\\n\",\nkernel/bpf/verifier.c-23902-\t\t\ttname, nslots);\n--\nkernel/bpf/verifier.c=23932=int bpf_check_ext_prologue(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-23943-\nkernel/bpf/verifier.c:23944:\tbpf_log(log,\nkernel/bpf/verifier.c-23945-\t\t\"Extension writing packet data cannot replace a function whose callers keep packet pointers\\n\");\n--\nkernel/bpf/verifier.c=23972=static int check_ext_args(struct bpf_verifier_log *log, const struct bpf_prog *prog,\n--\nkernel/bpf/verifier.c-23986-\nkernel/bpf/verifier.c:23987:\t\tbpf_log(log, \"Extension program's argument in R%d is incompatible with original\\n\",\nkernel/bpf/verifier.c-23988-\t\t\ti + 1);\n--\nkernel/bpf/verifier.c=23995=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-24014-\tif (!btf_id) {\nkernel/bpf/verifier.c:24015:\t\tbpf_log(log, \"Tracing programs must provide btf_id\\n\");\nkernel/bpf/verifier.c-24016-\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24019-\tif (!btf) {\nkernel/bpf/verifier.c:24020:\t\tbpf_log(log,\nkernel/bpf/verifier.c-24021-\t\t\t\"Tracing program can only be attached to another program annotated with BTF\\n\");\n--\nkernel/bpf/verifier.c-24025-\tif (!t) {\nkernel/bpf/verifier.c:24026:\t\tbpf_log(log, \"attach_btf_id %u is invalid\\n\", btf_id);\nkernel/bpf/verifier.c-24027-\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24030-\tif (!tname) {\nkernel/bpf/verifier.c:24031:\t\tbpf_log(log, \"attach_btf_id %u doesn't have a name\\n\", btf_id);\nkernel/bpf/verifier.c-24032-\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24041-\t\t !bpf_prog_dev_bound_match(prog, tgt_prog)) {\nkernel/bpf/verifier.c:24042:\t\t\tbpf_log(log, \"Target program bound device mismatch\");\nkernel/bpf/verifier.c-24043-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24047-\t\tif (subprog == -1) {\nkernel/bpf/verifier.c:24048:\t\t\tbpf_log(log, \"Subprog %s doesn't exist\\n\", tname);\nkernel/bpf/verifier.c-24049-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24057-\t\tif (subprog == 0 \u0026\u0026 bpf_prog_has_arena_ctx_arg(tgt_prog)) {\nkernel/bpf/verifier.c:24058:\t\t\tbpf_log(log, \"Cannot attach to a target with arena context arguments\\n\");\nkernel/bpf/verifier.c-24059-\t\t\treturn -EOPNOTSUPP;\n--\nkernel/bpf/verifier.c-24062-\t\tif (subprog \u0026\u0026 aux-\u003earena_stack_size) {\nkernel/bpf/verifier.c:24063:\t\t\tbpf_log(log, \"Cannot attach to a subprog of a program that uses R%d\\n\",\nkernel/bpf/verifier.c-24064-\t\t\t\tBPF_REG_ARENA_SP);\n--\nkernel/bpf/verifier.c-24067-\t\tif (aux-\u003efunc \u0026\u0026 aux-\u003efunc[subprog]-\u003eaux-\u003eexception_cb) {\nkernel/bpf/verifier.c:24068:\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24069-\t\t\t\t\"%s programs cannot attach to exception callback\\n\",\n--\nkernel/bpf/verifier.c-24079-\t\t prog-\u003eexpected_attach_type != BPF_TRACE_FENTRY) {\nkernel/bpf/verifier.c:24080:\t\t\tbpf_log(log, \"Only fentry can attach to %s, which can unwind\\n\", tname);\nkernel/bpf/verifier.c-24081-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24084-\t\tif (aux-\u003efunc \u0026\u0026 aux-\u003efunc[subprog]-\u003eaux-\u003ein_recursion) {\nkernel/bpf/verifier.c:24085:\t\t\tbpf_log(log, \"Cannot attach to %s, which is called in a recursion\\n\", tname);\nkernel/bpf/verifier.c-24086-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24091-\t\t\t conservative) {\nkernel/bpf/verifier.c:24092:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24093-\t\t\t\t\t\"Cannot replace static functions\\n\");\n--\nkernel/bpf/verifier.c-24096-\t\t\tif (!prog-\u003ejit_requested) {\nkernel/bpf/verifier.c:24097:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24098-\t\t\t\t\t\"Extension programs should be JITed\\n\");\n--\nkernel/bpf/verifier.c-24105-\t\t\tif (tgt_prog-\u003etype == BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE) {\nkernel/bpf/verifier.c:24106:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24107-\t\t\t\t\t\"Cannot extend a writable raw tracepoint program\\n\");\n--\nkernel/bpf/verifier.c-24110-\t\t\tif (!func_has_rcu_read_lock(tgt_prog, subprog)) {\nkernel/bpf/verifier.c:24111:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24112-\t\t\t\t\t\"Cannot extend a function that runs without RCU read lock\\n\");\n--\nkernel/bpf/verifier.c-24118-\t\t\tif (prog-\u003eaux-\u003echanges_pkt_data \u0026\u0026 !tgt_changes_pkt_data) {\nkernel/bpf/verifier.c:24119:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24120-\t\t\t\t\t\"Extension program changes packet data, while original does not\\n\");\n--\nkernel/bpf/verifier.c-24130-\t\t\tif (prog-\u003eaux-\u003emight_sleep \u0026\u0026 !tgt_might_sleep) {\nkernel/bpf/verifier.c:24131:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24132-\t\t\t\t\t\"Extension program may sleep, while original does not\\n\");\n--\nkernel/bpf/verifier.c-24136-\t\t\tif (prog-\u003eaux-\u003ecan_unwind \u0026\u0026 !tgt_can_unwind) {\nkernel/bpf/verifier.c:24137:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24138-\t\t\t\t\t\"Extension program can unwind, while original does not\\n\");\n--\nkernel/bpf/verifier.c-24142-\t\tif (!tgt_prog-\u003ejited) {\nkernel/bpf/verifier.c:24143:\t\t\tbpf_log(log, \"Can attach to only JITed progs\\n\");\nkernel/bpf/verifier.c-24144-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24152-\t\t\t\t */\nkernel/bpf/verifier.c:24153:\t\t\t\tbpf_log(log, \"Cannot nest tracing program attach more than once\\n\");\nkernel/bpf/verifier.c-24154-\t\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24161-\t\t\t */\nkernel/bpf/verifier.c:24162:\t\t\tbpf_log(log, \"Cannot recursively attach\\n\");\nkernel/bpf/verifier.c-24163-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24186-\t\t\t */\nkernel/bpf/verifier.c:24187:\t\t\tbpf_log(log, \"Cannot extend fentry/fexit/fsession\\n\");\nkernel/bpf/verifier.c-24188-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24191-\t\tif (prog_extension) {\nkernel/bpf/verifier.c:24192:\t\t\tbpf_log(log, \"Cannot replace kernel functions\\n\");\nkernel/bpf/verifier.c-24193-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24199-\t\tif (tgt_prog) {\nkernel/bpf/verifier.c:24200:\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24201-\t\t\t\t\"Only FENTRY/FEXIT/FSESSION progs are attachable to another BPF prog\\n\");\n--\nkernel/bpf/verifier.c-24204-\t\tif (!btf_type_is_typedef(t)) {\nkernel/bpf/verifier.c:24205:\t\t\tbpf_log(log, \"attach_btf_id %u is not a typedef\\n\",\nkernel/bpf/verifier.c-24206-\t\t\t\tbtf_id);\n--\nkernel/bpf/verifier.c-24209-\t\tif (strncmp(prefix, tname, sizeof(prefix) - 1)) {\nkernel/bpf/verifier.c:24210:\t\t\tbpf_log(log, \"attach_btf_id %u points to wrong type name %s\\n\",\nkernel/bpf/verifier.c-24211-\t\t\t\tbtf_id, tname);\n--\nkernel/bpf/verifier.c-24222-\t\tif (prog-\u003esleepable \u0026\u0026 !tracepoint_is_faultable(btp-\u003etp)) {\nkernel/bpf/verifier.c:24223:\t\t\tbpf_log(log, \"Sleepable program cannot attach to non-faultable tracepoint %s\\n\",\nkernel/bpf/verifier.c-24224-\t\t\t\ttname);\n--\nkernel/bpf/verifier.c-24235-\t\tif (!fname || ret \u003c 0) {\nkernel/bpf/verifier.c:24236:\t\t\tbpf_log(log, \"Cannot find btf of tracepoint template, fall back to %s%s.\\n\",\nkernel/bpf/verifier.c-24237-\t\t\t\tprefix, tname);\n--\nkernel/bpf/verifier.c-24256-\t\tif (!btf_type_is_func(t)) {\nkernel/bpf/verifier.c:24257:\t\t\tbpf_log(log, \"attach_btf_id %u is not a function\\n\",\nkernel/bpf/verifier.c-24258-\t\t\t\tbtf_id);\n--\nkernel/bpf/verifier.c-24283-\t\t !bpf_jit_supports_fsession()) {\nkernel/bpf/verifier.c:24284:\t\t\tbpf_log(log, \"JIT does not support fsession\\n\");\nkernel/bpf/verifier.c-24285-\t\t\treturn -EOPNOTSUPP;\n--\nkernel/bpf/verifier.c-24287-\t\tif (!btf_type_is_func(t)) {\nkernel/bpf/verifier.c:24288:\t\t\tbpf_log(log, \"attach_btf_id %u is not a function\\n\",\nkernel/bpf/verifier.c-24289-\t\t\t\tbtf_id);\n--\nkernel/bpf/verifier.c-24311-\t\t\tif (tgt_prog-\u003eaux-\u003efunc_info_aux[subprog].stack_args) {\nkernel/bpf/verifier.c:24312:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24313-\t\t\t\t\t\"Cannot attach to static function %s: unreliable BTF and stack arguments\\n\",\n--\nkernel/bpf/verifier.c-24332-\t\t attach_uses_trampoline_retval(prog-\u003eexpected_attach_type)) {\nkernel/bpf/verifier.c:24333:\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24334-\t\t\t\t\"Attach to function %s with a \u003e8 byte return value is not supported for this attach type\\n\",\n--\nkernel/bpf/verifier.c-24366-\t\t\t\tmodule_put(mod);\nkernel/bpf/verifier.c:24367:\t\t\t\tbpf_log(log,\nkernel/bpf/verifier.c-24368-\t\t\t\t\t\"The address of function %s cannot be found\\n\",\n--\nkernel/bpf/verifier.c-24377-\t\t\t\tmodule_put(mod);\nkernel/bpf/verifier.c:24378:\t\t\t\tbpf_log(log, \"%s is not sleepable\\n\", tname);\nkernel/bpf/verifier.c-24379-\t\t\t\treturn ret;\n--\nkernel/bpf/verifier.c-24383-\t\t\t\tmodule_put(mod);\nkernel/bpf/verifier.c:24384:\t\t\t\tbpf_log(log, \"can't modify return codes of BPF programs\\n\");\nkernel/bpf/verifier.c-24385-\t\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c-24392-\t\t\t\tmodule_put(mod);\nkernel/bpf/verifier.c:24393:\t\t\t\tbpf_log(log, \"%s() is not modifiable\\n\", tname);\nkernel/bpf/verifier.c-24394-\t\t\t\treturn ret;\n"
} |
| 23/2 | 2026/11/12 13:16 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49676 output: 33 thoughts: 6896 Thoughts: **My Analysis of the BPF Link Attach Patch** Alright, let's break this down. From my perspective, as an expert in this field, the changes presented in this patch boil down to essentially one thing: improving the diagnostic logging within the BPF link creation and attachment process. Initially, `bpf_check_attach_target` already took a `log` but did nothing, and now it's being plumbed down from `link_create`. Specifically, the code modifications seem laser-focused on providing *better* error messages to the user when a link attachment fails. Everywhere this is happening, the essential `bpf_log(log, ...)` call is being used to communicate why an attachment failed, such as invalid target FDs, flags, or other misconfigurations, which are not new error paths and continue to return the same errors as before. This allows the user to debug the problem much faster. The important thing to note is that this function does *absolutely* nothing if the `log` pointer is NULL; that is, no change in behavior is seen if it isn't set, as in many cases, it remains `NULL`. A thorough review of every single file, shows a pattern of introducing or propagating the `struct bpf_verifier_log *log` pointer. The vast majority of the changes are simply the addition of `bpf_log(log, "...")` calls *before* existing `return` statements or moving existing `return` statements into separate `if` blocks to print unique messages for each failure case. The only alterations to existing control flow are the splitting of compound `if` statements into multiple `if` statements to provide distinct error messages. The return value, however, is the exact same. This, in my estimation, is purely for the benefit of the user, as the conditions which would return errors are the same as before. The core of my assessment rests on whether these changes are "purely decorative logging that do not alter control flow or data structures," because that would exclude it from my fuzzing regime. No kernel data structures are being changed, at all. Function signatures *are* being updated to pass the `struct bpf_verifier_log *log`, but the *use* of the `log` variable is limited to `bpf_log(log, "...")` calls. There is no possibility that this logging causes a crash or corruption since `bpf_log` is well-established as a non-fatal logging function. Based on this comprehensive analysis, which includes a line-by-line inspection of all the relevant code and a meticulous review against the relevant criteria, I conclude that these changes *strictly* fall under the category of "purely decorative logging that does not alter control flow or data structures". The logging statements do not affect any kernel control flow or data structures, nor do they touch any core subsystem logic or user-facing functionality beyond this descriptive logging. Furthermore, the testing changes in the `tools/testing/selftests` are also user-space. Therefore, I'd classify this as a patch that, while beneficial for diagnostics, *does not* warrant my focused fuzzing attention, according to the stated criteria. |
| 24/2 | 2026/11/12 13:17 | tool | grepper |
0mArgs:{
"Expression": "\\blog\\b",
"PathPrefixes": [
"kernel/bpf/verifier.c"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 536 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (1 files in total):\nkernel/bpf/verifier.c:122\n\nkernel/bpf/verifier.c=317=__printf(2, 3) static void verbose(void *private_data, const char *fmt, ...)\n--\nkernel/bpf/verifier.c-321-\nkernel/bpf/verifier.c:322:\tif (!bpf_verifier_log_needed(\u0026env-\u003elog))\nkernel/bpf/verifier.c-323-\t\treturn;\n--\nkernel/bpf/verifier.c-325-\tva_start(args, fmt);\nkernel/bpf/verifier.c:326:\tbpf_verifier_vlog(\u0026env-\u003elog, fmt, args);\nkernel/bpf/verifier.c-327-\tva_end(args);\n--\nkernel/bpf/verifier.c=2849=static struct btf *find_kfunc_desc_btf_cached(struct bpf_verifier_env *env, s16 offset)\n--\nkernel/bpf/verifier.c-2870-\nkernel/bpf/verifier.c:2871:static const struct btf_type *find_kfunc_impl_proto(struct bpf_verifier_log *log,\nkernel/bpf/verifier.c-2872-\t\t\t\t\t\t struct btf *btf,\n--\nkernel/bpf/verifier.c-2881-\tif (len \u003c 0 || len \u003e= sizeof(buf)) {\nkernel/bpf/verifier.c:2882:\t\tbpf_log(log, \"function name %s%s is too long\\n\",\nkernel/bpf/verifier.c-2883-\t\t\tfunc_name, KF_IMPL_SUFFIX);\n--\nkernel/bpf/verifier.c-2888-\tif (impl_id \u003c= 0) {\nkernel/bpf/verifier.c:2889:\t\tbpf_log(log, \"cannot find function %s in BTF\\n\", buf);\nkernel/bpf/verifier.c-2890-\t\treturn NULL;\n--\nkernel/bpf/verifier.c=2898=static int fetch_kfunc_meta(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2940-\tif (kfunc_flags \u0026\u0026 (*kfunc_flags \u0026 KF_IMPLICIT_ARGS))\nkernel/bpf/verifier.c:2941:\t\tfunc_proto = find_kfunc_impl_proto(\u0026env-\u003elog, btf, func_name);\nkernel/bpf/verifier.c-2942-\telse\n--\nkernel/bpf/verifier.c=2964=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-3047-\tif (bpf_dev_bound_kfunc_id(func_id)) {\nkernel/bpf/verifier.c:3048:\t\terr = bpf_dev_bound_kfunc_check(\u0026env-\u003elog, prog_aux);\nkernel/bpf/verifier.c-3049-\t\tif (err)\n--\nkernel/bpf/verifier.c-3052-\nkernel/bpf/verifier.c:3053:\terr = btf_distill_func_proto(\u0026env-\u003elog, kfunc.btf, kfunc.proto, kfunc.name, \u0026func_model);\nkernel/bpf/verifier.c-3054-\tif (err)\n--\nkernel/bpf/verifier.c=3099=static int add_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-3177-\nkernel/bpf/verifier.c:3178:\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\nkernel/bpf/verifier.c-3179-\t\tfor (i = 0; i \u003c env-\u003esubprog_cnt; i++)\n--\nkernel/bpf/verifier.c=3396=static int sort_subprogs_topo(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-3480-\nkernel/bpf/verifier.c:3481:\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\nkernel/bpf/verifier.c-3482-\t\tfor (i = 0; i \u003c cnt; i++)\n--\nkernel/bpf/verifier.c=4691=static int map_kptr_match_type(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-4759-\t */\nkernel/bpf/verifier.c:4760:\tif (!btf_struct_ids_match(\u0026env-\u003elog, reg-\u003ebtf, reg-\u003ebtf_id, reg-\u003evar_off.value,\nkernel/bpf/verifier.c-4761-\t\t\t\t kptr_field-\u003ekptr.btf, kptr_field-\u003ekptr.btf_id,\n--\nkernel/bpf/verifier.c=6731=static bool type_is_rcu(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6739-\nkernel/bpf/verifier.c:6740:\treturn btf_nested_type_is_trusted(\u0026env-\u003elog, reg, field_name, btf_id, \"__safe_rcu\");\nkernel/bpf/verifier.c-6741-}\n--\nkernel/bpf/verifier.c=6743=static bool type_is_rcu_or_null(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6750-\nkernel/bpf/verifier.c:6751:\treturn btf_nested_type_is_trusted(\u0026env-\u003elog, reg, field_name, btf_id, \"__safe_rcu_or_null\");\nkernel/bpf/verifier.c-6752-}\n--\nkernel/bpf/verifier.c=6754=static bool type_is_trusted(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6766-\nkernel/bpf/verifier.c:6767:\treturn btf_nested_type_is_trusted(\u0026env-\u003elog, reg, field_name, btf_id, \"__safe_trusted\");\nkernel/bpf/verifier.c-6768-}\n--\nkernel/bpf/verifier.c=6770=static bool type_is_trusted_or_null(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6778-\nkernel/bpf/verifier.c:6779:\treturn btf_nested_type_is_trusted(\u0026env-\u003elog, reg, field_name, btf_id,\nkernel/bpf/verifier.c-6780-\t\t\t\t\t \"__safe_trusted_or_null\");\n--\nkernel/bpf/verifier.c=6822=static int check_ptr_to_btf_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6898-\t\t}\nkernel/bpf/verifier.c:6899:\t\tret = env-\u003eops-\u003ebtf_struct_access(\u0026env-\u003elog, reg, off, size);\nkernel/bpf/verifier.c-6900-\t\tif (ret \u003c 0)\n--\nkernel/bpf/verifier.c-6924-\nkernel/bpf/verifier.c:6925:\t\tret = btf_struct_access(\u0026env-\u003elog, reg, off, size, atype, \u0026btf_id, \u0026flag, \u0026field_name);\nkernel/bpf/verifier.c-6926-\t}\n--\nkernel/bpf/verifier.c=7018=static int check_ptr_to_map_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-7069-\t\treturn ret;\nkernel/bpf/verifier.c:7070:\tret = btf_struct_access(\u0026env-\u003elog, \u0026map_reg, off, size, atype, \u0026btf_id, \u0026flag, NULL);\nkernel/bpf/verifier.c-7071-\tif (ret \u003c 0)\n--\nkernel/bpf/verifier.c=7445=static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-7542-\t\t\t.is_ldsx = is_ldsx,\nkernel/bpf/verifier.c:7543:\t\t\t.log = \u0026env-\u003elog,\nkernel/bpf/verifier.c-7544-\t\t};\n--\nkernel/bpf/verifier.c=9830=static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 prev_slot,\n--\nkernel/bpf/verifier.c-10083-\t\tif (is_bpf_cast_to_kern_ctx_kfunc(meta)) {\nkernel/bpf/verifier.c:10084:\t\t\terr = get_kern_ctx_btf_id(\u0026env-\u003elog, resolve_prog_type(env-\u003eprog));\nkernel/bpf/verifier.c-10085-\t\t\tif (err \u003c 0)\n--\nkernel/bpf/verifier.c=11808=int bpf_flow_return(struct bpf_verifier_env *env, struct bpf_verifier_state *caller,\n--\nkernel/bpf/verifier.c-11880-\t callee-\u003eentry_preempt_locks \u003c caller_preempt) {\nkernel/bpf/verifier.c:11881:\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\nkernel/bpf/verifier.c-11882-\t\t\tverbose(env, \"func#%d releases what its caller holds at insn %d\\n\",\n--\nkernel/bpf/verifier.c=11916=static int check_static_func_call(struct bpf_verifier_env *env, int subprog,\n--\nkernel/bpf/verifier.c-11965-\nkernel/bpf/verifier.c:11966:\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL) {\nkernel/bpf/verifier.c-11967-\t\tverbose(env, \"caller:\\n\");\n--\nkernel/bpf/verifier.c=11976=static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-12028-\nkernel/bpf/verifier.c:12029:\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL)\nkernel/bpf/verifier.c-12030-\t\t\tverbose(env, \"Func#%d ('%s') is global and assumed valid.\\n\",\n--\nkernel/bpf/verifier.c=12618=static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)\n--\nkernel/bpf/verifier.c-12712-\nkernel/bpf/verifier.c:12713:\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL) {\nkernel/bpf/verifier.c-12714-\t\tverbose(env, \"returning from callee:\\n\");\n--\nkernel/bpf/verifier.c=13102=static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-13257-\t\t\tcur_func(env)-\u003ecallback_depth = 0;\nkernel/bpf/verifier.c:13258:\t\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\nkernel/bpf/verifier.c-13259-\t\t\t\tverbose(env, \"frame%d bpf_loop iteration limit reached\\n\",\n--\nkernel/bpf/verifier.c=14484=get_kfunc_arg_type(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\n--\nkernel/bpf/verifier.c-14556-\t\targ_type = ARG_PTR_TO_CTX;\nkernel/bpf/verifier.c:14557:\telse if (btf_is_prog_ctx_type(\u0026env-\u003elog, meta-\u003ebtf, t, resolve_prog_type(env-\u003eprog), arg))\nkernel/bpf/verifier.c-14558-\t\targ_type = ARG_PTR_TO_CTX;\n--\nkernel/bpf/verifier.c=14789=static int process_arg_ptr_to_btf_id(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-14832-\tif ((arg_type_is_release(arg_type) \u0026\u0026 !is_helper_call(meta, BPF_FUNC_sk_release)) ||\nkernel/bpf/verifier.c:14833:\t (is_kfunc(meta) \u0026\u0026 btf_type_ids_nocast_alias(\u0026env-\u003elog, reg_btf, reg_btf_id,\nkernel/bpf/verifier.c-14834-\t\t\t\t\t\t arg_btf, arg_btf_id)))\n--\nkernel/bpf/verifier.c-14841-\nkernel/bpf/verifier.c:14842:\tstruct_same = btf_struct_ids_match(\u0026env-\u003elog, reg_btf, reg_btf_id,\nkernel/bpf/verifier.c-14843-\t\t\t\t\t reg-\u003evar_off.value, arg_btf, arg_btf_id,\n--\nkernel/bpf/verifier.c=15307=__process_kf_arg_ptr_to_graph_node(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15345-\tt = btf_type_by_id(reg-\u003ebtf, reg-\u003ebtf_id);\nkernel/bpf/verifier.c:15346:\tif (!btf_struct_ids_match(\u0026env-\u003elog, reg-\u003ebtf, reg-\u003ebtf_id, 0, field-\u003egraph_root.btf,\nkernel/bpf/verifier.c-15347-\t\t\t\t field-\u003egraph_root.value_btf_id, true,\n--\nkernel/bpf/verifier.c=15727=static bool try_btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/verifier.c-15729-\tstruct bpf_prog *prog = env-\u003eprog;\nkernel/bpf/verifier.c:15730:\tu32 log_level = env-\u003elog.level;\nkernel/bpf/verifier.c-15731-\tint err;\n--\nkernel/bpf/verifier.c-15735-\nkernel/bpf/verifier.c:15736:\tenv-\u003elog.level = 0;\nkernel/bpf/verifier.c-15737-\terr = btf_prepare_func_args(env, subprog);\nkernel/bpf/verifier.c:15738:\tenv-\u003elog.level = log_level;\nkernel/bpf/verifier.c-15739-\treturn !err;\n--\nkernel/bpf/verifier.c=19686=static int check_cond_jmp_op(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19790-\t\t}\nkernel/bpf/verifier.c:19791:\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL)\nkernel/bpf/verifier.c-19792-\t\t\tprint_insn_state(env, this_branch, this_branch-\u003ecurframe);\n--\nkernel/bpf/verifier.c-19805-\t\t}\nkernel/bpf/verifier.c:19806:\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL)\nkernel/bpf/verifier.c-19807-\t\t\tprint_insn_state(env, this_branch, this_branch-\u003ecurframe);\n--\nkernel/bpf/verifier.c-19901-\t}\nkernel/bpf/verifier.c:19902:\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL)\nkernel/bpf/verifier.c-19903-\t\tprint_insn_state(env, this_branch, this_branch-\u003ecurframe);\n--\nkernel/bpf/verifier.c=21237=static int loop_stack_push(struct bpf_verifier_env *env, bool *pushed)\n--\nkernel/bpf/verifier.c-21288-\t\tloop_stack[cnt].guarded = aux[h].loop-\u003eguarded;\nkernel/bpf/verifier.c:21289:\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\nkernel/bpf/verifier.c-21290-\t\t\tverbose(env, \"entering loop %d\\n\", h);\n--\nkernel/bpf/verifier.c=21310=static int loop_stack_pop(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-21332-pop:\nkernel/bpf/verifier.c:21333:\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\nkernel/bpf/verifier.c-21334-\t\tfor (i = frame-\u003eloop_stack_cnt - 1; i \u003e= new_cnt; i--)\n--\n\n"
} |
| 25/2 | 2026/11/12 13:17 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 61830 output: 140 thoughts: 882 Thoughts: **WorthFuzzing Evaluation: Negative Confirmation** Okay, let's break this down systematically. My immediate concern is whether this patch series warrants further fuzzing. To determine that, I need to meticulously evaluate the scope and nature of the modifications. First, I checked `kernel/bpf/verifier.c`, specifically lines 23995-24400. I wanted to see how `bpf_check_attach_target` uses the `struct bpf_verifier_log *log` argument. The only uses are calls to `bpf_log()`, `bpf_check_ext_prologue()`, `check_ext_args()`, and `btf_distill_func_proto()`. Importantly, `log` is *only* passed to `bpf_log()` within those functions. There are no conditional branches or modifications of data structures based on the `log` pointer or its contents. This suggests the logging is purely informational, which is a good sign. Next, I meticulously compared the patch series against the "Return WorthFuzzing=false" criteria outlined in Section 2. I need to make sure this meets the negative criteria for not fuzzing. My analysis is as follows: The modified code falls into two specific categories: 1. **User-space and self-tests:** This includes modifications in the `tools/lib/bpf` directory, as well as several selftest directories. These changes are isolated from the kernel and don't directly impact the compiled kernel image. 2. **Purely decorative logging:** I've confirmed that changes are primarily related to adding the `struct bpf_verifier_log *log` parameter to various link attachment functions (across `include/linux/*` and `kernel/bpf/*` directories) and calling `bpf_log()` before existing error returns. These `bpf_log` calls are *strictly* for diagnostic purposes and don't alter control flow or data structures. Critically, these conditional splits preserve the original return codes and conditions. Therefore, this patch series *strictly* aligns with the "negative" criteria for skipping fuzzing: all modifications are either in user-space tools and tests, or purely decorative logging within existing error paths. I need to be absolutely sure. Let me double-check for anything I might have missed: * Are there new assertions? No `WARN_ON`, `BUG_ON`, or anything like that. * Any memory allocation, state management, locking, or reference counting changes? Nothing. * Data structure modifications within the kernel? Nope. The `struct bpf_verifier_log *log` is passed as a function argument, nothing more. * Control flow changes? Absolutely none. The error checks are the same. Given this thorough review, I can confidently conclude that `WorthFuzzing` is `false`. The changes are limited to user-space tools and logging, and don't impact the kernel's critical execution paths. With this certainty, I'll go ahead and set the results accordingly. |
| 26/2 | 2026/11/12 13:17 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch series only updates user-space tooling/selftests (tools/lib/bpf and tools/testing/selftests) and adds purely decorative diagnostic verifier logging (bpf_log) to existing failure paths across BPF link attachment functions (cgroup_bpf_link_attach, bpf_tracing_prog_attach, bpf_iter_link_attach, and bpf_tracing_multi_attach). No kernel data structures, control flow, error returns, or runtime assertions are altered.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch series only updates user-space tooling/selftests (tools/lib/bpf and tools/testing/selftests) and adds purely decorative diagnostic verifier logging (bpf_log) to existing failure paths across BPF link attachment functions (cgroup_bpf_link_attach, bpf_tracing_prog_attach, bpf_iter_link_attach, and bpf_tracing_multi_attach). No kernel data structures, control flow, error returns, or runtime assertions are altered.",
"WorthFuzzing": false
} |
| 27/1 | 2026/11/12 13:17 | 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) |
|---|