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

zpoline integration for an option to hijack library #524

Merged
merged 5 commits into from
Aug 1, 2023

Conversation

thehajime
Copy link
Member

this is still under progress but we've been working on another implementation of hijack library. More to come soon and will publish as (non-draft) a pull request here.

https://github.com/yasukata/zpoline

@thehajime thehajime force-pushed the zpoline-lkl branch 4 times, most recently from 046f0e0 to e6e1430 Compare June 14, 2023 22:46
Documentation/lkl.txt Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
Documentation/lkl.txt Outdated Show resolved Hide resolved
Documentation/lkl.txt Outdated Show resolved Hide resolved
Documentation/lkl.txt Outdated Show resolved Hide resolved
Documentation/lkl.txt Outdated Show resolved Hide resolved
@thehajime thehajime force-pushed the zpoline-lkl branch 5 times, most recently from 80a4d3a to ee602d8 Compare June 28, 2023 02:10
When epoll_create of host syscall fails, it returns a negative integer,
not zero.  Thus the condition of if statement was wrong.  This commit
fixes this issue.

Signed-off-by: Hajime Tazaki <[email protected]>
This is problematic when an application uses TLS on thread 0, and LKL is
loaded via dlmopen.

when lkl_syscall is called, it tries to get pthread_key but there are
existing key/data, then lkl_syscall uses the existing one and it's not
task_struct so, crashed.

The root cause is that __pthread_keys is a global symbol and isolated
via namespace created by dlmopen, while pthread_getspecific looks at the
storage of the thread, which are not isolated via dlmopen.

There are a discussion which I found.
- pthread_key_create, pthread_setspecific are incompatible with dlmopen
https://sourceware.org/bugzilla/show_bug.cgi?id=24776

A work around is to avoid using pthread_key API when LKL is loaded via
dlmopen(3) and replace TLS function upon the initialization.  We only
fixed for posix host environment as dlmopen(3) is only usable on Linux
implementation (AFAIK).

Signed-off-by: Hajime Tazaki <[email protected]>
This commit add a testcase when LKL is loaded via dlmopen(3) function
call.  In this situation, the thread specific data which LKL uses
behaves wrong and cause an unconditional memory access.

This test should detect this case.

note 230614: the test hungs at this moment on the multiple
pthread_exit(), which is due to a lock handling on load of libgcc_s.so.
Still investigating what's going on.  If we replace dlmopen with dlopen,
everything goes fine..

Signed-off-by: Hajime Tazaki <[email protected]>
This commit add an exception to the checkpatch.pl to silence warnings of
compiler attributes styles (e.g., __unused, __alias, etc), as the
userspace code used in LKL is hard to include headers from
include/linux/compiler.h and tools/include/linux/compiler.h.

Signed-off-by: Hajime Tazaki <[email protected]>
@thehajime thehajime marked this pull request as ready for review July 26, 2023 00:48
@thehajime thehajime requested a review from tavip July 26, 2023 00:48
@thehajime
Copy link
Member Author

sorry to be late. the patchset is ready for review and please take a look at it. thanks !


- Build
```
make -C tools/lkl -j8 zpoine=../zpoline

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: zpoine

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed.

This commit introduces an integration with zpoline (*1), which is a
mechanism to rewrite binary upon loading.  zpoline allows us to replace
symbols of system call to different functions, which current LKL hijack
library does the same thing in a different way, by using symbol
replacement via LD_PRELOAD.

The benefit of zpoline is that the replacement of syscall is at the
instruction of `syscall` or `sysenter`, which userspace program can
catch all syscalls,  while the approach based on LD_PRELOAD cannot when
the symbols of interet are hidden within libc (e.g., __socket).

For more detail about the internal of zpoline, take a look at *1.

*1: https://github.com/yasukata/zpoline

Signed-off-by: Hajime Tazaki <[email protected]>
Copy link
Member

@tavip tavip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work!

@thehajime thehajime merged commit 182efc8 into lkl:master Aug 1, 2023
6 of 7 checks passed
@thehajime thehajime deleted the zpoline-lkl branch August 1, 2023 00:46
@thehajime
Copy link
Member Author

thanks @AkihiroSuda @tavip for the review ! (Cc: @yasukata)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants