AppImageCrafters / AppRun

AppDir runtime components
MIT License
26 stars 10 forks source link

`libapprun_hooks.so` Can Break Programs By Setting Working Directory #51

Closed TheBrokenRail closed 2 years ago

TheBrokenRail commented 2 years ago

https://github.com/AppImageCrafters/AppRun/blob/2496b3929090c58d05ecd2a50d34fbc8262eb64c/src/hooks/main_hook.c#L16

This line of code that runs right before main restores the working directory of the parent process. Normally, this works fine. The calling process changes it's working directory so relative interpreters work, then it starts the program, then the hooks restore the current directory right before main.

However, there is an issue, if the child process changes its working directory for whatever reason inside of a __attribute__((constructor)) function, that working directory is overwritten.

Suggested fix: Hook chdir and set a variable to true when chdir is called, only restore the original working directory if that variable is false.

azubieta commented 2 years ago

Good catch, I'm not a big fan of having global variables that may affect the users applications (we already have a lot of those). Would not be better to do the chdir restoration in the libapprun_hooks constructor ? As it's preloaded it will be executed first right ?