Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp248893rwn; Thu, 8 Sep 2022 00:33:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR7HMd10IfACSEEC/61bgYERVeLOboKDl4YVonqojezJ+UlVwvkONdsikxkMNEGiquPE/ARM X-Received: by 2002:a17:903:24c:b0:172:7090:64a4 with SMTP id j12-20020a170903024c00b00172709064a4mr7580834plh.124.1662622414260; Thu, 08 Sep 2022 00:33:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662622414; cv=none; d=google.com; s=arc-20160816; b=paLHY6ZqXtGZoMjuzvpnFfuGoOug3BHrpISvbeakEf+Pf0BtpiiXA7Q4haL7zdp8fJ y86XDmYXl5H7kMteIE2owZUu2ff+uv9lojyqb7hHyjPegVZDj6B0vKO25TksXUJuF3ML MTyobUYrEz6ZWnmyhv6f/wztaSajHDtir8/eus7bBm9oU705hiYBx2qlFzU2mPBi8fhb HIhHpocD/SrO6qVfkVLVrOZkrUex263DZua/AS3lnTAyarZoF9O1xOU+fdopvzRPqNGf lQKaR5LTsBmH2eMRFqg2lXn4oIjdSs4D7HgchuHZjsYynScDhT4NrFnuodGHivanlrBW +VjA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3UuvUwFev/bg9tfkGx61KYfVq5fKLuROxSMPS7swgUg=; b=OUSxB/7Hqv7B7ZZREm5aszNGsc7exND4UntnMhmEs4PcLInvMpgwaFfvTQy9GisZ5E XvfCkArS2Rqtx/2vroqx9JBrHTWnibe2EVcfGZ0eUyca4Dbgx2emK3GY4jXdl8yWANnX xdunrckokNKuDupkAsZkkysDxxDD6EdK5+QZDdOZ3zfPgwUxmPRKqySna3fUXt8I6RTI In4S8dSnEnaIDhRMt5sWfpyhgbe8XvdMCwQ/dVikEY0nq2+8IgfpecTyNmaEpznSIZfg +B9B70hVtpdSvJWd6hAg+Y8Lza7A1mheyaEtRlrASmYw9H/ZL2smr1E9FHG8OvIyJY4V lc6g== 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 h9-20020a170902f70900b001769f625ad8si13520650plo.532.2022.09.08.00.33.11; Thu, 08 Sep 2022 00:33:34 -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 S230520AbiIHGvf (ORCPT + 99 others); Thu, 8 Sep 2022 02:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbiIHGv3 (ORCPT ); Thu, 8 Sep 2022 02:51:29 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA771CB35; Wed, 7 Sep 2022 23:51:27 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MNV9G2sgJzKJJM; Thu, 8 Sep 2022 14:49:38 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP2 (Coremail) with SMTP id Syh0CgBXqHHskBljwcslAg--.10754S3; Thu, 08 Sep 2022 14:51:26 +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 v2 1/2] bpf, cgroup: Fix attach flags being assigned to effective progs Date: Thu, 8 Sep 2022 14:53:03 +0000 Message-Id: <20220908145304.3436139-2-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908145304.3436139-1-pulehui@huaweicloud.com> References: <20220908145304.3436139-1-pulehui@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgBXqHHskBljwcslAg--.10754S3 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWftw17WFyxAFWxGFW7Arb_yoW8JFy5pF W8ZFy7W3WY9F9Fva97t3yFq3yrZw4ktr1jkr98Ary5AFy7Ww1v9ryFk34ayF1SyryUAw1r ZFyYyr9Fka4UZFJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_GcWl84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x0262 8vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GF ylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jg a9fUUUUU= 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_PASS,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, query sub-cgroup with effective flags will incorrectly fill the prog_attach_flags array. 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 --- 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 00c7f864900e..9c439d163a0b 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1093,11 +1093,14 @@ static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr, } if (prog_attach_flags) { + int progs_cnt = min_t(int, prog_list_length(&cgrp->bpf.progs[atype]), total_cnt); flags = cgrp->bpf.flags[atype]; - for (i = 0; i < cnt; i++) + /* attach flags only valid 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