All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] bpf/verifier: improve disassembly of BPF_END instructions
@ 2017-09-21 15:09 Edward Cree
  2017-09-21 15:52 ` Alexei Starovoitov
  0 siblings, 1 reply; 21+ messages in thread
From: Edward Cree @ 2017-09-21 15:09 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Daniel Borkmann, Alexei Starovoitov

print_bpf_insn() was treating all BPF_ALU[64] the same, but BPF_END has a
 different structure: it has a size in insn->imm (even if it's BPF_X) and
 uses the BPF_SRC (X or K) to indicate which endianness to use.  So it
 needs different code to print it.

Signed-off-by: Edward Cree <ecree@solarflare.com>
---
It's not the same format as the new LLVM asm uses, does that matter?
AFAIK the LLVM format doesn't comprehend BPF_TO_LE, just assumes that all
 endian ops are necessarily swaps (rather than sometimes nops).

 kernel/bpf/verifier.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 799b245..e7657a4 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -331,20 +331,29 @@ static void print_bpf_insn(const struct bpf_verifier_env *env,
 	u8 class = BPF_CLASS(insn->code);
 
 	if (class == BPF_ALU || class == BPF_ALU64) {
-		if (BPF_SRC(insn->code) == BPF_X)
+		if (BPF_OP(insn->code) == BPF_END) {
+			if (class == BPF_ALU64)
+				verbose("BUG_alu64_%02x\n", insn->code);
+			else
+				verbose("(%02x) (u%d) r%d %s %s\n",
+					insn->code, insn->imm, insn->dst_reg,
+					bpf_alu_string[BPF_END >> 4],
+					BPF_SRC(insn->code) == BPF_X ? "be" : "le");
+		} else if (BPF_SRC(insn->code) == BPF_X) {
 			verbose("(%02x) %sr%d %s %sr%d\n",
 				insn->code, class == BPF_ALU ? "(u32) " : "",
 				insn->dst_reg,
 				bpf_alu_string[BPF_OP(insn->code) >> 4],
 				class == BPF_ALU ? "(u32) " : "",
 				insn->src_reg);
-		else
+		} else {
 			verbose("(%02x) %sr%d %s %s%d\n",
 				insn->code, class == BPF_ALU ? "(u32) " : "",
 				insn->dst_reg,
 				bpf_alu_string[BPF_OP(insn->code) >> 4],
 				class == BPF_ALU ? "(u32) " : "",
 				insn->imm);
+		}
 	} else if (class == BPF_STX) {
 		if (BPF_MODE(insn->code) == BPF_MEM)
 			verbose("(%02x) *(%s *)(r%d %+d) = r%d\n",

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-09-26 14:37 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-21 15:09 [PATCH net-next] bpf/verifier: improve disassembly of BPF_END instructions Edward Cree
2017-09-21 15:52 ` Alexei Starovoitov
2017-09-21 16:24   ` Edward Cree
2017-09-21 16:40     ` Alexei Starovoitov
2017-09-21 16:40     ` Y Song
2017-09-21 16:58       ` Edward Cree
2017-09-21 19:29         ` Daniel Borkmann
2017-09-21 19:44           ` Alexei Starovoitov
2017-09-21 19:58             ` Edward Cree
2017-09-21 23:11               ` Y Song
2017-09-22 13:46                 ` Edward Cree
2017-09-22 14:11                   ` Y Song
2017-09-22 14:27                     ` Y Song
2017-09-22 15:16                       ` Alexei Starovoitov
2017-09-22 16:23                         ` Edward Cree
2017-09-23  4:49                           ` Y Song
2017-09-24  5:50                             ` Alexei Starovoitov
2017-09-25 21:44                               ` Daniel Borkmann
2017-09-26  1:33                                 ` Alexei Starovoitov
2017-09-26 14:37                                   ` Edward Cree
2017-09-21 16:30   ` Y Song

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.