• Pu Lehui's avatar
    bpftool: Fix wrong cgroup attach flags being assigned to effective progs · bdcee1b0
    Pu Lehui authored
    When root-cgroup attach multi progs and sub-cgroup attach a override prog,
    bpftool will display incorrectly for the attach flags of the sub-cgroup’s
    effective progs:
    
    $ bpftool cgroup tree /sys/fs/cgroup effective
    CgroupPath
    ID       AttachType      AttachFlags     Name
    /sys/fs/cgroup
    6        cgroup_sysctl   multi           sysctl_tcp_mem
    13       cgroup_sysctl   multi           sysctl_tcp_mem
    /sys/fs/cgroup/cg1
    20       cgroup_sysctl   override        sysctl_tcp_mem
    6        cgroup_sysctl   override        sysctl_tcp_mem <- wrong
    13       cgroup_sysctl   override        sysctl_tcp_mem <- wrong
    /sys/fs/cgroup/cg1/cg2
    20       cgroup_sysctl                   sysctl_tcp_mem
    6        cgroup_sysctl                   sysctl_tcp_mem
    13       cgroup_sysctl                   sysctl_tcp_mem
    
    Attach flags is only valid for attached progs of this layer cgroup,
    but not for effective progs. For querying with EFFECTIVE flags,
    exporting attach flags does not make sense. So let's remove the
    AttachFlags field and the associated logic. After this patch, the
    above effective cgroup tree will show as bellow:
    
    $ bpftool cgroup tree /sys/fs/cgroup effective
    CgroupPath
    ID       AttachType      Name
    /sys/fs/cgroup
    6        cgroup_sysctl   sysctl_tcp_mem
    13       cgroup_sysctl   sysctl_tcp_mem
    /sys/fs/cgroup/cg1
    20       cgroup_sysctl   sysctl_tcp_mem
    6        cgroup_sysctl   sysctl_tcp_mem
    13       cgroup_sysctl   sysctl_tcp_mem
    /sys/fs/cgroup/cg1/cg2
    20       cgroup_sysctl   sysctl_tcp_mem
    6        cgroup_sysctl   sysctl_tcp_mem
    13       cgroup_sysctl   sysctl_tcp_mem
    
    Fixes: b79c9fc9 ("bpf: implement BPF_PROG_QUERY for BPF_LSM_CGROUP")
    Fixes: a98bf573 ("tools: bpftool: add support for reporting the effective cgroup progs")
    Signed-off-by: default avatarPu Lehui <pulehui@huawei.com>
    Link: https://lore.kernel.org/r/20220921104604.2340580-3-pulehui@huaweicloud.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
    bdcee1b0
cgroup.c 14.6 KB