Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

keylog module causes deadlock when trying dynamically load c-shared poseidon on older glibc #62

Open
paul-axe opened this issue Oct 19, 2024 · 0 comments

Comments

@paul-axe
Copy link

Hi.

I faced an issue when tried to load poseidon as c-shared library in an obsolete evnironment and it resulted in a deadlock. After the debugging session it's turned out that the issue is because of keylog module, and particularly in user.Curent() of os/user . The issue is most likely because the call is triggered from the library contrustror, which loads keylog module which creates an NewKeyLog instance in the init stage:

var (
curTask *structs.Task
// Struct to monitor keystrokes.
ksmonitor, _ = NewKeyLog()

func NewKeyLog() (KeyLogWithMutex, error) {
curUser, err := user.Current()

As far as I understand the problem is related to a multithreaded loading of the dynamic library (user.Current loads libc to execute getpwuid_r) while another thread holds the dlopen lock for loading poseidon library. It also seems that problem is fixed/mitigated somehow in the libc 2.35. The problem also doesnt appear when loading poseidon using LD_PRELOAD.

Steps to reproduce:

  1. Compile poseidon as c-shared library
  2. Try to load it with libc <= 2.34 (any ubuntu before 22.04 release)
$ docker run -ti -v $(pwd):/app python:2 python2 -c '__import__("ctypes").CDLL("/app/poseidon.so")'
debug string: true
  1. You've got a deadlock

Possible solution

Probably moving the call of NewKeyLog from init/constructor stage to a direct call from outside should fix the issue

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant