Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4737265rwb; Tue, 20 Sep 2022 19:53:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vj0klEwtymxKeCOeRp+Sqhhzp3taVzGeAkXrH4BdDa303Yg/ZbDQ793CHRzh2NF0RyEYZ X-Received: by 2002:a17:907:60d3:b0:77e:5e9b:8ec with SMTP id hv19-20020a17090760d300b0077e5e9b08ecmr19232553ejc.640.1663728796592; Tue, 20 Sep 2022 19:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663728796; cv=none; d=google.com; s=arc-20160816; b=JDndt+CssL8fdHL6Fa/dJZJBfP/HdecMmTxrX2zP2CABQt0j3W66iDvLKYRpaoR4RM Mnka8gYOnXLYdK5MkWjL3nXKuJHFJGu/4fIDK3m/fGpaZca0uEgvh6owbslf/27OXnkV Q1DPOAHQz4DwoEz3VrNazlJvILrnQxTfNVrW9m/x8AEL0+xDUUdyVQBEfZ9OPNfY2HyU Pt8Y8HhEbPhwcDSaLiyELEiAxLnRmIdk0hjewI5EJ8FKM03THb7wykYm8siM6IqmlmR4 I+hj+tNmvrdxCdrB3QZZmDQSkDh1RA/EJFVqKkYqxt1aMtx9RL3hN4iG3xe5Kqwa4AOk PwTQ== 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=GG9pVqxQSdRTCVto+McAXBo7Ai18DjkswaCdeTOD9Uc=; b=L4KjDeLJmNkYSCb0BaOb1JrMLXQzvX3ADLHAQW8oWYV88E6awX8aG5tq8bJhzYhQ+f tPLyDtbrxMtDNRL2v3/9711Kg7XK7mMv59C9fesDEaW6IZ9j/7ofjgep8S/cTnXGetT2 nGgggCTy+sjAFCx0LO2AGmlvPLgeCuLmAEzIrHMRg9dvylqjsaRhWeacIEDHz0XTqDY7 mbeE1wKYEnWhQ8DSYFZXBy7WVlQaXymhUNwrrp9Dxg49NPiX94L7zGwmChurnEA8qhm3 NtJIi4zcK34tctfCqEan+HF/VmQGpI6x+FB8+1ystpFS98FMhR/JsJJGMDb4wZS8QMg5 nlqA== 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 gb19-20020a170907961300b0077d79066580si1805728ejc.331.2022.09.20.19.52.51; Tue, 20 Sep 2022 19:53:16 -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 S230346AbiIUCoO (ORCPT + 99 others); Tue, 20 Sep 2022 22:44:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbiIUCoM (ORCPT ); Tue, 20 Sep 2022 22:44:12 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0A6F7D1F0; Tue, 20 Sep 2022 19:44:10 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MXN3k3NWWzKLKs; Wed, 21 Sep 2022 10:42:10 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP1 (Coremail) with SMTP id cCh0CgD3xCh3eipjRFhmBA--.50399S2; Wed, 21 Sep 2022 10:44:09 +0800 (CST) From: Pu Lehui To: Martin KaFai Lau , Stanislav Fomichev , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Pu Lehui , Pu Lehui Subject: [PATCH bpf v5 0/3] Fix wrong cgroup attach flags being assigned to effective progs Date: Wed, 21 Sep 2022 10:46:01 +0000 Message-Id: <20220921104604.2340580-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: cCh0CgD3xCh3eipjRFhmBA--.50399S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAFW7KrWktFy3Aw43Xr45Awb_yoW5GF4kpF WkZ3W5Jwn8Wr93JrWSk34jga4rtw48Aw1jy3ZrXr48uFyxtryqyrWIk3yFkr17XFsrKw4x Zw15ZF98G3y5taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9a14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2ocxC64kIII 0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xv wVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4 x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG 64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r 1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAq YI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4I kC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWU WwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr 0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVW3 JVWrJr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8Jr UvcSsGvfC2KfnxnUUI43ZEXa7sRiPl1DUUUUU== X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, KHOP_HELO_FCRDNS,SPF_HELO_NONE,SPF_NONE autolearn=no 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. So let's remove the AttachFlags field and the associated logic. After these patches, 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 v5: - Adapt selftests for effective query uapi change. v4: https://lore.kernel.org/bpf/20220920154233.1494352-1-pulehui@huaweicloud.com - Reject prog_attach_flags array when effective query. (Martin) - Target to bpf tree. (Martin) v3: https://lore.kernel.org/bpf/20220914161742.3180731-1-pulehui@huaweicloud.com - 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 (3): bpf, cgroup: Reject prog_attach_flags array when effective query bpftool: Fix wrong cgroup attach flags being assigned to effective progs selftests/bpf: Adapt cgroup effective query uapi change include/uapi/linux/bpf.h | 7 ++- kernel/bpf/cgroup.c | 28 ++++++---- tools/bpf/bpftool/cgroup.c | 54 +++++++++++++++++-- tools/include/uapi/linux/bpf.h | 7 ++- .../selftests/bpf/prog_tests/cgroup_link.c | 11 ++-- 5 files changed, 81 insertions(+), 26 deletions(-) -- 2.25.1