Re: [PATCH bpf-next v3 4/9] bpf: Add log support for cgroup prog link_create

From: bot+bpf-ci

Date: Mon Nov 23 2026 - 11:04:55 EST


> bpf: Add log support for cgroup prog link_create

TL;DR: The new bpf_log() calls in cgroup attach run under cgroup_mutex and
cgroup_bpf_mutex, so a copy_to_user() fault on the user log buffer may stall
other cgroup operations. Consider logging after unlock.

> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c

[ ... ]

> @@ -1045,23 +1060,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;
> + }

[ ... ]

> @@ -1143,13 +1168,14 @@ static int cgroup_bpf_attach(struct cgroup *cgrp,
> cgroup_bpf_lock_hierarchy();
> ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags,
> - id_or_fd, revision);
> + id_or_fd, revision, log);
> cgroup_bpf_unlock_hierarchy();
> return ret;

Can these bpf_log() calls block other cgroup users while the locks are
held?

cgroup_bpf_attach() takes cgroup_mutex and cgroup_bpf_mutex through
cgroup_bpf_lock_hierarchy() before calling __cgroup_bpf_attach(), and
the new messages are emitted from inside it (and from get_prog_list()
via insert_pl_to_hlist()):

cgroup_bpf_attach()
cgroup_bpf_lock_hierarchy()
__cgroup_bpf_attach()
bpf_log()
bpf_verifier_vlog()
copy_to_user(log->ubuf + ..., log->kbuf, ...)

log->ubuf is the user supplied log_buf, so if that page is not resident
(swapped out, or backed by FUSE or userfaultfd), copy_to_user() can sleep
in the fault for as long as the caller chooses. While it sleeps,
cgroup_mutex and cgroup_bpf_mutex remain held, so cgroup mkdir/rmdir,
migration, BPF attach/detach, BPF_PROG_QUERY and the cgroup bpf release
work would all wait.

Commit 40aec6bab02e ("bpf, cgroup: Protect cgroup_bpf state with its own
mutex") split these paths out from cgroup_mutex to avoid hung tasks, and
before this patch the attach path did not touch user memory under these
locks.

This isn't a lock ordering problem, since cgroup_mutex -> mmap_lock
already exists, but would it be better to record the message and emit it
from cgroup_bpf_link_attach() after cgroup_bpf_unlock_hierarchy()?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45209424655