I'm facing a strange problem with dlmopen() on Tumbleweed, FC34 and
Ubuntu 21.04. The dlopen() functions work fine though. The problem
doesn't happen on Leap 42.3 and all debian versions. The workaround is
to set the LD_DEBUG environment variable. The other work around is to
modify /etc/nsswitch.conf to not use only files. This issue was first
reported on 24 Mar 2021 by someone. I too have reported multiple
conditions under which the bug occurs and it still continues. This is
an upstream issue but causing issues for multiple distributions
downstream.
https://sourceware.org/bugzilla/show_bug.cgi?id=27646
Any application that uses dlmopen() and calls any of the getpwent,
getgrent, getaliasent, etc either segfault or give error on missing
libnss symbols.
It is trivial to simulate the issue. The below code snippets foo.c and
test.c exploits the issue.
cat <<EOF>foo.c
#include
#include
void bar1()
{
struct passwd *pw;
pw = getpwent();
if (pw)
printf("%s\n", pw->pw_name);
}
EOF
cat <<EOF>test.c
#define _GNU_SOURCE
#include
#include
int
main(int argc, char **argv)
{
void *handle;
int (*func) ();
if (!(handle = dlmopen(LM_ID_NEWLM, "./libfoo.so", RTLD_NOW))) {
perror("dlmopen");
return 1;
}
func = dlsym(handle, "bar1");
(*func)();
return 0;
}
EOF
# On Tumbleweed
gcc -fPIC -shared foo.c -o libfoo.so
gcc test.c -o test -ldl
./test
./test: symbol lookup error: /lib64/libnss_compat.so.2: undefined
symbol: _nss_compat_endaliasent
# setting LD_DEBUG=unused fixes the issue
env LD_DEBUG=unused ./test
root
# On Fedora 34
gcc -fPIC -shared foo.c -o libfoo.so
gcc test.c -o test -ldl
./test
Segmentation fault (core dumped)
echo This command will not segfault
env LD_DEBUG=unused ./test
root
# On Ubuntu 21.04
gcc -fPIC -shared foo.c -o libfoo.so
gcc test.c -o test -ldl
./test
./test: symbol lookup error: /lib/x86_64-linux-gnu/libnss_files.so.2:
undefined symbol: _nss_files_getcanonname_r
# setting LD_DEBUG=unused fixes the issue
env LD_DEBUG=unused ./test
root
--
Regards Manvendra - http://www.indimail.org
GPG Pub Key
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC7CBC760014D250C