From: Riku Voipio <riku.voipio@iki.fi>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] linux-user: identify running binary in /proc/self/exe
Date: Tue, 20 Jan 2009 18:01:04 +0200 [thread overview]
Message-ID: <20090120160104.GA4358@kos.to> (raw)
In-Reply-To: <200901191557.27453.paul@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 565 bytes --]
On Mon, Jan 19, 2009 at 03:57:26PM +0000, Paul Brook wrote:
> On Monday 19 January 2009, Riku Voipio wrote:
> > Some applications like to test /proc/self/exe to find
> > out who they are. Fake the result of readlink() for
> > them.
>
> > + exec_path = argv[optind];
> Won't this give the wrong answer when the binary is invoked using a relative
> path or a symlink? On my system /proc/self/exe is always an absolute path to
> an actual file.
You are right. Fixed version attached.
--
"rm -rf" only sounds scary if you don't have backups
[-- Attachment #2: 0002-linux-user-identify-running-binary-in-proc-self-ex.patch --]
[-- Type: text/plain, Size: 2496 bytes --]
>From f3be7d8337ae3def8f2d3d4e089016fcd9686467 Mon Sep 17 00:00:00 2001
From: Riku Voipio <riku.voipio@iki.fi>
Date: Tue, 20 Jan 2009 17:46:18 +0200
Subject: [PATCH] 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>
---
linux-user/main.c | 3 +++
linux-user/qemu.h | 1 +
linux-user/syscall.c | 12 ++++++++++--
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index 59da5fd..b45dcfe 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -34,6 +34,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;
@@ -2312,6 +2314,7 @@ int main(int argc, char **argv, char **envp)
if (optind >= argc)
usage();
filename = argv[optind];
+ exec_path = argv[optind];
/* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs));
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 9fddd05..4137567 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -120,6 +120,7 @@ typedef struct TaskState {
uint8_t stack[0];
} __attribute__((aligned(16))) TaskState;
+extern char *exec_path;
void init_task_state(TaskState *ts);
extern const char *qemu_uname_release;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5d787bb..21ec17b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4375,8 +4375,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 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];
+ ret = get_errno(realpath(exec_path,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);
}
--
1.5.6.3
next prev parent reply other threads:[~2009-01-20 16:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-19 15:30 [Qemu-devel] [PATCH] linux-user: identify running binary in /proc/self/exe Riku Voipio
2009-01-19 15:57 ` Paul Brook
2009-01-20 16:01 ` Riku Voipio [this message]
2009-01-26 19:07 ` Riku Voipio
2009-01-30 20:10 ` Aurelien Jarno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090120160104.GA4358@kos.to \
--to=riku.voipio@iki.fi \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).