Attach flags is only valid for attached progs of this layer cgroup, but not for effective progs. We know that the attached progs is at the beginning of the effective progs array, so we can just populate the elements in front of the prog_attach_flags array. Signed-off-by: Pu Lehui <pulehui@xxxxxxxxxx> --- kernel/bpf/cgroup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 59b7eb60d5b4..9adf72e99907 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1091,11 +1091,14 @@ static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, } if (prog_attach_flags) { + int progs_cnt = prog_list_length(&cgrp->bpf.progs[atype]); flags = cgrp->bpf.flags[atype]; - for (i = 0; i < cnt; i++) + /* attach flags only for attached progs, but not effective progs */ + for (i = 0; i < progs_cnt; i++) if (copy_to_user(prog_attach_flags + i, &flags, sizeof(flags))) return -EFAULT; + prog_attach_flags += cnt; } -- 2.25.1