Skip to content

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

@paul-axe

Description

@paul-axe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions