From: Dmitry V. Levin Date: Thu, 27 Jul 2017 00:44:31 +0000 (+0000) Subject: bpf: update BPF_PROG_LOAD decoding X-Git-Tag: v4.19~202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c024f1a60f9c3580bd2d1afd1d37d533db501564;p=strace bpf: update BPF_PROG_LOAD decoding Implement decoding of union bpf_attr.prog_flags field for BPF_PROG_LOAD command introduced by linux kernel commit v4.12-rc2~34^2~29^2~2. * configure.ac: Check for prog_flags member of union bpf_attr instead of kern_version. * xlat/bpf_prog_flags.in: New file. * bpf.c: Include "xlat/bpf_prog_flags.h". (decode_BPF_PROG_LOAD): Add prog_flags field to the structure, print it. * tests/bpf.c: Update macro guards of BPF_PROG_LOAD decoder test. (init_BPF_PROG_LOAD_first, print_BPF_PROG_LOAD_attr): Update expected output. (init_BPF_PROG_LOAD_attr): Initialize prog_flags field, update offset. --- diff --git a/bpf.c b/bpf.c index 676ab85e..19109b5d 100644 --- a/bpf.c +++ b/bpf.c @@ -36,6 +36,7 @@ #include "xlat/bpf_commands.h" #include "xlat/bpf_map_types.h" #include "xlat/bpf_prog_types.h" +#include "xlat/bpf_prog_flags.h" #include "xlat/bpf_map_update_elem_flags.h" #include "xlat/bpf_attach_type.h" #include "xlat/bpf_attach_flags.h" @@ -202,11 +203,9 @@ DEF_BPF_CMD_DECODER(BPF_PROG_LOAD) uint64_t ATTRIBUTE_ALIGNED(8) insns, license; uint32_t log_level, log_size; uint64_t ATTRIBUTE_ALIGNED(8) log_buf; - uint32_t kern_version; + uint32_t kern_version, prog_flags; } attr = {}; - const size_t attr_size = - offsetofend(struct bpf_prog_load, kern_version); - const unsigned int len = size < attr_size ? size : attr_size; + const unsigned int len = size < sizeof(attr) ? size : sizeof(attr); memcpy(&attr, data, len); @@ -219,7 +218,8 @@ DEF_BPF_CMD_DECODER(BPF_PROG_LOAD) PRINT_FIELD_U(", ", attr, log_size); PRINT_FIELD_X(", ", attr, log_buf); PRINT_FIELD_U(", ", attr, kern_version); - decode_attr_extra_data(tcp, data, size, attr_size); + PRINT_FIELD_FLAGS(", ", attr, prog_flags, bpf_prog_flags, "BPF_F_???"); + decode_attr_extra_data(tcp, data, size, sizeof(attr)); tprints("}"); return RVAL_DECODED | RVAL_FD; diff --git a/configure.ac b/configure.ac index 19d5f19a..27a2ea12 100644 --- a/configure.ac +++ b/configure.ac @@ -431,8 +431,8 @@ AC_CHECK_HEADERS([linux/bpf.h], [ st_CHECK_UNION_BPF_ATTR([attach_flags]) st_CHECK_UNION_BPF_ATTR([bpf_fd]) st_CHECK_UNION_BPF_ATTR([flags]) - st_CHECK_UNION_BPF_ATTR([kern_version]) st_CHECK_UNION_BPF_ATTR([max_entries]) + st_CHECK_UNION_BPF_ATTR([prog_flags]) ]) AC_CHECK_TYPES([struct statfs], [ diff --git a/tests/bpf.c b/tests/bpf.c index fc038797..83a92a90 100644 --- a/tests/bpf.c +++ b/tests/bpf.c @@ -34,8 +34,8 @@ && (defined HAVE_UNION_BPF_ATTR_ATTACH_FLAGS \ || defined HAVE_UNION_BPF_ATTR_BPF_FD \ || defined HAVE_UNION_BPF_ATTR_FLAGS \ - || defined HAVE_UNION_BPF_ATTR_KERN_VERSION \ - || defined HAVE_UNION_BPF_ATTR_MAX_ENTRIES) + || defined HAVE_UNION_BPF_ATTR_MAX_ENTRIES \ + || defined HAVE_UNION_BPF_ATTR_PROG_FLAGS) # include # include @@ -344,7 +344,7 @@ init_BPF_MAP_GET_NEXT_KEY_attr(const unsigned long eop) # endif /* HAVE_UNION_BPF_ATTR_FLAGS */ -# ifdef HAVE_UNION_BPF_ATTR_KERN_VERSION +# ifdef HAVE_UNION_BPF_ATTR_PROG_FLAGS static unsigned int init_BPF_PROG_LOAD_first(const unsigned long eop) @@ -363,7 +363,7 @@ print_BPF_PROG_LOAD_first(const unsigned long addr) printf("prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=0, insns=0" ", license=NULL, log_level=0, log_size=0, log_buf=0" - ", kern_version=0"); + ", kern_version=0, prog_flags=0"); } static const struct bpf_insn insns[] = { @@ -382,10 +382,11 @@ init_BPF_PROG_LOAD_attr(const unsigned long eop) .log_level = 42, .log_size = sizeof(log_buf), .log_buf = (uintptr_t) log_buf, - .kern_version = 0xcafef00d + .kern_version = 0xcafef00d, + .prog_flags = 1 }; static const unsigned int offset = - offsetofend(union bpf_attr, kern_version); + offsetofend(union bpf_attr, prog_flags); const unsigned long addr = eop - offset; memcpy((void *) addr, &attr, offset); @@ -397,12 +398,12 @@ print_BPF_PROG_LOAD_attr(const unsigned long addr) { printf("prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=%u, insns=%p" ", license=\"GPL\", log_level=42, log_size=4096, log_buf=%p" - ", kern_version=%u", + ", kern_version=%u, prog_flags=BPF_F_STRICT_ALIGNMENT", (unsigned int) ARRAY_SIZE(insns), insns, log_buf, 0xcafef00d); } -# endif /* HAVE_UNION_BPF_ATTR_KERN_VERSION */ +# endif /* HAVE_UNION_BPF_ATTR_PROG_FLAGS */ /* * bpf() syscall and its first six commands were introduced in Linux kernel @@ -554,7 +555,7 @@ main(void) TEST_BPF(BPF_MAP_GET_NEXT_KEY); # endif -# ifdef HAVE_UNION_BPF_ATTR_KERN_VERSION +# ifdef HAVE_UNION_BPF_ATTR_PROG_FLAGS TEST_BPF(BPF_PROG_LOAD); # endif diff --git a/xlat/bpf_prog_flags.in b/xlat/bpf_prog_flags.in new file mode 100644 index 00000000..7fcf3a7a --- /dev/null +++ b/xlat/bpf_prog_flags.in @@ -0,0 +1 @@ +BPF_F_STRICT_ALIGNMENT 1