]> granicus.if.org Git - strace/commitdiff
bpf: BPF_PROG_QUERY bpf_attr.query.prog_ids printing fixes
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 20 May 2018 15:57:02 +0000 (17:57 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 28 May 2018 17:34:50 +0000 (17:34 +0000)
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Use
print_uint32_array_member instead of print_uint64_array_member for
printing prog_ids elements (and change the type of prog_id_buf from
uint64_t to uint32_t), as they are 32-bit; use common trick with
print_big_u64_addr for handling possible ambiguity with prog_ids
address.
* tests/bpf.c (BIG_ADDR_MAYBE): New macro.
(BPF_PROG_QUERY_checks): Update expected output.

bpf.c
tests/bpf.c

diff --git a/bpf.c b/bpf.c
index ba5a01ae9f51f1ede6bf82e8bc89559bb7676988..3a8745fd997a8de24229bce48e864fe9e534a2bf 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -439,7 +439,7 @@ END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD)
 
 BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)
 {
-       uint64_t prog_id_buf;
+       uint32_t prog_id_buf;
 
        if (entering(tcp)) {
                PRINT_FIELD_FD("{query={", attr, target_fd, tcp);
@@ -463,17 +463,10 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)
                return 0;
        }
 
-       /*
-        * The issue here is that we can't pass pointers bigger than
-        * (our) kernel long ti print_array, so we opt out from decoding
-        * the array.
-        */
-       if (syserror(tcp) || attr.prog_ids > max_kaddr())
-               printaddr64(attr.prog_ids);
-       else
-               print_array(tcp, attr.prog_ids, attr.prog_cnt, &prog_id_buf,
-                           sizeof(prog_id_buf), umoven_or_printaddr,
-                           print_uint64_array_member, 0);
+       print_big_u64_addr(attr.prog_ids);
+       print_array(tcp, attr.prog_ids, attr.prog_cnt, &prog_id_buf,
+                   sizeof(prog_id_buf), umoven_or_printaddr,
+                   print_uint32_array_member, 0);
 
        tprints(", prog_cnt=");
        if (priv && priv->bpf_prog_query_stored
index 52a560c4f558981bca97041c6812960d7b11b7fb..96f68b341e478b6d992050711b41fc7357aaa4fd 100644 (file)
 
 #if defined MPERS_IS_m32 || SIZEOF_KERNEL_LONG_T > 4
 # define BIG_ADDR(addr64_, addr32_) addr64_
+# define BIG_ADDR_MAYBE(addr_)
 #elif defined __arm__ || defined __i386__ || defined __mips__ \
    || defined __powerpc__ || defined __riscv__ || defined __s390__ \
    || defined __sparc__ || defined __tile__
 # define BIG_ADDR(addr64_, addr32_) addr64_ " or " addr32_
+# define BIG_ADDR_MAYBE(addr_) addr_ " or "
 #else
 # define BIG_ADDR(addr64_, addr32_) addr32_
+# define BIG_ADDR_MAYBE(addr_)
 #endif
 
 #ifndef HAVE_STRUCT_BPF_INSN
@@ -887,7 +890,9 @@ static const struct bpf_attr_check BPF_PROG_QUERY_checks[] = {
                       ", attach_type=0xe /* BPF_??? */"
                       ", query_flags=0xfffffffe /* BPF_F_QUERY_??? */"
                       ", attach_flags=0xfffffffc /* BPF_F_??? */"
-                      ", prog_ids=0xffffffffffffffff, prog_cnt=2718281828}",
+                      ", prog_ids="
+                      BIG_ADDR("0xffffffffffffffff", "0xffffffff")
+                      ", prog_cnt=2718281828}",
        },
        { /* 3 */
                .data = { .BPF_PROG_QUERY_data = {
@@ -903,7 +908,8 @@ static const struct bpf_attr_check BPF_PROG_QUERY_checks[] = {
                       ", attach_type=0xfeedface /* BPF_??? */"
                       ", query_flags=BPF_F_QUERY_EFFECTIVE|0xdeadf00c"
                       ", attach_flags=BPF_F_ALLOW_MULTI|0xbeefcafc"
-                      ", prog_ids=0xffffffffffffffff, prog_cnt=0}",
+                      ", prog_ids=" BIG_ADDR_MAYBE("0xffffffffffffffff") "[]"
+                      ", prog_cnt=0}",
        },
 };