From patchwork Mon Mar 11 17:19:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 226675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F31782C02EA for ; Tue, 12 Mar 2013 06:54:19 +1100 (EST) Received: from localhost ([::1]:55279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF8na-0008Mf-31 for incoming@patchwork.ozlabs.org; Mon, 11 Mar 2013 15:54:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF6Ok-0005ox-KR for qemu-devel@nongnu.org; Mon, 11 Mar 2013 13:20:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UF6Oh-0008Fn-1d for qemu-devel@nongnu.org; Mon, 11 Mar 2013 13:20:30 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33614 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UF6Og-0007ce-PA for qemu-devel@nongnu.org; Mon, 11 Mar 2013 13:20:26 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DFAE3A51F2 for ; Mon, 11 Mar 2013 18:19:44 +0100 (CET) From: Andreas Schwab To: qemu-devel@nongnu.org X-Yow: The PILLSBURY DOUGHBOY is CRYING for an END to BURT REYNOLDS movies!! Date: Mon, 11 Mar 2013 18:19:44 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 X-Mailman-Approved-At: Mon, 11 Mar 2013 15:53:59 -0400 Subject: [Qemu-devel] [PATCH] linux-user: identify running binary in /proc/$$/exe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Some applications like to test /proc/$$/exe (where $$ is the own pid) to find out who they are. Handle it like /proc/self/exe. Also, do the same handling in readlinkat. Signed-off-by: Andreas Schwab --- linux-user/syscall.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 19630ea..3e5a6ae 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6413,7 +6413,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (!p || !p2) ret = -TARGET_EFAULT; else { - if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) { + char myself[PATH_MAX]; + snprintf(myself, sizeof(myself), "/proc/%d/exe", getpid()); + if (strncmp((const char *)p, "/proc/self/exe", 14) == 0 || + strcmp((const char *)p, myself) == 0) { char real[PATH_MAX]; temp = realpath(exec_path,real); ret = (temp==NULL) ? get_errno(-1) : strlen(real) ; @@ -6429,13 +6432,24 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) case TARGET_NR_readlinkat: { - void *p2; + void *p2, *temp; p = lock_user_string(arg2); p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0); if (!p || !p2) ret = -TARGET_EFAULT; - else - ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4)); + else { + char myself[PATH_MAX]; + snprintf(myself, sizeof(myself), "/proc/%d/exe", getpid()); + if (strncmp((const char *)p, "/proc/self/exe", 14) == 0 || + strcmp((const char *)p, myself) == 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(sys_readlinkat(arg1, path(p), p2, arg4)); + } unlock_user(p2, arg3, ret); unlock_user(p, arg2, 0); }