From: Peter Maydell <peter.maydell@linaro.org>
To: Andreas Schwab <schwab@suse.de>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] linux-user: identify running binary in /proc/$$/exe
Date: Thu, 18 Apr 2013 15:56:10 +0100 [thread overview]
Message-ID: <CAFEAcA9-q4zghef=N96cq6c2RitAE5TJR7ikL9VXBv84xmUOXQ@mail.gmail.com> (raw)
In-Reply-To: <mvmy5dtq2fj.fsf@hawking.suse.de>
On 11 March 2013 17:19, Andreas Schwab <schwab@suse.de> wrote:
> 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.
Sorry I didn't get round to reviewing this earlier; I think
it slipped through the cracks :-(
> 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));
You could add braces on the 'then' part of this if() and get rid
of the stray hardcoded tab in the existing code. (not a requirement
but since we're in the area anyway...)
> + 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);
This seems to be a fair chunk of code in common with the readlink
case above -- can we abstract it out? (ideally to a function
somewhere in the same area of this file as the code that handles
intercepting /proc/ calls for open().)
It would be consistent to support /proc/$$/ for all the open()
intercepts too.
> + }
> + else
> + ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4));
> + }
> unlock_user(p2, arg3, ret);
> unlock_user(p, arg2, 0);
> }
> --
> 1.8.1.5
thanks
-- PMM
next prev parent reply other threads:[~2013-04-18 14:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-11 17:19 [Qemu-devel] [PATCH] linux-user: identify running binary in /proc/$$/exe Andreas Schwab
2013-04-18 14:56 ` Peter Maydell [this message]
2013-05-08 10:31 ` [Qemu-devel] [PATCH] linux-user: handle /proc/$$ like /proc/self Andreas Schwab
2013-06-27 17:09 ` Peter Maydell
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='CAFEAcA9-q4zghef=N96cq6c2RitAE5TJR7ikL9VXBv84xmUOXQ@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=schwab@suse.de \
/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).