All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pu Lehui <pulehui@huaweicloud.com>
To: Martin KaFai Lau <martin.lau@linux.dev>,
	Stanislav Fomichev <sdf@google.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Quentin Monnet <quentin@isovalent.com>,
	Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	Pu Lehui <pulehui@huawei.com>, Pu Lehui <pulehui@huaweicloud.com>
Subject: Re: [PATCH bpf-next v3 1/2] bpf, cgroup: Don't populate prog_attach_flags array when effective query
Date: Mon, 19 Sep 2022 21:32:02 +0800	[thread overview]
Message-ID: <037a6a32-5143-ddad-4a43-bd815280a0ef@huaweicloud.com> (raw)
In-Reply-To: <9b66564e-2582-03b2-56f1-8037f8aca886@linux.dev>



On 2022/9/17 8:03, Martin KaFai Lau wrote:
> On 9/14/22 9:17 AM, Pu Lehui wrote:
>> From: Pu Lehui <pulehui@huawei.com>
>>
>> Attach flags is only valid for attached progs of this layer cgroup,
>> but not for effective progs. For querying with EFFECTIVE flags,
>> exporting attach flags does not make sense. so we don't need to
>> populate prog_attach_flags array when effective query.
> 
> prog_attach_flags has been added to 6.0 which is in rc5.  It is still 
> doable (and cleaner) to reject prog_attach_flags when it is an 
> effective_query.  This should be done regardless of 'type == 
> BPF_LSM_CGROUP' or not.  Something like:
> 
> if (effective_query && prog_attach_flags)
>      return -EINVAL;
> 
> Otherwise, the whole prog_attach_flags needs to be set to 0 during 
> effective_query.  Please target the change to the bpf tree instead of 
> bpf-next such that this uapi bit can be fixed before 6.0.
> 

Okay, will handle in next version.

> Also, the effective_query issue is not limited to the prog_attach_flags? 
> For the older uattr->query.attach_flags, it should be set to 0 also when 
> it is an effective_query, right?

For output uattr->query.attach_flags, we certainly don't need to copy it 
to userspace when effective query. Since we do not utilize 
uattr->query.attach_flags in the cgroup query function, should we need 
to take it as input and reject when it is non-zero in effective query? 
Something like:
if (effective_query && (prog_attach_flags || attr->query.attach_flags))

For both output and input scenarios, we are faced with the problem that 
there is a ambiguity in attach_flags being 0. When we do not copy to the 
userspace, libbpf will set it to 0 by default, and 0 can mean NONE flag 
attach, or no attach prog. The same is true for input scenarios.

So should we need to define NONE attach flag and redefine the others? 
Such as follow:
#define BPF_F_ALLOW_NONE    	(1U << 0)
#define BPF_F_ALLOW_OVERRIDE    (1U << 1)
#define BPF_F_ALLOW_MULTI       (1U << 2)
#define BPF_F_REPLACE           (1U << 3)

And then attach flags being 0 certainly means no attach any prog.


  reply	other threads:[~2022-09-19 13:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 16:17 [PATCH bpf-next v3 0/2] Fix wrong cgroup attach flags being assigned to effective progs Pu Lehui
2022-09-14 16:17 ` [PATCH bpf-next v3 1/2] bpf, cgroup: Don't populate prog_attach_flags array when effective query Pu Lehui
2022-09-17  0:03   ` Martin KaFai Lau
2022-09-19 13:32     ` Pu Lehui [this message]
2022-09-19 17:28       ` Martin KaFai Lau
2022-09-14 16:17 ` [PATCH bpf-next v3 2/2] bpftool: Fix wrong cgroup attach flags being assigned to effective progs Pu Lehui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=037a6a32-5143-ddad-4a43-bd815280a0ef@huaweicloud.com \
    --to=pulehui@huaweicloud.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=pulehui@huawei.com \
    --cc=quentin@isovalent.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.