2

I am using LD_PRELOAD, and I am seeing a difference between bash and dash when using the system() command.

Let's consider this simple C program:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char *argv[]) { 
    system("echo $LD_PRELOAD > /tmp/blah.txt");
    return 0;
}

I would start my test program like this:

LD_PRELOAD=preload.so ./test

Both in bash and dash, I got:

~$ cat /tmp/blah.txt 
 preload.so

So far so good except that the LD_PRELOAD is not applied to the command given to system when dash is the shell. I mean

  • if /bin/sh points to /bin/bash, LD_PRELOAD is applied to the command given to system()
  • if /bin/sh points to /bin/dash, LD_PRELOAD is NOT applied to the command given to system().

My preload.so library override open(). It is executed with the test program when bash is used (/bin/sh=/bin/bash), but not when dash is used (/bin/sh=/bin/dash).

I am guessing that bash and dash might treat the environment variables passed to execve differently, but I can not find a way with dash to have LD_PRELOAD applied to the command given to system... Unfortunately I have to use dash, and using bash is not an option.

Olivier
  • 19
  • 2
  • using your C program is just confusing things. You should be able to do this on bash or dash command line. `system()` simply invokes the shell, the effects being the same as command line. Post how you try your command line on `dash`, what you expect, and what you get. – Mark Galeck Aug 15 '16 at 20:44
  • This program is just a minimal example. I have to use LD_PRELOAD to transform pathname (existent code which I could not change, at least for now). The issue is that LD_PRELOAD do not propagate to the program called by execve (that's what system is calling) when DASH is used. No issue at all with BASH. By 'propagate' I mean that the preload library is NOT applied to the program called by execve (again, just when DASH is used). Everything is already explained clearly in my original email. – Olivier Aug 16 '16 at 22:09

1 Answers1

0

In my case, this issue was only happening when LibreOffice launched it. Turned out AppArmor was interfering somehow. Consider disabling AppArmor and rebooting to see if that's your issue (and if it is, maybe debug further - I just left AppArmor disabled)

Luke-Jr
  • 137
  • 1
  • 8