Thread (29 messages) 29 messages, 5 authors, 2019-11-16

Re: [PATCH v4 bpf-next 15/20] bpf: Annotate context types

From: Song Liu <hidden>
Date: 2019-11-14 22:55:57
Also in: bpf

On Nov 14, 2019, at 10:57 AM, Alexei Starovoitov [off-list ref] 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 */ }

Or did I miss the size check? 

Thanks,
Song
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help