[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220604080542.2fk7anxkjvysd6gr@kafai-mbp>
Date: Sat, 4 Jun 2022 01:05:42 -0700
From: Martin KaFai Lau <kafai@...com>
To: Stanislav Fomichev <sdf@...gle.com>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org, ast@...nel.org,
daniel@...earbox.net, andrii@...nel.org
Subject: Re: [PATCH bpf-next v8 05/11] bpf: implement BPF_PROG_QUERY for
BPF_LSM_CGROUP
On Fri, Jun 03, 2022 at 11:59:38PM -0700, Martin KaFai Lau wrote:
> On Wed, Jun 01, 2022 at 12:02:12PM -0700, Stanislav Fomichev wrote:
> > diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> > index a27a6a7bd852..cb3338ef01e0 100644
> > --- a/kernel/bpf/cgroup.c
> > +++ b/kernel/bpf/cgroup.c
> > @@ -1035,6 +1035,7 @@ static int cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
> > static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
> > union bpf_attr __user *uattr)
> > {
> > + __u32 __user *prog_attach_flags = u64_to_user_ptr(attr->query.prog_attach_flags);
> > __u32 __user *prog_ids = u64_to_user_ptr(attr->query.prog_ids);
> > enum bpf_attach_type type = attr->query.attach_type;
> > enum cgroup_bpf_attach_type atype;
> > @@ -1042,50 +1043,92 @@ static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
> > struct hlist_head *progs;
> > struct bpf_prog *prog;
> > int cnt, ret = 0, i;
> > + int total_cnt = 0;
> > u32 flags;
> >
> > - atype = to_cgroup_bpf_attach_type(type);
> > - if (atype < 0)
> > - return -EINVAL;
> > + enum cgroup_bpf_attach_type from_atype, to_atype;
> >
> > - progs = &cgrp->bpf.progs[atype];
> > - flags = cgrp->bpf.flags[atype];
> > + if (type == BPF_LSM_CGROUP) {
> > + from_atype = CGROUP_LSM_START;
> > + to_atype = CGROUP_LSM_END;
> Enforce prog_attach_flags for BPF_LSM_CGROUP:
>
> if (total_cnt && !prog_attach_flags)
Correction. Mixed up with the total_cnt below.
Should be "attr->query.prog_cnt && prog_ids && !prog_attach_flags".
> return -EINVAL;
>
[ ... ]
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index a237be4f8bb3..27492d44133f 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -3520,7 +3520,7 @@ static int bpf_prog_detach(const union bpf_attr *attr)
> > }
> > }
> >
> > -#define BPF_PROG_QUERY_LAST_FIELD query.prog_cnt
> > +#define BPF_PROG_QUERY_LAST_FIELD query.prog_attach_flags
> >
> > static int bpf_prog_query(const union bpf_attr *attr,
> > union bpf_attr __user *uattr)
> > @@ -3556,6 +3556,7 @@ static int bpf_prog_query(const union bpf_attr *attr,
> > case BPF_CGROUP_SYSCTL:
> > case BPF_CGROUP_GETSOCKOPT:
> > case BPF_CGROUP_SETSOCKOPT:
> > + case BPF_LSM_CGROUP:
> > return cgroup_bpf_prog_query(attr, uattr);
> > case BPF_LIRC_MODE2:
> > return lirc_prog_query(attr, uattr);
> > @@ -4066,6 +4067,9 @@ static int bpf_prog_get_info_by_fd(struct file *file,
> >
> > if (prog->aux->btf)
> > info.btf_id = btf_obj_id(prog->aux->btf);
> > + info.attach_btf_id = prog->aux->attach_btf_id;
> > + if (prog->aux->attach_btf)
> > + info.attach_btf_obj_id = btf_obj_id(prog->aux->attach_btf);
> Need this also:
>
> else if (prog->aux->dst_prog)
> info.attach_btf_obj_id = btf_obj_id(prog->aux->dst_prog->aux->attach_btf);
Should be btf_obj_id(prog->aux->dst_prog->aux->btf) instead.
>
> >
> > ulen = info.nr_func_info;
> > info.nr_func_info = prog->aux->func_info_cnt;
> > --
> > 2.36.1.255.ge46751e96f-goog
> >
Powered by blists - more mailing lists