Skip to content
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

i#5431: Support glibc's rseq support #5711

Merged
merged 42 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0115daa
i#5431: Support GLIBC rseq support
abhinav92003 Oct 28, 2022
c6ac74d
Some fixes.
abhinav92003 Oct 28, 2022
d07698f
Fix api.rseq
abhinav92003 Oct 28, 2022
3b0805d
Add missing conditional compilation.
abhinav92003 Oct 29, 2022
f7eecc6
Merge branch 'master' into i5431-glibc-rseq
abhinav92003 Oct 29, 2022
a88e7d7
Cleanup.
abhinav92003 Oct 29, 2022
1b8a871
Add tmate
abhinav92003 Oct 29, 2022
0a0dfce
Revert "Add tmate"
abhinav92003 Oct 29, 2022
52e14e5
Cleanup.
abhinav92003 Oct 29, 2022
64cb131
Revert "Revert "Add tmate""
abhinav92003 Oct 29, 2022
cd069e5
Fix build
abhinav92003 Oct 29, 2022
51190be
Use dynamo_control_via_attach to detect attach mode
abhinav92003 Oct 31, 2022
ba77f10
Revert ubuntu-22 test filters.
abhinav92003 Oct 31, 2022
79d80f3
Remove the reached image entry hook, which is not very reliable.
abhinav92003 Oct 31, 2022
b80ec25
Remove spurious files.
abhinav92003 Oct 31, 2022
f2c3d7f
Merge branch 'master' into i5431-glibc-rseq
abhinav92003 Nov 1, 2022
25bb369
Remove hook in interp and adjust logic to locate rseq_cs entries.
abhinav92003 Nov 1, 2022
71d4881
Cleanup.
abhinav92003 Nov 1, 2022
782c811
Revert "Revert "Revert "Add tmate"""
abhinav92003 Nov 1, 2022
c418d74
Detect app's glibc instead of relying on the macro.
abhinav92003 Nov 1, 2022
8c2744a
Move check_glibc_rseq_support after lock
abhinav92003 Nov 1, 2022
1789ef4
Add ubuntu-22 test filters back.
abhinav92003 Nov 1, 2022
b57460b
Cleanup.
abhinav92003 Nov 1, 2022
599c8cc
Fix rseq registration in rseq_thread_loop
abhinav92003 Nov 1, 2022
9e059ab
Cleanup.
abhinav92003 Nov 2, 2022
1b69dad
Fix ENOSYS assertion in tests.
abhinav92003 Nov 2, 2022
bf8a606
Merge branch 'master' into i5431-glibc-rseq
abhinav92003 Nov 10, 2022
62e5908
Revert previous design since it doesn't work on fully static binaries.
abhinav92003 Nov 10, 2022
cd6d8c8
Alternate method of detecting glibc rseq.
abhinav92003 Nov 10, 2022
ea7b07a
Add glibc 2.35+ support for aarch64, and prevent hardcoding rseq tls …
abhinav92003 Nov 10, 2022
8a0bedd
Some cleanup.
abhinav92003 Nov 10, 2022
7c0ae88
Some cleanup.
abhinav92003 Nov 11, 2022
77d30f0
Fix log.
abhinav92003 Nov 11, 2022
320713d
Clarify registered rseq check.
abhinav92003 Nov 11, 2022
6bfd645
Check expected glibc rseq offset first.
abhinav92003 Nov 11, 2022
c092a1a
Review comments.
abhinav92003 Nov 11, 2022
9752a29
Add comment about AArch32.
abhinav92003 Nov 11, 2022
9489250
Update AArch32 comment.
abhinav92003 Nov 11, 2022
d0654ff
Merge branch 'master' into i5431-glibc-rseq
abhinav92003 Nov 11, 2022
949bd92
Improve logs.
abhinav92003 Nov 13, 2022
ddf88fc
Merge branch 'master' into i5431-glibc-rseq
abhinav92003 Nov 16, 2022
d2f3bbf
Merge branch 'master' into i5431-glibc-rseq
abhinav92003 Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/unix/rseq_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ DECLARE_CXTSWPROT_VAR(static mutex_t rseq_trigger_lock,
INIT_LOCK_FREE(rseq_trigger_lock));
static volatile bool rseq_enabled;

/* The struct rseq registered by glibc is present in the struct pthread.
* As of glibc 2.35, it is present at the following offset from the app
* lib seg base. We check these offsets first and then fall back to a
* wider search. The linux.rseq test helps detect changes in these
* offsets in future glibc versions.
*/
#ifdef X86
# define GLIBC_RSEQ_OFFSET 2464
abhinav92003 marked this conversation as resolved.
Show resolved Hide resolved
#else
# define GLIBC_RSEQ_OFFSET -32
#endif

/* We require all threads to use the same TLS offset to point at struct rseq. */
static int rseq_tls_offset;

Expand Down Expand Up @@ -667,6 +679,19 @@ rseq_locate_tls_offset(void)
*/
int offset = 0;
byte *addr = get_app_segment_base(LIB_SEG_TLS);
if (addr > 0) {
byte *try_glibc_addr = addr + GLIBC_RSEQ_OFFSET;
if (try_struct_rseq(try_glibc_addr)) {
LOG(GLOBAL, LOG_LOADER, 2,
"Found glibc struct rseq @ " PFX " for thread => %s:%s0x%x\n",
try_glibc_addr, get_register_name(LIB_SEG_TLS),
(GLIBC_RSEQ_OFFSET < 0 ? "-" : ""), abs(GLIBC_RSEQ_OFFSET));
return GLIBC_RSEQ_OFFSET;
}
}
/* Either the app's glibc does not have rseq support (old glibc or disabled by app)
* or the offset of glibc's struct rseq has changed. We do a wider search now.
*/
byte *seg_bottom;
size_t seg_size;
if (addr > 0 && get_memory_info(addr, &seg_bottom, &seg_size, NULL)) {
Expand Down
8 changes: 4 additions & 4 deletions suite/tests/linux/rseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ register_rseq()
{
#ifdef GLIBC_RSEQ
if (__rseq_size > 0) {
/* Our glibc rseq handling in rseq_linux.c does not depend on the exact
* offset, but it does depend on it being in struct pthread, therefore
* the sign of __rseq_offset. Nevertheless, we check for the exact
* offset here so that we know if glibc changes how it handles rseq.
/* Our glibc rseq handling in rseq_linux.c checks the following offset
* first for the glibc-registered struct rseq. Though we do have a
* fallback that does a wider search, it would be good to keep the
* expected offset in sync with glibc changes.
*/
# ifdef X86
assert(__rseq_offset == 2464);
Expand Down