Skip to contentSkip to conversation

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

Qemu-devel Yury Gribov 4 participants 11 messages Mar 28, 2014 – Jun 17, 2016

lore
Share & tools
lore
#0 lore raw

Public bug reported:

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.

** Affects: qemu
Importance: Undecided
Status: New

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#1 lore raw

This tiny patch seems to work.

** Patch added: "qemu.patch"
https://bugs.launchpad.net/qemu/+bug/1299190/+attachment/4055887/+files/qemu.patch

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#2 lore raw
In reply to Yury Gribov

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.

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#3 lore raw
In reply to Yury Gribov

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

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#4 lore raw
In reply to Yury Gribov

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.)

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#5 lore raw
In reply to Yury Gribov

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

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#6 lore raw
In reply to Yury Gribov

Yes, it works. Here is updated patch.

** Patch added: "qemu.patch"
https://bugs.launchpad.net/qemu/+bug/1299190/+attachment/4062345/+files/qemu.patch

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#7 lore raw
In reply to Yury Gribov

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.

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#8 lore raw
In reply to Yury Gribov

Ok, fixed.

** Patch added: "qemu.patch"
https://bugs.launchpad.net/qemu/+bug/1299190/+attachment/4062748/+files/qemu.patch

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
Reviewed-by
#9 lore raw
In reply to Yury Gribov

Thanks. That version

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  New

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions
#10 lore raw
In reply to Yury Gribov

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

** Changed in: qemu
Status: New => Fix Released

Signature · 24 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1299190

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

Status in QEMU:
  Fix Released

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1299190/+subscriptions