mbox series

[bpf-next,v2,0/2] Fix cgroup attach flags being assigned to effective progs

Message ID 20220908145304.3436139-1-pulehui@huaweicloud.com (mailing list archive)
Headers show
Series Fix cgroup attach flags being assigned to effective progs | expand

Message

Pu Lehui Sept. 8, 2022, 2:53 p.m. UTC
From: Pu Lehui <pulehui@huawei.com>

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

For cg1, obviously, the attach flags of prog6 and prog13 can not be
OVERRIDE, and the attach flags of prog6 and prog13 is meaningless for
cg1. We only need to care the attach flags of prog which attached to
cg1, other progs attach flags should be omit. After these patches,
the above situation will show as bellow:

$ 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                   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

v2:
- Limit prog_cnt to avoid overflow. (John)
- Add more detail message.

v1:
https://lore.kernel.org/bpf/20220820120234.2121044-1-pulehui@huawei.com

Pu Lehui (2):
  bpf, cgroup: Fix attach flags being assigned to effective progs
  bpftool: Fix cgroup attach flags being assigned to effective progs

 kernel/bpf/cgroup.c        | 5 ++++-
 tools/bpf/bpftool/cgroup.c | 9 +++------
 2 files changed, 7 insertions(+), 7 deletions(-)

Comments

Stanislav Fomichev Sept. 8, 2022, 5:28 p.m. UTC | #1
On 09/08, Pu Lehui wrote:
> From: Pu Lehui <pulehui@huawei.com>

> 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

> For cg1, obviously, the attach flags of prog6 and prog13 can not be
> OVERRIDE, and the attach flags of prog6 and prog13 is meaningless for
> cg1. We only need to care the attach flags of prog which attached to
> cg1, other progs attach flags should be omit. After these patches,
> the above situation will show as bellow:

> $ 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                   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

> v2:
> - Limit prog_cnt to avoid overflow. (John)
> - Add more detail message.

John also raised a good question in v1: the flags don't seem to
make sense when requesting effective list. So maybe not export them
at all?

> v1:
> https://lore.kernel.org/bpf/20220820120234.2121044-1-pulehui@huawei.com

> Pu Lehui (2):
>    bpf, cgroup: Fix attach flags being assigned to effective progs
>    bpftool: Fix cgroup attach flags being assigned to effective progs

>   kernel/bpf/cgroup.c        | 5 ++++-
>   tools/bpf/bpftool/cgroup.c | 9 +++------
>   2 files changed, 7 insertions(+), 7 deletions(-)

> --
> 2.25.1
Martin KaFai Lau Sept. 8, 2022, 7:13 p.m. UTC | #2
On 9/8/22 10:28 AM, sdf@google.com wrote:
> On 09/08, Pu Lehui wrote:
>> From: Pu Lehui <pulehui@huawei.com>
> 
>> 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
> 
>> For cg1, obviously, the attach flags of prog6 and prog13 can not be
>> OVERRIDE, and the attach flags of prog6 and prog13 is meaningless for
>> cg1. We only need to care the attach flags of prog which attached to
>> cg1, other progs attach flags should be omit. After these patches,
>> the above situation will show as bellow:
> 
>> $ 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                   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
> 
>> v2:
>> - Limit prog_cnt to avoid overflow. (John)
>> - Add more detail message.
> 
> John also raised a good question in v1: the flags don't seem to
> make sense when requesting effective list. So maybe not export them
> at all?
+1. not exporting them for 'effective' listing makes sense.

This seems to be the day one behavior instead of the recent 
prog_attach_flags changes? so bpf-next makes sense also.
Pu Lehui Sept. 13, 2022, 1:35 p.m. UTC | #3
On 2022/9/9 1:28, sdf@google.com wrote:
> On 09/08, Pu Lehui wrote:
>> From: Pu Lehui <pulehui@huawei.com>
> 
>> 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
> 
>> For cg1, obviously, the attach flags of prog6 and prog13 can not be
>> OVERRIDE, and the attach flags of prog6 and prog13 is meaningless for
>> cg1. We only need to care the attach flags of prog which attached to
>> cg1, other progs attach flags should be omit. After these patches,
>> the above situation will show as bellow:
> 
>> $ 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                   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
> 
>> v2:
>> - Limit prog_cnt to avoid overflow. (John)
>> - Add more detail message.
> 
> John also raised a good question in v1: the flags don't seem to
> make sense when requesting effective list. So maybe not export them
> at all?
> 

Misunderstood John's meaning. will remove the attach flags when query 
with EFFECTIVE in next version. Thanks all.

>> v1:
>> https://lore.kernel.org/bpf/20220820120234.2121044-1-pulehui@huawei.com
> 
>> Pu Lehui (2):
>>    bpf, cgroup: Fix attach flags being assigned to effective progs
>>    bpftool: Fix cgroup attach flags being assigned to effective progs
> 
>>   kernel/bpf/cgroup.c        | 5 ++++-
>>   tools/bpf/bpftool/cgroup.c | 9 +++------
>>   2 files changed, 7 insertions(+), 7 deletions(-)
> 
>> -- 
>> 2.25.1
>