diff mbox series

[bpf-next] bpf: explicitly prohibit ctx_{in, out} in non-skb BPF_PROG_TEST_RUN

Message ID 20190411224707.104655-1-sdf@google.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] bpf: explicitly prohibit ctx_{in, out} in non-skb BPF_PROG_TEST_RUN | expand

Commit Message

Stanislav Fomichev April 11, 2019, 10:47 p.m. UTC
This should allow us later to extend BPF_PROG_TEST_RUN for non-skb case
and be sure that nobody is erroneously setting ctx_{in,out}.

Fixes: b0b9395d865e ("bpf: support input __sk_buff context in BPF_PROG_TEST_RUN")
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 net/bpf/test_run.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Daniel Borkmann April 11, 2019, 10:57 p.m. UTC | #1
On 04/12/2019 12:47 AM, Stanislav Fomichev wrote:
> This should allow us later to extend BPF_PROG_TEST_RUN for non-skb case
> and be sure that nobody is erroneously setting ctx_{in,out}.
> 
> Fixes: b0b9395d865e ("bpf: support input __sk_buff context in BPF_PROG_TEST_RUN")
> Reported-by: Daniel Borkmann <daniel@iogearbox.net>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>

Looks good, applied, thanks!
diff mbox series

Patch

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index cbd4fb65aa4f..2221573dacdb 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -347,6 +347,9 @@  int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 	void *data;
 	int ret;
 
+	if (kattr->test.ctx_in || kattr->test.ctx_out)
+		return -EINVAL;
+
 	data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM + NET_IP_ALIGN, 0);
 	if (IS_ERR(data))
 		return PTR_ERR(data);
@@ -390,6 +393,9 @@  int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
 	if (prog->type != BPF_PROG_TYPE_FLOW_DISSECTOR)
 		return -EINVAL;
 
+	if (kattr->test.ctx_in || kattr->test.ctx_out)
+		return -EINVAL;
+
 	data = bpf_test_init(kattr, size, NET_SKB_PAD + NET_IP_ALIGN,
 			     SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
 	if (IS_ERR(data))