Access to /proc/self/exe in linux-user mode

Bug #1299190 reported by Yury Gribov
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Fix Released
Undecided
Unassigned

Bug Description

This is based on a recent bug in GCC Bugzilla: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60681

It looks like libbacktrace (GCC runtime library used for obtaining stack traces) uses /proc/self/exe for error reporting. Currently this is mapped to qemu-arm which effectively disables libbacktrace on linux-user.

It seems that QEMU already supports /proc/self/{maps,stat,auxv} so addition of /proc/self/exe may be trivial.

Revision history for this message
Maxim Ostapenko (m-ostapenko) wrote :

This tiny patch seems to work.

Revision history for this message
Yury Gribov (tetra2005) wrote :

I think the problem is not in libbacktrace per se but rather libsanitizer initializing libbacktrace with contents of /proc/self/exe. Patch is still relevant though.

Revision history for this message
Riku Voipio (riku-voipio) wrote :

Looks good, I'll get this to linux-user que once QEMU 2.0 is released.

Revision history for this message
Peter Maydell (pmaydell) wrote :

That patch will copy the whole of the target executable into a temporary file without changing any of it -- the fake_open mechanism is really intended for cases where we need to return modified results. Wouldn't it be easier to just have something in do_open() that said:
    if (is_proc_myself(pathname, "exe")) {
        return get_errno(open(exec_path), flags, mode);
    }

That will then give the right behaviour for read-only executables and other error-related corner cases.

(See also the logic in the readlink/readlinkat handling which already specialcases /proc/self/exe using exec_path.)

Revision history for this message
Peter Maydell (pmaydell) wrote :

(I got the bracket placement wrong there so as you can tell the code is untested :-))

Revision history for this message
Maxim Ostapenko (m-ostapenko) wrote :

Yes, it works. Here is updated patch.

Revision history for this message
Peter Maydell (pmaydell) wrote :

Some nits:
 The "(CPUArchState *)" cast isn't necessary
 We should use exec_path, not ts->bprm->argv[0] (the guest argv[0] isn't necessarily the executable path)
 We don't want to call path() here -- exec_path is a host path, and only guest filename paths need to go through path().

Looking a little more closely at the logic in main.c I wonder if we actually want:

   if (is_proc_myself(pathname, "exe")) {
        execfd = qemu_getauxval(AT_EXECFD);
        if (execfd) {
             return execfd;
        }
        return get_errno(open(exec_path, flags, mode));
    }

Also if you'd like us to apply your patches we'll need at least a "Signed-off-by: " line from you.

Revision history for this message
Maxim Ostapenko (m-ostapenko) wrote :

Ok, fixed.

Revision history for this message
Peter Maydell (pmaydell) wrote :

Thanks. That version
Reviewed-by: Peter Maydell <email address hidden>

Revision history for this message
Maxim Ostapenko (m-ostapenko) wrote :

Hi,

Is this patch deployed in new version of QEMU?

Thanks,
Maxim

Revision history for this message
Peter Maydell (pmaydell) wrote :

This bug was fixed by commit aa07f5ecf9828 in 2014 and has been released in QEMU.

Changed in qemu:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.