public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/30118] New: add_to_global_resize crashes when called in a non-base namespace
@ 2023-02-13 11:24 nimaa.hamidi at gmail dot com
  2023-02-13 11:27 ` [Bug dynamic-link/30118] " nimaa.hamidi at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: nimaa.hamidi at gmail dot com @ 2023-02-13 11:24 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 30118
           Summary: add_to_global_resize crashes when called in a non-base
                    namespace
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: nimaa.hamidi at gmail dot com
  Target Milestone: ---

Calling dlopen with RTLD_GLOBAL flag set results in segfault when it's called
from a non-base namespace. This is due to the fact that add_to_global_resize
does not take into account the global namespace does not exist yet. The
following code reproduces the issue.

--------------
docker run --rm -it ubuntu:devel bash
apt-get update
apt install g++-10
cd ~

cat >a.cpp <<EOF
// a.cpp
#include <iostream>
#include <dlfcn.h>

using namespace std;

int main () {
 void * handle = nullptr;
 bool mopen = true;

 if (mopen) {
 cout << "mopening libb.so" << endl;
 handle = dlmopen(LM_ID_NEWLM, "libb.so", RTLD_NOW | RTLD_LOCAL);
 } else {
 cout << "opening libb.so" << endl;
 handle = dlopen("libb.so", RTLD_NOW | RTLD_LOCAL);
 }

 void (*bfunc)();
 *(void**)(&bfunc) = dlsym(handle, "bfunc");
 bfunc();

 return 0;
}
EOF

cat >b.cpp <<EOF
// b.cpp
#include <iostream>
#include <dlfcn.h>

using namespace std;

extern "C" void bfunc() {
 cout << "bfunc in b.cpp is being called..." << endl;
 void * handle = dlopen("libc.so", RTLD_NOW | RTLD_GLOBAL);
 //void * handle = dlopen("libc.so", RTLD_NOW | RTLD_LOCAL);

 void (*cfunc)();
 *(void**)(&cfunc) = dlsym(handle, "cfunc");
 cfunc();
}
EOF

cat >c.cpp <<EOF
// c.cpp
#include <iostream>

using namespace std;

extern "C" void cfunc() {
 cout << "cfunc in c.cpp is being called..." << endl;
}
EOF

g++-10 a.cpp -o a -ldl -Wl,-rpath `pwd`
g++-10 b.cpp -o libb.so -shared -fPIC -ldl -Wl,-rpath `pwd`
g++-10 c.cpp -o libc.so -shared -fPIC

--------------

Finally, when running LD_DEBUG=all ./a, it crashes with the following log:

--------------
 902:   symbol=_ZNSt8ios_base4InitD1Ev; lookup in file=/root/libb.so [1]
 902:   symbol=_ZNSt8ios_base4InitD1Ev; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__cxa_finalize; lookup in file=/root/libb.so [1]
 902:   symbol=__cxa_finalize; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__cxa_finalize; lookup in file=/lib/aarch64-linux-gnu/libc.so.6
[1]
 902:   symbol=_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc; lookup
in file=/root/libb.so [1]
 902:   symbol=_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc; lookup
in file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=_ZNSolsEPFRSoS_E; lookup in file=/root/libb.so [1]
 902:   symbol=_ZNSolsEPFRSoS_E; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__cxa_atexit; lookup in file=/root/libb.so [1]
 902:   symbol=__cxa_atexit; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__cxa_atexit; lookup in file=/lib/aarch64-linux-gnu/libc.so.6
[1]
 902:   symbol=_ZNSt8ios_base4InitC1Ev; lookup in file=/root/libb.so [1]
 902:   symbol=_ZNSt8ios_base4InitC1Ev; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__gmon_start__; lookup in file=/root/libb.so [1]
 902:   symbol=__gmon_start__; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__gmon_start__; lookup in file=/lib/aarch64-linux-gnu/libc.so.6
[1]
 902:   symbol=__gmon_start__; lookup in file=/lib/ld-linux-aarch64.so.1 [0]
 902:   symbol=__gmon_start__; lookup in file=/lib/aarch64-linux-gnu/libm.so.6
[1]
 902:   symbol=__gmon_start__; lookup in
file=/lib/aarch64-linux-gnu/libgcc_s.so.1 [1]
 902:   symbol=__gmon_start__; lookup in file=/root/libc.so [1]
 902:   symbol=__gmon_start__; lookup in
file=/lib/aarch64-linux-gnu/libstdc++.so.6 [1]
 902:   symbol=__gmon_start__; lookup in file=/lib/aarch64-linux-gnu/libc.so.6
[1]
 902:   symbol=__gmon_start__; lookup in file=/lib/aarch64-linux-gnu/libm.so.6
[1]
 902:   symbol=__gmon_start__; lookup in file=/lib/ld-linux-aarch64.so.1 [0]
 902:   symbol=__gmon_start__; lookup in
file=/lib/aarch64-linux-gnu/libgcc_s.so.1 [1]
Segmentation fault
--------------

LIBC version:
--------------
$ ldd --version
ldd (Ubuntu GLIBC 2.36-0ubuntu4) 2.36
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper
--------------

The error won’t happen if I dlopen with RTLD_LOCAL in b.cpp rather than
RTLD_GLOBAL. I would appreciate any help on what I’m doing wrong here.

Best,
Nima

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

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

* [Bug dynamic-link/30118] add_to_global_resize crashes when called in a non-base namespace
  2023-02-13 11:24 [Bug dynamic-link/30118] New: add_to_global_resize crashes when called in a non-base namespace nimaa.hamidi at gmail dot com
@ 2023-02-13 11:27 ` nimaa.hamidi at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: nimaa.hamidi at gmail dot com @ 2023-02-13 11:27 UTC (permalink / raw)
  To: glibc-bugs

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

Nima Hamidi <nimaa.hamidi at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nimaa.hamidi at gmail dot com

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

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

end of thread, other threads:[~2023-02-13 11:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13 11:24 [Bug dynamic-link/30118] New: add_to_global_resize crashes when called in a non-base namespace nimaa.hamidi at gmail dot com
2023-02-13 11:27 ` [Bug dynamic-link/30118] " nimaa.hamidi 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).