diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2014-05-15 18:56:38 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-05-16 16:44:08 -0400 |
commit | ed4afd451f12ea57f9aaaf6f8442eee7e415fa1a (patch) | |
tree | 2532887c7f3077036a36ef5f60b44c16099f9d66 /tools | |
parent | e0a1272cfacd53ff99c768b9e09b64cfdd77159c (diff) |
tools: bpf_jit_disasm: ignore image address for disasm
seccomp filters use kernel JIT image addresses, so bpf_jit_enable=2 prints
[ 20.146438] flen=3 proglen=82 pass=0 image=0000000000000000
[ 20.146442] JIT code: 00000000: 55 48 89 e5 48 81 ec 28 02 00 00 ...
ignore image address, so that seccomp filters can be disassembled
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/net/bpf_jit_disasm.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/tools/net/bpf_jit_disasm.c b/tools/net/bpf_jit_disasm.c index cfe0cdcda3de..d9730c3319b9 100644 --- a/tools/net/bpf_jit_disasm.c +++ b/tools/net/bpf_jit_disasm.c | |||
@@ -43,8 +43,7 @@ static void get_exec_path(char *tpath, size_t size) | |||
43 | free(path); | 43 | free(path); |
44 | } | 44 | } |
45 | 45 | ||
46 | static void get_asm_insns(uint8_t *image, size_t len, unsigned long base, | 46 | static void get_asm_insns(uint8_t *image, size_t len, int opcodes) |
47 | int opcodes) | ||
48 | { | 47 | { |
49 | int count, i, pc = 0; | 48 | int count, i, pc = 0; |
50 | char tpath[256]; | 49 | char tpath[256]; |
@@ -107,13 +106,13 @@ static void put_klog_buff(char *buff) | |||
107 | } | 106 | } |
108 | 107 | ||
109 | static int get_last_jit_image(char *haystack, size_t hlen, | 108 | static int get_last_jit_image(char *haystack, size_t hlen, |
110 | uint8_t *image, size_t ilen, | 109 | uint8_t *image, size_t ilen) |
111 | unsigned long *base) | ||
112 | { | 110 | { |
113 | char *ptr, *pptr, *tmp; | 111 | char *ptr, *pptr, *tmp; |
114 | off_t off = 0; | 112 | off_t off = 0; |
115 | int ret, flen, proglen, pass, ulen = 0; | 113 | int ret, flen, proglen, pass, ulen = 0; |
116 | regmatch_t pmatch[1]; | 114 | regmatch_t pmatch[1]; |
115 | unsigned long base; | ||
117 | regex_t regex; | 116 | regex_t regex; |
118 | 117 | ||
119 | if (hlen == 0) | 118 | if (hlen == 0) |
@@ -136,7 +135,7 @@ static int get_last_jit_image(char *haystack, size_t hlen, | |||
136 | 135 | ||
137 | ptr = haystack + off - (pmatch[0].rm_eo - pmatch[0].rm_so); | 136 | ptr = haystack + off - (pmatch[0].rm_eo - pmatch[0].rm_so); |
138 | ret = sscanf(ptr, "flen=%d proglen=%d pass=%d image=%lx", | 137 | ret = sscanf(ptr, "flen=%d proglen=%d pass=%d image=%lx", |
139 | &flen, &proglen, &pass, base); | 138 | &flen, &proglen, &pass, &base); |
140 | if (ret != 4) | 139 | if (ret != 4) |
141 | return 0; | 140 | return 0; |
142 | 141 | ||
@@ -162,7 +161,7 @@ static int get_last_jit_image(char *haystack, size_t hlen, | |||
162 | assert(ulen == proglen); | 161 | assert(ulen == proglen); |
163 | printf("%d bytes emitted from JIT compiler (pass:%d, flen:%d)\n", | 162 | printf("%d bytes emitted from JIT compiler (pass:%d, flen:%d)\n", |
164 | proglen, pass, flen); | 163 | proglen, pass, flen); |
165 | printf("%lx + <x>:\n", *base); | 164 | printf("%lx + <x>:\n", base); |
166 | 165 | ||
167 | regfree(®ex); | 166 | regfree(®ex); |
168 | return ulen; | 167 | return ulen; |
@@ -172,7 +171,6 @@ int main(int argc, char **argv) | |||
172 | { | 171 | { |
173 | int len, klen, opcodes = 0; | 172 | int len, klen, opcodes = 0; |
174 | char *kbuff; | 173 | char *kbuff; |
175 | unsigned long base; | ||
176 | uint8_t image[4096]; | 174 | uint8_t image[4096]; |
177 | 175 | ||
178 | if (argc > 1) { | 176 | if (argc > 1) { |
@@ -189,9 +187,9 @@ int main(int argc, char **argv) | |||
189 | 187 | ||
190 | kbuff = get_klog_buff(&klen); | 188 | kbuff = get_klog_buff(&klen); |
191 | 189 | ||
192 | len = get_last_jit_image(kbuff, klen, image, sizeof(image), &base); | 190 | len = get_last_jit_image(kbuff, klen, image, sizeof(image)); |
193 | if (len > 0 && base > 0) | 191 | if (len > 0) |
194 | get_asm_insns(image, len, base, opcodes); | 192 | get_asm_insns(image, len, opcodes); |
195 | 193 | ||
196 | put_klog_buff(kbuff); | 194 | put_klog_buff(kbuff); |
197 | 195 | ||