Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Mention /etc/ld.so.preload to avoid LD_PRELOAD restrictions #48

Open
10110111 opened this issue May 21, 2019 · 1 comment
Open

Mention /etc/ld.so.preload to avoid LD_PRELOAD restrictions #48

10110111 opened this issue May 21, 2019 · 1 comment

Comments

@10110111
Copy link

LD_PRELOAD is ignored when you run setuid binaries, unset by sudo, while /etc/ld.so.preload is honored in all these cases. Also, in some cases other entities (like IDEs) may try to make a clean environment, which will also remove gtk3-nocsd from the preloaded libraries list.

So I think it'd be good to mention this approach in the README.

@10110111
Copy link
Author

Actually, I've found that all this preloading business conflicts with some other libraries that expect to be loaded before all: e.g., libasan. Thus, both LD_PRELOAD and /etc/ld.so.preload are unacceptable to me.

But I've devised a better way, which I've implemented on my Ubuntu 19.04 system, and which works both system-wide (e.g. for root user), as well as without conflicts with libasan. Here's what I did:

origGLIB=$(ldd `which gtk-update-icon-cache` |
            sed -n 's@^\s*libglib-2.0.so.0 => \([^ ]\+\).*@\1@p')
libdir=${origGLIB%/libglib-2.0.so.0}/gtk3-nocsd
# Optional (if we want to disable CSDs unconditionally; I did)
sed -i 's@g_getenv ("GTK_CSD")@"0"@' gtk3-nocsd.c
# Add libglib-2.0.so.0 to NEEDED list, even though it's not statically used. We'll
# change reference to its actual soname to the name of symlink we'll create.
sed -i "s@.*-soname,libgtk3-no.*@\0 -Wl,-rpath,$libdir -Wl,--no-as-needed -lglib-2.0@"\
    Makefile
make
# Avoid patchelf --add-needed/--replace-needed: they'll likely corrupt the
# binary (at least in patchelf 0.10).
# Just rely on the fact that libgtk3-nocsd.so.0 only references the original glib-2.0
# library, so we can change _all_ the references to it to the symlink name.
sed -i '[email protected]@libglib2-orig.so@g' libgtk3-nocsd.so.0
sudo sh -c "mkdir -pv '$libdir' &&
            cp -vi libgtk3-nocsd.so.0 '$libdir'/libglib-2.0.so.0 &&
            ln -sv '$origGLIB' '$libdir'/libglib2-orig.so &&
            echo '$libdir' > /etc/ld.so.conf.d/00-gtk3-nocsd.conf &&
            ldconfig"

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

No branches or pull requests

1 participant