Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzztaiki/379919fdf47a0dcc117697fd962e53fb to your computer and use it in GitHub Desktop.
Save buzztaiki/379919fdf47a0dcc117697fd962e53fb to your computer and use it in GitHub Desktop.
LD_PRELOAD と Gnome Shell と Linux Kernel Capability

環境変数 LD_PRELOADLD_LIBRARY_PATH を設定した状態で gnome-shell を起動しても gnome-shell やその子供達には引き継がれないよという話。

はまったので雑にメモ。

きっかけ

https://github.com/lincheney/fzf-tab-completion を常に readline から使いたくて ~/pam_environment に LD_PRELOAD を書いたのだけど以下の状態になった。

  • 黒いコンソールでは使える
  • Openbox では使える
  • Gnome-Shell では LD_PRELOAD が消えている。

pam で無効化されてるのではとか思って以下も試してみたけれど全部だめだった

  • ~/pam_environment
  • /etc/environment
  • ~/.config/environment.d/*.conf
  • /etc/environment.d/*.conf

そしてググったら https://bugzilla.redhat.com/show_bug.cgi?id=1847314 が見つかった。

原因

ArchLinux や Fedora では gnome-shell で rt_scheduler を有効とするために setcap されていて

どうやら setcap していると ld_* が無視されるようになるって話っぽい。

https://man.archlinux.org/man/ld.so.8 にも以下のように書いてある。

For security reasons, if the dynamic linker determines that a binary should be run in secure-execution mode, the effects of some environment variables are voided or modified, and furthermore those environment variables are stripped from the environment, so that the program does not even see the definitions. Some of these environment variables affect the operation of the dynamic linker itself, and are described below. A binary is executed in secure-execution mode if the AT_SECURE entry in the auxiliary vector (see getauxval(3)) has a nonzero value. This entry may have a nonzero value for various reasons, including:

  • A process with a non-root user ID executed a binary that conferred capabilities to the process.

setuid root したバイナリを使うか ld.so.confld.so.preload を使えとの事。こわ。

余談

environment.d とか初めて知ったけどわりと便利そうというか、pam_environment と比べると書式に自由度がありそうな感じがする。man environment.d で man が引ける。ユーザーセッションが動くときに有効になるそうなので、/etc/environment よりも安全そうに思える。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment