From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LTtiA-0000yJ-AK for qemu-devel@nongnu.org; Mon, 02 Feb 2009 02:59:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LTti8-0000y7-PD for qemu-devel@nongnu.org; Mon, 02 Feb 2009 02:59:16 -0500 Received: from [199.232.76.173] (port=52309 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LTti8-0000y4-Ih for qemu-devel@nongnu.org; Mon, 02 Feb 2009 02:59:16 -0500 Received: from fg-out-1718.google.com ([72.14.220.154]:56138) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LTti7-0004ga-TT for qemu-devel@nongnu.org; Mon, 02 Feb 2009 02:59:16 -0500 Received: by fg-out-1718.google.com with SMTP id e21so533529fga.8 for ; Sun, 01 Feb 2009 23:59:14 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 2 Feb 2009 08:59:14 +0100 Message-ID: <761ea48b0902012359u2f73e99ajb6a1a4ea56fc0e6b@mail.gmail.com> Subject: Re: [Qemu-devel] [6485] linux-user: identify running binary in /proc/self/exe From: Laurent Desnogues Content-Type: text/plain; charset=ISO-8859-1 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 On Fri, Jan 30, 2009 at 9:09 PM, Aurelien Jarno 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 > Signed-off-by: Aurelien Jarno > > 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