Failed in using LD_PRELOAD to hook mmap system call in qemu(through libvirt)

Dear sir: I want to hook mmap system call in qemu, and I use libvirt to passthrough the environment argument like this:<qemu:commandline> <qemu:env name='LD_PRELOAD' value='/glibcHookMMAP.so'/> </qemu:commandline> But it failed. I can hardly find out what is the matter! The log in libvirt like this:ERROR: ld.so: object '/glibcHookMMAP.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. Firstly, I think it's the problem of authority. But the file glibcHookMMAP.so has been done with command `chmod 777`. My environment is as follows: Ubuntu 18.04.2 Linux 5.4.0-92 libvirt 4.0.0 qemu 2.11.1 Look forward to your feedbacks. Sincerely yours

On Thu, Jan 06, 2022 at 07:44:25PM +0800, Xiong。 wrote:
Dear sir: I want to hook mmap system call in qemu, and I use libvirt to passthrough the environment argument like this: <qemu:commandline> <qemu:env name='LD_PRELOAD' value='/glibcHookMMAP.so'/> </qemu:commandline> But it failed. I can hardly find out what is the matter! The log in libvirt like this:ERROR: ld.so: object '/glibcHookMMAP.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. Firstly, I think it's the problem of authority. But the file glibcHookMMAP.so has been done with command `chmod 777`. My environment is as follows: Ubuntu 18.04.2 Linux 5.4.0-92 libvirt 4.0.0 qemu 2.11.1
Aside from normal file permissions, the other likely problem on Ubuntu will be AppArmor policy. It likely won't allow QEMU to load files from the / directory - if you put your .so in /usr/local/lib it might work. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Thu, Jan 06, 2022 at 07:44:25PM +0800, Xiong。 wrote: > Dear sir: > I want to hook mmap system call in qemu, and I use > libvirt to passthrough the environment argument like this: > <qemu:commandline> > <qemu:env name='LD_PRELOAD' value='/glibcHookMMAP.so'/> > </qemu:commandline> > But it failed. I can hardly find out what is the matter! > The log in libvirt like this:ERROR: ld.so: object > '/glibcHookMMAP.so' from LD_PRELOAD cannot be preloaded > (cannot open shared object file): ignored. Firstly, > I think it's the problem of authority. But the file > glibcHookMMAP.so has been done with command `chmod 777`. > My environment is as follows: Ubuntu 18.04.2 Linux > 5.4.0-92 libvirt 4.0.0 qemu 2.11.1 On Thu, Jan 06, 2022 at 09:47:25PM +0800, Daniel P. Berrangé。 wrote: > Aside from normal file permissions, the other likely problem on Ubuntu > will be AppArmor policy. It likely won't allow QEMU to load files from > the / directory - if you put your .so in /usr/local/lib it might > work. I have a try, but it does not work and makes the same warning: ld.so: object '/usr/local/lib/glibcHookMMAP.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. However, I use qemu command directly and it works. Command is like this: sudo LD_PRELOAD=/usr/local/lib/glibcHookMMAP.so qemu-system-x86_64 -enable-kvm ...(other args). After that, I get print information with my hook program. And I think the problem is in passing the environment args in libvirt.
participants (2)
-
Daniel P. Berrangé
-
Xiong。