From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LPJ2O-0000vU-CB for qemu-devel@nongnu.org; Tue, 20 Jan 2009 11:01:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LPJ2N-0000ut-Jp for qemu-devel@nongnu.org; Tue, 20 Jan 2009 11:01:11 -0500 Received: from [199.232.76.173] (port=53731 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LPJ2N-0000uo-AP for qemu-devel@nongnu.org; Tue, 20 Jan 2009 11:01:11 -0500 Received: from [84.20.150.76] (port=34539 helo=narury.org) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LPJ2M-0002oY-Ef for qemu-devel@nongnu.org; Tue, 20 Jan 2009 11:01:10 -0500 Received: from kos.to (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by narury.org (Postfix) with ESMTP id 291873274003 for ; Tue, 20 Jan 2009 18:01:05 +0200 (EET) Date: Tue, 20 Jan 2009 18:01:04 +0200 From: Riku Voipio Subject: Re: [Qemu-devel] [PATCH] linux-user: identify running binary in /proc/self/exe Message-ID: <20090120160104.GA4358@kos.to> References: <20090119153008.GA20882@kos.to> <200901191557.27453.paul@codesourcery.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" Content-Disposition: inline In-Reply-To: <200901191557.27453.paul@codesourcery.com> Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > > + =C2=A0 =C2=A0exec_path =3D argv[optind]; > Won't this give the wrong answer when the binary is invoked using a rel= ative=20 > path or a symlink? On my system /proc/self/exe is always an absolute pa= th to=20 > an actual file. You are right. Fixed version attached. --=20 "rm -rf" only sounds scary if you don't have backups --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-linux-user-identify-running-binary-in-proc-self-ex.patch" >>From f3be7d8337ae3def8f2d3d4e089016fcd9686467 Mon Sep 17 00:00:00 2001 From: Riku Voipio 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 --- 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 --IS0zKkzwUGydFO0o--