From: Eugene Syromyatnikov Date: Sun, 20 May 2018 15:57:02 +0000 (+0200) Subject: bpf: BPF_PROG_QUERY bpf_attr.query.prog_ids printing fixes X-Git-Tag: v4.23~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3b04cdf6e9a5ce6732c9b717b0d9f0052436ae4;p=strace bpf: BPF_PROG_QUERY bpf_attr.query.prog_ids printing fixes * 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. --- diff --git a/bpf.c b/bpf.c index ba5a01ae..3a8745fd 100644 --- 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 diff --git a/tests/bpf.c b/tests/bpf.c index 52a560c4..96f68b34 100644 --- a/tests/bpf.c +++ b/tests/bpf.c @@ -51,12 +51,15 @@ #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}", }, };