netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"x86@kernel.org" <x86@kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"Kernel Team" <Kernel-team@fb.com>
Subject: Re: [PATCH v4 bpf-next 15/20] bpf: Annotate context types
Date: Thu, 14 Nov 2019 23:19:09 +0000	[thread overview]
Message-ID: <E4C70DF1-372F-4129-94DB-E036FB262BEA@fb.com> (raw)
In-Reply-To: <20191114230117.wtusupri5p5xw63b@ast-mbp.dhcp.thefacebook.com>



> On Nov 14, 2019, at 3:01 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> 
> On Thu, Nov 14, 2019 at 10:55:37PM +0000, Song Liu wrote:
>> 
>> 
>>> On Nov 14, 2019, at 10:57 AM, Alexei Starovoitov <ast@kernel.org> wrote:
>>> 
>>> Annotate BPF program context types with program-side type and kernel-side type.
>>> This type information is used by the verifier. btf_get_prog_ctx_type() is
>>> used in the later patches to verify that BTF type of ctx in BPF program matches to
>>> kernel expected ctx type. For example, the XDP program type is:
>>> BPF_PROG_TYPE(BPF_PROG_TYPE_XDP, xdp, struct xdp_md, struct xdp_buff)
>>> That means that XDP program should be written as:
>>> int xdp_prog(struct xdp_md *ctx) { ... }
>>> 
>>> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
>>> 
>> 
>> [...]
>> 
>>> +	/* only compare that prog's ctx type name is the same as
>>> +	 * kernel expects. No need to compare field by field.
>>> +	 * It's ok for bpf prog to do:
>>> +	 * struct __sk_buff {};
>>> +	 * int socket_filter_bpf_prog(struct __sk_buff *skb)
>>> +	 * { // no fields of skb are ever used }
>>> +	 */
>>> +	if (strcmp(ctx_tname, tname))
>>> +		return NULL;
>> 
>> Do we need to check size of the two struct? I guess we should not 
>> allow something like
>> 
>> 	struct __sk_buff {
>> 		char data[REALLY_BIG_NUM]; 
>> 	};
>> 	int socket_filter_bpf_prog(struct __sk_buff *skb)
>> 	{ /* access end of skb */ }
> 
> I don't think we should check sizes either. Same comment above applies. The
> prog's __sk_buff can be different from kernel's view into __sk_buff. Either
> bigger or larger doesn't matter. If it's accessed by the prog the verifier will
> check that all accessed fields are correct. Extra unused fields (like char
> data[REALLY_BIG_NUM];) don't affect safety.
> When bpf-tracing is attaching to bpf-skb it doesn't use bpf-skb's
> __sk_buff with giant fake data[BIG_NUM];. It's using kernel's __sk_buff.
> That is what btf_translate_to_vmlinux() in patch 17 is doing.

I see. Thanks for the pointer. 

Song

  reply	other threads:[~2019-11-14 23:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 18:57 [PATCH v4 bpf-next 00/20] Introduce BPF trampoline Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 01/20] x86/alternatives: Teach text_poke_bp() to emulate instructions Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 02/20] bpf: refactor x86 JIT into helpers Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 03/20] bpf: Add bpf_arch_text_poke() helper Alexei Starovoitov
2019-11-15 22:18   ` Andrii Nakryiko
2019-11-14 18:57 ` [PATCH v4 bpf-next 04/20] bpf: Introduce BPF trampoline Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 05/20] libbpf: Introduce btf__find_by_name_kind() Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 06/20] libbpf: Add support to attach to fentry/fexit tracing progs Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 07/20] selftest/bpf: Simple test for fentry/fexit Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 08/20] bpf: Add kernel test functions for fentry testing Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 09/20] selftests/bpf: Add test for BPF trampoline Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 10/20] selftests/bpf: Add fexit tests " Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 11/20] selftests/bpf: Add combined fentry/fexit test Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 12/20] selftests/bpf: Add stress test for maximum number of progs Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 13/20] bpf: Reserve space for BPF trampoline in BPF programs Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 14/20] bpf: Fix race in btf_resolve_helper_id() Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 15/20] bpf: Annotate context types Alexei Starovoitov
2019-11-14 22:55   ` Song Liu
2019-11-14 23:01     ` Alexei Starovoitov
2019-11-14 23:19       ` Song Liu [this message]
2019-11-14 23:23   ` Song Liu
2019-11-14 18:57 ` [PATCH v4 bpf-next 16/20] bpf: Compare BTF types of functions arguments with actual types Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 17/20] bpf: Support attaching tracing BPF program to other BPF programs Alexei Starovoitov
2019-11-14 23:30   ` Song Liu
2019-11-14 18:57 ` [PATCH v4 bpf-next 18/20] libbpf: Add support for attaching BPF programs " Alexei Starovoitov
2019-11-14 23:39   ` Song Liu
2019-11-14 18:57 ` [PATCH v4 bpf-next 19/20] selftests/bpf: Extend test_pkt_access test Alexei Starovoitov
2019-11-14 18:57 ` [PATCH v4 bpf-next 20/20] selftests/bpf: Add a test for attaching BPF prog to another BPF prog and subprog Alexei Starovoitov
2019-11-16  0:01 ` [PATCH v4 bpf-next 00/20] Introduce BPF trampoline Daniel Borkmann

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=E4C70DF1-372F-4129-94DB-E036FB262BEA@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=x86@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).