From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v2 1/3] bpf: implement link_query for bpf iterators
Date: Thu, 20 Aug 2020 23:42:31 -0700 [thread overview]
Message-ID: <08982c2f-b9a8-3d30-9e4c-4f3f071a5a58@fb.com> (raw)
In-Reply-To: <CAEf4BzZ32inDH2MhLFv5o8PiQ9=4EGR0C75Ks6dWzHjVsgozAg@mail.gmail.com>
On 8/20/20 11:31 PM, Andrii Nakryiko wrote:
> On Thu, Aug 20, 2020 at 3:50 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> This patch implemented bpf_link callback functions
>> show_fdinfo and fill_link_info to support link_query
>> interface.
>>
>> The general interface for show_fdinfo and fill_link_info
>> will print/fill the target_name. Each targets can
>> register show_fdinfo and fill_link_info callbacks
>> to print/fill more target specific information.
>>
>> For example, the below is a fdinfo result for a bpf
>> task iterator.
>> $ cat /proc/1749/fdinfo/7
>> pos: 0
>> flags: 02000000
>> mnt_id: 14
>> link_type: iter
>> link_id: 11
>> prog_tag: 990e1f8152f7e54f
>> prog_id: 59
>> target_name: task
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>> include/linux/bpf.h | 6 ++++
>> include/uapi/linux/bpf.h | 7 ++++
>> kernel/bpf/bpf_iter.c | 58 ++++++++++++++++++++++++++++++++++
>> tools/include/uapi/linux/bpf.h | 7 ++++
>> 4 files changed, 78 insertions(+)
>>
>
> [...]
>
>> +
>> +static int bpf_iter_link_fill_link_info(const struct bpf_link *link,
>> + struct bpf_link_info *info)
>> +{
>> + struct bpf_iter_link *iter_link =
>> + container_of(link, struct bpf_iter_link, link);
>> + char __user *ubuf = u64_to_user_ptr(info->iter.target_name);
>> + bpf_iter_fill_link_info_t fill_link_info;
>> + u32 ulen = info->iter.target_name_len;
>> + const char *target_name;
>> + u32 target_len;
>> +
>> + if (ulen && !ubuf)
>> + return -EINVAL;
>> +
>> + target_name = iter_link->tinfo->reg_info->target;
>> + target_len = strlen(target_name);
>> + info->iter.target_name_len = target_len + 1;
>> + if (!ubuf)
>> + return 0;
>
> this might return prematurely before fill_link_info() below gets a
> chance to fill in some extra info?
The extra info filled by below fill_link_info is target specific
and we need a target name to ensure picking right union members.
So it is best to enforce a valid target name before filling
target dependent fields. See below, if there are any errors
for copy_to_user or enospc, we won't copy addition link info
either.
>
>> +
>> + if (ulen >= target_len + 1) {
>> + if (copy_to_user(ubuf, target_name, target_len + 1))
>> + return -EFAULT;
>> + } else {
>> + char zero = '\0';
>> +
>> + if (copy_to_user(ubuf, target_name, ulen - 1))
>> + return -EFAULT;
>> + if (put_user(zero, ubuf + ulen - 1))
>> + return -EFAULT;
>> + return -ENOSPC;
>> + }
>> +
>> + fill_link_info = iter_link->tinfo->reg_info->fill_link_info;
>> + if (fill_link_info)
>> + return fill_link_info(&iter_link->aux, info);
>> +
>> + return 0;
>> +}
>> +
>
> [...]
>
next prev parent reply other threads:[~2020-08-21 6:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-20 22:49 [PATCH bpf-next v2 0/3] bpf: implement link_query for bpf iterators Yonghong Song
2020-08-20 22:49 ` [PATCH bpf-next v2 1/3] " Yonghong Song
2020-08-21 6:31 ` Andrii Nakryiko
2020-08-21 6:42 ` Yonghong Song [this message]
2020-08-21 16:44 ` Andrii Nakryiko
2020-08-21 17:46 ` Yonghong Song
2020-08-20 22:49 ` [PATCH bpf-next v2 2/3] bpf: implement link_query callbacks in map element iterators Yonghong Song
2020-08-21 6:33 ` Andrii Nakryiko
2020-08-21 6:44 ` Yonghong Song
2020-08-20 22:49 ` [PATCH bpf-next v2 3/3] bpftool: implement link_query for bpf iterators Yonghong Song
2020-08-21 6:35 ` Andrii Nakryiko
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=08982c2f-b9a8-3d30-9e4c-4f3f071a5a58@fb.com \
--to=yhs@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).