* [PATCH 4/5] bpf: Add bpf_verify_program() to the library.
@ 2017-05-10 19:10 David Miller
2017-05-11 12:54 ` Daniel Borkmann
0 siblings, 1 reply; 2+ messages in thread
From: David Miller @ 2017-05-10 19:10 UTC (permalink / raw)
To: ast; +Cc: alexei.starovoitov, daniel, netdev
This allows a test case to load a BPF program and unconditionally
acquire the verifier log.
It also allows specification of the strict alignment flag.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
tools/lib/bpf/bpf.c | 22 ++++++++++++++++++++++
tools/lib/bpf/bpf.h | 4 ++++
2 files changed, 26 insertions(+)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 4fe444b80..6e17898 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -117,6 +117,28 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
}
+int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
+ size_t insns_cnt, int strict_alignment,
+ const char *license, __u32 kern_version,
+ char *log_buf, size_t log_buf_sz)
+{
+ union bpf_attr attr;
+
+ bzero(&attr, sizeof(attr));
+ attr.prog_type = type;
+ attr.insn_cnt = (__u32)insns_cnt;
+ attr.insns = ptr_to_u64(insns);
+ attr.license = ptr_to_u64(license);
+ attr.log_buf = ptr_to_u64(log_buf);
+ attr.log_size = log_buf_sz;
+ attr.log_level = 2;
+ log_buf[0] = 0;
+ attr.kern_version = kern_version;
+ attr.prog_flags = strict_alignment ? BPF_F_STRICT_ALIGNMENT : 0;
+
+ return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
+}
+
int bpf_map_update_elem(int fd, const void *key, const void *value,
__u64 flags)
{
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index edb4dae..972bd83 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -35,6 +35,10 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
size_t insns_cnt, const char *license,
__u32 kern_version, char *log_buf,
size_t log_buf_sz);
+int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
+ size_t insns_cnt, int strict_alignment,
+ const char *license, __u32 kern_version,
+ char *log_buf, size_t log_buf_sz);
int bpf_map_update_elem(int fd, const void *key, const void *value,
__u64 flags);
--
2.1.2.532.g19b5d50
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 4/5] bpf: Add bpf_verify_program() to the library.
2017-05-10 19:10 [PATCH 4/5] bpf: Add bpf_verify_program() to the library David Miller
@ 2017-05-11 12:54 ` Daniel Borkmann
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2017-05-11 12:54 UTC (permalink / raw)
To: David Miller, ast; +Cc: alexei.starovoitov, netdev
On 05/10/2017 09:10 PM, David Miller wrote:
>
> This allows a test case to load a BPF program and unconditionally
> acquire the verifier log.
>
> It also allows specification of the strict alignment flag.
>
> Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-11 12:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-10 19:10 [PATCH 4/5] bpf: Add bpf_verify_program() to the library David Miller
2017-05-11 12:54 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.