public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
@ 2021-04-21 19:40 ` fweimer at redhat dot com
  2021-05-31 18:10 ` fweimer at redhat dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2021-04-21 19:40 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=24773

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
  2021-04-21 19:40 ` [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen fweimer at redhat dot com
@ 2021-05-31 18:10 ` fweimer at redhat dot com
  2021-05-31 18:10 ` fweimer at redhat dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2021-05-31 18:10 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com

--- Comment #9 from Florian Weimer <fweimer at redhat dot com> ---
Bug 26955 raises the related issue that there is just mapping per thread from
key to data, but the data structure that maintains the keys is duplicated if
libc.so is loaded more than once.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
  2021-04-21 19:40 ` [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen fweimer at redhat dot com
  2021-05-31 18:10 ` fweimer at redhat dot com
@ 2021-05-31 18:10 ` fweimer at redhat dot com
  2021-08-08  5:15 ` alxchk at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2021-05-31 18:10 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sware at reimardoeffinger dot de

--- Comment #10 from Florian Weimer <fweimer at redhat dot com> ---
*** Bug 26955 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-05-31 18:10 ` fweimer at redhat dot com
@ 2021-08-08  5:15 ` alxchk at gmail dot com
  2021-08-08 11:06 ` sware at reimardoeffinger dot de
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: alxchk at gmail dot com @ 2021-08-08  5:15 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Oleksii Shevchuk <alxchk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alxchk at gmail dot com

--- Comment #11 from Oleksii Shevchuk <alxchk at gmail dot com> ---
/tmp > cat ldr.c 
#define _GNU_SOURCE
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

int main() {
    pthread_key_t key = 0xFFFFFFFF;
    pthread_key_create(&key, NULL);
    pthread_setspecific(key, (void*) 0xDEADBEEF);
    printf("[tid=%lx] Key created: %u with value %p\n", pthread_self(), key,
pthread_getspecific(key));

    printf("[New LMID]\n");
    void *ldr2 = dlmopen(LM_ID_NEWLM, "./ldr2.so", RTLD_NOW | RTLD_LOCAL);
    if (!ldr2) {
        printf("ERR: %s\n", dlerror());
        return -1;
    }

    printf("[Base LMID]\n");
    ldr2 = dlmopen(LM_ID_BASE, "./ldr2.so", RTLD_NOW | RTLD_LOCAL);
    if (!ldr2) {
        printf("ERR: %s\n", dlerror());
        return -1;
    }

    return 0;
}


/tmp > cat ldr2.c
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>

void init(int, char*[], char*[]) {
    pthread_key_t key = 0xFFFFFFFF;
    pthread_key_create(&key, NULL);
    printf("[tid=%lx] Key created: %u\n", pthread_self(), key);
    printf("[tid=%lx] Key value: %p\n", pthread_self(),
pthread_getspecific(key));
}

__attribute__((section(".init_array"))) void (* __init)(int, char*[], char*[])
= init;


/tmp > gcc -o ldr ldr.c -pthread  -ldl
/tmp > gcc -shared -o ldr2.so ldr2.c -pthread     
/tmp > ./ldr
[tid=7fe649b0a740] Key created: 0 with value 0xdeadbeef
[New LMID]
[tid=7fe649b0a740] Key created: 0
[tid=7fe649b0a740] Key value: 0xdeadbeef
[Base LMID]
[tid=7fe649b0a740] Key created: 2
[tid=7fe649b0a740] Key value: (nil)


Pain..

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2021-08-08  5:15 ` alxchk at gmail dot com
@ 2021-08-08 11:06 ` sware at reimardoeffinger dot de
  2021-11-20 16:37 ` ppluzhnikov at google dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: sware at reimardoeffinger dot de @ 2021-08-08 11:06 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

--- Comment #12 from Reimar Döffinger <sware at reimardoeffinger dot de> ---
I think your example is pretty much the same as mine in
https://sourceware.org/bugzilla/show_bug.cgi?id=26955
I "fixed" it by using a LD_PRELOAD that provides its own implementation of
pthread_key_create etc. that are not entirely correct (lowish fixed limit of
keys, no freeing, implemented using the thread_local keyword) but work for my
purpose.
Unfortunately dlmopen still seems to be the most realistic solution when one
has the misfortune of having a process using Python3 that has a library
dependency that requires Python2.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2021-08-08 11:06 ` sware at reimardoeffinger dot de
@ 2021-11-20 16:37 ` ppluzhnikov at google dot com
  2022-10-01 17:16 ` jadahl at gmail dot com
  2023-04-24 12:17 ` kristofer.berggren at gmail dot com
  7 siblings, 0 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2021-11-20 16:37 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot com

--- Comment #13 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
There is a more fundamental problem with pthread_key_create from dlmopen'ed
copy of libpthread: it creates duplicate keys (since it looks in the local copy
of __pthread_keys).

The key is then used as an index into THREAD_SELF->specific_1stblock etc, which
is shared between all the namespaces, with a disastrous result.

Real-life example: https://stackoverflow.com/q/70030529

Trivial repro:

// --- cut ---
#define _GNU_SOURCE
#include <assert.h>
#include <dlfcn.h>
#include <pthread.h>

typedef int (*pthread_key_create_t)(pthread_key_t *, void (*)(void*));
int main()
{
  pthread_key_t k1, k2;
  int rc;

  rc = pthread_key_create(&k1, NULL);
  void *h = dlmopen(LM_ID_NEWLM, "libpthread.so.0", RTLD_LAZY);
  assert(h != NULL);

  pthread_key_create_t fn = (pthread_key_create_t)dlsym(h,
"pthread_key_create");
  assert(fn != NULL);

  rc = fn(&k2, NULL);
  assert(rc == 0);
  assert(k2 != k1);

  return 0;
}
// --- cut ---

gcc -g t.c -pthread -ldl -Wall -Wextra
./a.out
a.out: t.c:21: main: Assertion `k2 != k1' failed.
Aborted

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2021-11-20 16:37 ` ppluzhnikov at google dot com
@ 2022-10-01 17:16 ` jadahl at gmail dot com
  2023-04-24 12:17 ` kristofer.berggren at gmail dot com
  7 siblings, 0 replies; 8+ messages in thread
From: jadahl at gmail dot com @ 2022-10-01 17:16 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Jonas Ådahl <jadahl at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jadahl at gmail dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen
       [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2022-10-01 17:16 ` jadahl at gmail dot com
@ 2023-04-24 12:17 ` kristofer.berggren at gmail dot com
  7 siblings, 0 replies; 8+ messages in thread
From: kristofer.berggren at gmail dot com @ 2023-04-24 12:17 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=24776

Kristofer Berggren <kristofer.berggren at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kristofer.berggren at gmail dot co
                   |                            |m

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-24 12:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-24776-131@http.sourceware.org/bugzilla/>
2021-04-21 19:40 ` [Bug nptl/24776] pthread_key_create, pthread_setspecific are incompatible with dlmopen fweimer at redhat dot com
2021-05-31 18:10 ` fweimer at redhat dot com
2021-05-31 18:10 ` fweimer at redhat dot com
2021-08-08  5:15 ` alxchk at gmail dot com
2021-08-08 11:06 ` sware at reimardoeffinger dot de
2021-11-20 16:37 ` ppluzhnikov at google dot com
2022-10-01 17:16 ` jadahl at gmail dot com
2023-04-24 12:17 ` kristofer.berggren at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).