Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7635213rwn; Wed, 14 Sep 2022 01:49:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6pgtW/BfvkJ0RDoeZVm639VDGw6wa5a7uGGu87v8KF923nrVCyhpcAmNXNTzhzC81bahEC X-Received: by 2002:a17:90b:1c8a:b0:1fe:1536:5617 with SMTP id oo10-20020a17090b1c8a00b001fe15365617mr3547793pjb.246.1663145352420; Wed, 14 Sep 2022 01:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663145352; cv=none; d=google.com; s=arc-20160816; b=YkMveHzCzXPhGzv8fv+rw/fx4MmXLggg0AYzGonEN8+2++8OHPQeI5SlnNEU365Ihb c2ko60BRezyzW53F0LByfgHwp3EUf2vPgRce+tWs39dvIO0fLgqigIyYYkPIkHM63uJG tC39TDhpozNaD5k27DAPbvivNr8BB/PVqQROAuB3QhsJOk1B9wj7l19TIeK8qZUUy3A1 xYgAPOY531Rhrls4GXrnap1ByxfAbtstUjG1TkPxpRJ66VcE1G/U9BLBvNexsaOSpG86 Lm3npdrfmOjTpJj49noQ6Cl2D/2CRnx3dGcxDjha5cswTGbv54hwumQZPpk0UUBrfHF8 mcKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=XPsG6aPolMTC+1Smxwfmg2mtEBVuVWgQqO/MuojEHug=; b=Gzvl0+xiFsIL006z94wA17hYQl4bF4NWxwsp/VLDNd7CuNzaeZ+BtFQW5foDP0Wntu 3KjIzFqZvlEiNbbYLENIHRYSESYjMd+D9Z0xrFkdCCa3CSPHVHHjitHADcbHPQKHO3+u MBmbzASfj3D4JPgE3//ok6UD818MS/0MwWpPtrxI3WRGuVcLTuMkuoabjwG53wuHRFrI D+D7F+XJC5kVl4iT6wn7CxngDhY6fethkKt+BcBDkGT5WTiEyYMj/v4dBCpO54XyigDG /Gx6jsgFt5jV9cAjgPITuSvCo6140yPnucg4oFK5KQ94pd/rPz6RIK/ipsQNT3F70/0F rMCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c18-20020aa78e12000000b00535d28e6909si2512022pfr.294.2022.09.14.01.49.00; Wed, 14 Sep 2022 01:49:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbiINIQY (ORCPT + 99 others); Wed, 14 Sep 2022 04:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbiINIQA (ORCPT ); Wed, 14 Sep 2022 04:16:00 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87B4652E78; Wed, 14 Sep 2022 01:15:58 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MSClv6dWkzKPsg; Wed, 14 Sep 2022 16:14:03 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP2 (Coremail) with SMTP id Syh0CgB3yXK6jSFjj9FPAw--.59270S2; Wed, 14 Sep 2022 16:15:55 +0800 (CST) From: Pu Lehui To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Pu Lehui Subject: [PATCH bpf-next v3 0/2] Fix wrong cgroup attach flags being assigned to effective progs Date: Wed, 14 Sep 2022 16:17:40 +0000 Message-Id: <20220914161742.3180731-1-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgB3yXK6jSFjj9FPAw--.59270S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WFWkWF1xKw1DGFy3JFW5Wrg_yoW8ur17pF 95A3W3twn8ur93JrWSya4jga4rKr48Aw12y3ZrXr48Zr1xtryqyry2y3y0yry7XFZrGw4x ZF15AFy5Gw45taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvvb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_ tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26r xl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv 0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z2 80aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v 6xkF7I0E8cxan2IY04v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI 8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AK xVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI 8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjxUIf-PUUUUU X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pu Lehui 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 for query with EFFECTIVE flags, exporting attach flags does not make sense, we can remove this logic. After these patches, the above situation 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 v3: - Don't show attach flags when effective query. (John, sdf, martin) v2: https://lore.kernel.org/bpf/20220908145304.3436139-1-pulehui@huaweicloud.com - 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: Don't populate prog_attach_flags array when effective query bpftool: Fix wrong cgroup attach flags being assigned to effective progs kernel/bpf/cgroup.c | 23 +++++++++------- tools/bpf/bpftool/cgroup.c | 54 +++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 31 deletions(-) -- 2.25.1