From nobody Wed Apr 8 11:43:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F43C25B08 for ; Sat, 20 Aug 2022 11:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345264AbiHTLd1 (ORCPT ); Sat, 20 Aug 2022 07:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344899AbiHTLdS (ORCPT ); Sat, 20 Aug 2022 07:33:18 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60AF310B6; Sat, 20 Aug 2022 04:33:12 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M8xJb3PrsznTfD; Sat, 20 Aug 2022 19:30:55 +0800 (CST) Received: from dggpemm500019.china.huawei.com (7.185.36.180) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 20 Aug 2022 19:33:10 +0800 Received: from k04.huawei.com (10.67.174.115) by dggpemm500019.china.huawei.com (7.185.36.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 20 Aug 2022 19:33:10 +0800 From: Pu Lehui To: , CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "Jean-Philippe Brucker" , Stanislav Fomichev , "Hao Luo" , Jiri Olsa , Pu Lehui Subject: [PATCH bpf-next 1/2] bpf, cgroup: Fix attach flags being assigned to effective progs Date: Sat, 20 Aug 2022 20:02:33 +0800 Message-ID: <20220820120234.2121044-2-pulehui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220820120234.2121044-1-pulehui@huawei.com> References: <20220820120234.2121044-1-pulehui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.67.174.115] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500019.china.huawei.com (7.185.36.180) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 59b7eb60d5b4..9adf72e99907 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1091,11 +1091,14 @@ static int __cgroup_bpf_query(struct cgroup *cgrp, = const union bpf_attr *attr, } =20 if (prog_attach_flags) { + int progs_cnt =3D prog_list_length(&cgrp->bpf.progs[atype]); flags =3D cgrp->bpf.flags[atype]; =20 - for (i =3D 0; i < cnt; i++) + /* attach flags only for attached progs, but not effective progs */ + for (i =3D 0; i < progs_cnt; i++) if (copy_to_user(prog_attach_flags + i, &flags, sizeof(flags))) return -EFAULT; + prog_attach_flags +=3D cnt; } =20 --=20 2.25.1