Commit ed4afd45 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by David S. Miller

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: default avatarAlexei Starovoitov <ast@plumgrid.com>
Acked-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e0a1272c
...@@ -43,8 +43,7 @@ static void get_exec_path(char *tpath, size_t size) ...@@ -43,8 +43,7 @@ static void get_exec_path(char *tpath, size_t size)
free(path); free(path);
} }
static void get_asm_insns(uint8_t *image, size_t len, unsigned long base, static void get_asm_insns(uint8_t *image, size_t len, int opcodes)
int opcodes)
{ {
int count, i, pc = 0; int count, i, pc = 0;
char tpath[256]; char tpath[256];
...@@ -107,13 +106,13 @@ static void put_klog_buff(char *buff) ...@@ -107,13 +106,13 @@ static void put_klog_buff(char *buff)
} }
static int get_last_jit_image(char *haystack, size_t hlen, static int get_last_jit_image(char *haystack, size_t hlen,
uint8_t *image, size_t ilen, uint8_t *image, size_t ilen)
unsigned long *base)
{ {
char *ptr, *pptr, *tmp; char *ptr, *pptr, *tmp;
off_t off = 0; off_t off = 0;
int ret, flen, proglen, pass, ulen = 0; int ret, flen, proglen, pass, ulen = 0;
regmatch_t pmatch[1]; regmatch_t pmatch[1];
unsigned long base;
regex_t regex; regex_t regex;
if (hlen == 0) if (hlen == 0)
...@@ -136,7 +135,7 @@ static int get_last_jit_image(char *haystack, size_t hlen, ...@@ -136,7 +135,7 @@ static int get_last_jit_image(char *haystack, size_t hlen,
ptr = haystack + off - (pmatch[0].rm_eo - pmatch[0].rm_so); ptr = haystack + off - (pmatch[0].rm_eo - pmatch[0].rm_so);
ret = sscanf(ptr, "flen=%d proglen=%d pass=%d image=%lx", ret = sscanf(ptr, "flen=%d proglen=%d pass=%d image=%lx",
&flen, &proglen, &pass, base); &flen, &proglen, &pass, &base);
if (ret != 4) if (ret != 4)
return 0; return 0;
...@@ -162,7 +161,7 @@ static int get_last_jit_image(char *haystack, size_t hlen, ...@@ -162,7 +161,7 @@ static int get_last_jit_image(char *haystack, size_t hlen,
assert(ulen == proglen); assert(ulen == proglen);
printf("%d bytes emitted from JIT compiler (pass:%d, flen:%d)\n", printf("%d bytes emitted from JIT compiler (pass:%d, flen:%d)\n",
proglen, pass, flen); proglen, pass, flen);
printf("%lx + <x>:\n", *base); printf("%lx + <x>:\n", base);
regfree(&regex); regfree(&regex);
return ulen; return ulen;
...@@ -172,7 +171,6 @@ int main(int argc, char **argv) ...@@ -172,7 +171,6 @@ int main(int argc, char **argv)
{ {
int len, klen, opcodes = 0; int len, klen, opcodes = 0;
char *kbuff; char *kbuff;
unsigned long base;
uint8_t image[4096]; uint8_t image[4096];
if (argc > 1) { if (argc > 1) {
...@@ -189,9 +187,9 @@ int main(int argc, char **argv) ...@@ -189,9 +187,9 @@ int main(int argc, char **argv)
kbuff = get_klog_buff(&klen); kbuff = get_klog_buff(&klen);
len = get_last_jit_image(kbuff, klen, image, sizeof(image), &base); len = get_last_jit_image(kbuff, klen, image, sizeof(image));
if (len > 0 && base > 0) if (len > 0)
get_asm_insns(image, len, base, opcodes); get_asm_insns(image, len, opcodes);
put_klog_buff(kbuff); put_klog_buff(kbuff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment