-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic/Full Dynamic tracing error on ubuntu 20.04 #1231
Comments
Thanks very much for reporting this bug. I can reproduce the problem on Ubuntu 20.04.
I will take a look when I have some time. |
Hmm.. It shows 000000000001149 <b>:
1149: f3 0f 1e fa endbr64
114d: 55 push %rbp
114e: 48 89 e5 mov %rsp,%rbp
1151: 48 8d 3d ac 0e 00 00 lea 0xeac(%rip),%rdi # 2004 <_IO_stdin_used+0x4>
1158: b8 00 00 00 00 mov $0x0,%eax
115d: e8 ee fe ff ff callq 1050 <printf@plt>
1162: 90 nop
1163: 5d pop %rbp
1164: c3 retq
0000000000001165 <a>:
1165: f3 0f 1e fa endbr64
1169: 55 push %rbp
116a: 48 89 e5 mov %rsp,%rbp
116d: b8 00 00 00 00 mov $0x0,%eax
1172: e8 d2 ff ff ff callq 1149 <b>
1177: 90 nop
1178: 5d pop %rbp
1179: c3 retq
000000000000117a <main>:
117a: f3 0f 1e fa endbr64
117e: 55 push %rbp
117f: 48 89 e5 mov %rsp,%rbp
1182: b8 00 00 00 00 mov $0x0,%eax
1187: e8 d9 ff ff ff callq 1165 <a>
118c: b8 00 00 00 00 mov $0x0,%eax
1191: 5d pop %rbp
1192: c3 retq
1193: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
119a: 00 00 00
119d: 0f 1f 00 nopl (%rax) |
We've already seen |
The gcc info is as follows.
|
It can be reproduced with any test program. |
The actual error message was 'invalid permission' for the code address. Can you please test this? diff --git a/libmcount/dynamic.c b/libmcount/dynamic.c
index f228aa9b..6eaf51db 100644
--- a/libmcount/dynamic.c
+++ b/libmcount/dynamic.c
@@ -164,7 +164,8 @@ void mcount_freeze_code(void)
if (cp->frozen)
continue;
- mprotect(cp->page, CODE_CHUNK, PROT_READ|PROT_EXEC);
+ if (mprotect(cp->page, CODE_CHUNK, PROT_READ|PROT_EXEC) < 0)
+ pr_err("mprotect to freeze code page failed");
cp->frozen = true;
}
} |
Hello, thanks for the reply! I have tested this modification but the error output seems to be the same as the previous one, I didn't get the new added error message :
|
Thanks for the test. Regardless of the result I think we should have the change though. Can you try to build your test program with |
Hmm.. It works fine.
|
OK, then can you try this with the CF protection enabled binary? diff --git a/cmds/record.c b/cmds/record.c
index e750f053..c70da5f8 100644
--- a/cmds/record.c
+++ b/cmds/record.c
@@ -356,7 +356,7 @@ static void setup_child_environ(struct opts *opts, int argc, char *argv[])
put_libmcount_path(libpath);
setenv("XRAY_OPTIONS", "patch_premain=false", 1);
- setenv("GLIBC_TUNABLES", "glibc.cpu.hwcaps=-IBT,-SHSTK", 1);
+ setenv("GLIBC_TUNABLES", "glibc.cpu.x86_ibt=off:glibc.cpu.x86_shstk=off", 1);
}
static uint64_t calc_feat_mask(struct opts *opts) |
Hmm.. It doesn't work. It crashes as well. |
The followings glibc commits may be related to this problem.
|
Hmm.. Ubuntu 20.04 uses glibc-2.31, but it doesn't include both commits above. |
Hmm.. can you test this again and show me the error message? diff --git a/libmcount/mcount.c b/libmcount/mcount.c
index 8b7d3a82..2e534e00 100644
--- a/libmcount/mcount.c
+++ b/libmcount/mcount.c
@@ -704,8 +704,8 @@ static void segv_handler(int sig, siginfo_t *si, void *ctx)
break;
if (si->si_code == sigsegv_codes[i].code) {
- pr_warn("Segmentation fault: %s (addr: %p)\n",
- sigsegv_codes[i].msg, si->si_addr);
+ pr_warn("Segmentation fault: %s (addr: %p, error: %x)\n",
+ sigsegv_codes[i].msg, si->si_addr, si->si_errno);
break;
}
} |
Hmm.. |
It shows diff --git a/libmcount/mcount.c b/libmcount/mcount.c
index 8b7d3a82..06e48a55 100644
--- a/libmcount/mcount.c
+++ b/libmcount/mcount.c
@@ -704,8 +704,8 @@ static void segv_handler(int sig, siginfo_t *si, void *ctx)
break;
if (si->si_code == sigsegv_codes[i].code) {
- pr_warn("Segmentation fault: %s (addr: %p)\n",
- sigsegv_codes[i].msg, si->si_addr);
+ pr_warn("Segmentation fault: %s (addr: %p, error: %s)\n",
+ sigsegv_codes[i].msg, si->si_addr, strerror(si->si_errno));
break;
}
} |
I'm not sure si->si_errno is same as errno so that we can use strerror(). Actually I expected something other (like arch/kernel specific one). |
It might be a bug in glibc-2.31 so reported this in the glibc mailing list at https://sourceware.org/bugzilla/show_bug.cgi?id=27300. Let's see if there is a way to avoid this problem. |
@namhyung You can reproduce this problem in WSL2 Ubuntu 20.04 if you have a windows PC. |
This problem happens also in Ubuntu 20.10, which uses |
I've checked the Ubuntu's glibc source and it seems to have an out of tree kernel patch to control CET. (but still not sure why the glibc tunables don't work). Anyway can you please test the below patch? diff --git a/cmds/record.c b/cmds/record.c
index e750f053..42225023 100644
--- a/cmds/record.c
+++ b/cmds/record.c
@@ -357,6 +357,11 @@ static void setup_child_environ(struct opts *opts, int argc, char *argv[])
put_libmcount_path(libpath);
setenv("XRAY_OPTIONS", "patch_premain=false", 1);
setenv("GLIBC_TUNABLES", "glibc.cpu.hwcaps=-IBT,-SHSTK", 1);
+
+#ifdef ARCH_CET_DISABLE
+ /* 3 = GNU_PROPERTY_X86_FEATURE_1_(IBT|SHSTK) */
+ prctl(ARCH_CET_DISABLE, 3, 0, 0, 0);
+#endif
}
static uint64_t calc_feat_mask(struct opts *opts) |
Hmm.. I tested it on Ubuntu 20.04, but |
Maybe I need to include the headers. Can you please try again? diff --git a/cmds/record.c b/cmds/record.c
index 77887c26..d259923f 100644
--- a/cmds/record.c
+++ b/cmds/record.c
@@ -18,6 +18,8 @@
#include <sys/eventfd.h>
#include <sys/resource.h>
#include <sys/epoll.h>
+#include <sys/prctl.h>
+#include <asm/prctl.h>
#include <sys/personality.h>
#include "uftrace.h"
@@ -360,7 +362,10 @@ static void setup_child_environ(struct opts *opts, int argc, char *argv[])
#ifdef ARCH_CET_DISABLE
/* HACK: for Ubuntu 20.04 (3 = GNU_PROPERTY_X86_FEATURE_1_(IBT|SHSTK)) */
- prctl(ARCH_CET_DISABLE, 3, 0, 0, 0);
+ if (prctl(ARCH_CET_DISABLE, 3, 0, 0, 0))
+ pr_dbg("prctl(ARCH_CET_DISABLE) failed: %m\n");
+ else
+ pr_dbg("prctl(ARCH_CET_DISABLE): ok\n");
#endif
}
|
I mean |
Hmm.. ok. Can you strace your binary (without uftrace) and capture the output? |
Here is the
|
This is the ARCH_CET_STATUS according to https://lore.kernel.org/lkml/20180710222639.8241-28-yu-cheng.yu@intel.com/. But kernel returns -EINVAL so it might not have the CET support. Hmm.. |
Hmm.. It looks like a mismatching problem in Ubuntu not supporting |
This error happened when using uftrace from binutils2.35.1. |
Thanks for the hint! I'll check what changed in the binutils recently. |
After some simple investigation, it is found that even the following code can not execute the command correctly in aarch64 environment: int main() { WARN: child terminated by signal: 7: Bus error Look at the log,function mcount_init_file is not executed. Is there something wrong with initialize mcount library? Because I haven't tracked the code yet, I only know the information above. In addition, I have multiple platforms here. If you need to test after modifying the code, you can let me know. I can assist in testing |
Thanks for the investigation. I'm busy with other stuff these days so couldn't have a time to look at it. The mcount_init_file() is the first function when uftrace starts to trace so it seems to fail before the actual tracing.. hmm. |
@wangmingyu84 Thanks very much for your help. Could you please show us the full log of running the following command for the example above?
|
Can you please test check/dynamic-fix? |
@namhyung Thanks very much for the fix. It works fine now in Ubuntu 20.04 (x86_64).
@wangmingyu84 I don't see an error when testing in aarch64. Could you test it again in your aarch64 environment with @namhyung's fix in check/dynamic-fix? |
The bug in Ubuntu 20.04(binutils 2.24) and Ubuntu 20.10(binutils 2.35.1) may be not the same. |
OK, so we have another problem in Ubuntu 20.01... hmm. |
Let's discuss the 20.10 issue in a separate thread and close this. |
Hi @leimaohui, I tested it on Ubuntu 20.04 in aarch64 only. But it didn't have any problem even without this fix. |
Hi @leimaohui, it works fine on Ubuntu 20.10 in x86_64 as follows.
I haven't tested it on Ubuntu 20.10 in aarch64 though. |
The Ubuntu 20.10 in x86_64 uses binutils 2.35.1 but works fine now.
|
Yes, this issue only happens on aarch64. We have no problems on arm and x86-64. |
Hello, when I was testing full dynamic tracing on ubuntu 20.04, the following error output shows:
But when I tried the same test on ubuntu 18.04, the output is as expected and without any error during tracing.
The code in test.c is:
And during the test of dynamic tracing, error occur during gcc compile time with the command in the tutorial:
It can be solved by:
but during the trace, the following error shows:
The text was updated successfully, but these errors were encountered: