qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [6485] linux-user: identify running binary in /proc/self/exe
@ 2009-01-30 20:09 Aurelien Jarno
  2009-02-02  7:59 ` Laurent Desnogues
  0 siblings, 1 reply; 3+ messages in thread
From: Aurelien Jarno @ 2009-01-30 20:09 UTC (permalink / raw)
  To: qemu-devel

Revision: 6485
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6485
Author:   aurel32
Date:     2009-01-30 20:09:01 +0000 (Fri, 30 Jan 2009)

Log Message:
-----------
linux-user: identify running binary in /proc/self/exe

Some applications like to test /proc/self/exe to find
out who they are. Fake the result of readlink() for
them. Use realpath() to return full path to binary
(which the links /proc/self/exe are)

Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Modified Paths:
--------------
    trunk/linux-user/main.c
    trunk/linux-user/qemu.h
    trunk/linux-user/syscall.c

Modified: trunk/linux-user/main.c
===================================================================
--- trunk/linux-user/main.c	2009-01-30 19:59:17 UTC (rev 6484)
+++ trunk/linux-user/main.c	2009-01-30 20:09:01 UTC (rev 6485)
@@ -37,6 +37,8 @@
 
 #define DEBUG_LOGFILE "/tmp/qemu.log"
 
+char *exec_path;
+
 static const char *interp_prefix = CONFIG_QEMU_PREFIX;
 const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
 
@@ -2341,6 +2343,7 @@
     if (optind >= argc)
         usage();
     filename = argv[optind];
+    exec_path = argv[optind];
 
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));

Modified: trunk/linux-user/qemu.h
===================================================================
--- trunk/linux-user/qemu.h	2009-01-30 19:59:17 UTC (rev 6484)
+++ trunk/linux-user/qemu.h	2009-01-30 20:09:01 UTC (rev 6485)
@@ -120,6 +120,7 @@
     uint8_t stack[0];
 } __attribute__((aligned(16))) TaskState;
 
+extern char *exec_path;
 void init_task_state(TaskState *ts);
 extern const char *qemu_uname_release;
 

Modified: trunk/linux-user/syscall.c
===================================================================
--- trunk/linux-user/syscall.c	2009-01-30 19:59:17 UTC (rev 6484)
+++ trunk/linux-user/syscall.c	2009-01-30 20:09:01 UTC (rev 6485)
@@ -4410,13 +4410,22 @@
 #endif
     case TARGET_NR_readlink:
         {
-            void *p2;
+            void *p2, *temp;
             p = lock_user_string(arg1);
             p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
             if (!p || !p2)
                 ret = -TARGET_EFAULT;
-            else
-                ret = get_errno(readlink(path(p), p2, arg3));
+            else {
+                if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) {
+                    char real[PATH_MAX];
+                    temp = realpath(exec_path,real);
+                    ret = (temp==NULL) ? get_errno(-1) : strlen(real) ;
+                    snprintf((char *)p2, arg3, "%s", real);
+                    }
+                else
+                    ret = get_errno(readlink(path(p), p2, arg3));
+                break;
+            }
             unlock_user(p2, arg2, ret);
             unlock_user(p, arg1, 0);
         }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [6485] linux-user: identify running binary in /proc/self/exe
  2009-01-30 20:09 [Qemu-devel] [6485] linux-user: identify running binary in /proc/self/exe Aurelien Jarno
@ 2009-02-02  7:59 ` Laurent Desnogues
  2009-02-02  9:15   ` Riku Voipio
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Desnogues @ 2009-02-02  7:59 UTC (permalink / raw)
  To: qemu-devel

On Fri, Jan 30, 2009 at 9:09 PM, Aurelien Jarno <aurelien@aurel32.net> wrote:
> Revision: 6485
>          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6485
> Author:   aurel32
> Date:     2009-01-30 20:09:01 +0000 (Fri, 30 Jan 2009)
>
> Log Message:
> -----------
> linux-user: identify running binary in /proc/self/exe
>
> Some applications like to test /proc/self/exe to find
> out who they are. Fake the result of readlink() for
> them. Use realpath() to return full path to binary
> (which the links /proc/self/exe are)
>
> Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
>
> Modified Paths:
> --------------
>    trunk/linux-user/main.c
>    trunk/linux-user/qemu.h
>    trunk/linux-user/syscall.c
>
[...]
> Modified: trunk/linux-user/syscall.c
> ===================================================================
> --- trunk/linux-user/syscall.c  2009-01-30 19:59:17 UTC (rev 6484)
> +++ trunk/linux-user/syscall.c  2009-01-30 20:09:01 UTC (rev 6485)
> @@ -4410,13 +4410,22 @@
>  #endif
>     case TARGET_NR_readlink:
>         {
> -            void *p2;
> +            void *p2, *temp;
>             p = lock_user_string(arg1);
>             p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
>             if (!p || !p2)
>                 ret = -TARGET_EFAULT;
> -            else
> -                ret = get_errno(readlink(path(p), p2, arg3));
> +            else {
> +                if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) {
> +                    char real[PATH_MAX];
> +                    temp = realpath(exec_path,real);
> +                    ret = (temp==NULL) ? get_errno(-1) : strlen(real) ;
> +                    snprintf((char *)p2, arg3, "%s", real);
> +                    }
> +                else
> +                    ret = get_errno(readlink(path(p), p2, arg3));
> +                break;

Do we really want to skip unlock_user?

> +            }
>             unlock_user(p2, arg2, ret);
>             unlock_user(p, arg1, 0);
>         }


Laurent

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [6485] linux-user: identify running binary in /proc/self/exe
  2009-02-02  7:59 ` Laurent Desnogues
@ 2009-02-02  9:15   ` Riku Voipio
  0 siblings, 0 replies; 3+ messages in thread
From: Riku Voipio @ 2009-02-02  9:15 UTC (permalink / raw)
  To: qemu-devel

On Mon, Feb 02, 2009 at 08:59:14AM +0100, Laurent Desnogues wrote:
> Do we really want to skip unlock_user?

indeed. I wonder how it still works when testing. will send a fix ASAP.

-- 
"rm -rf" only sounds scary if you don't have backups

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-02-02  9:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-30 20:09 [Qemu-devel] [6485] linux-user: identify running binary in /proc/self/exe Aurelien Jarno
2009-02-02  7:59 ` Laurent Desnogues
2009-02-02  9:15   ` Riku Voipio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).