[Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
With the current fake /proc/self/stat implementation `ps` is segfaulting because it expects to read PID and argv[0] as first and second field respectively, with the latter being enclosed between backets. Reproducing is as easy as running: `ps` inside qemu-user chroot with /proc mounted.

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
ts-bprm-argv seems NULL here. Isn't it supposed to be set? -- Fabio Erculiani

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Alexander Graf
On 03.01.2012, at 17:07, Fabio Erculiani wrote: ts-bprm-argv seems NULL here. Isn't it supposed to be set? Good question. Maybe we need some other way to fetch argv0 then? Alex

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
On Tue, Jan 3, 2012 at 6:41 PM, Alexander Graf ag...@suse.de wrote: On 03.01.2012, at 17:07, Fabio Erculiani wrote: ts-bprm-argv seems NULL here. Isn't it supposed to be set? Good question. Maybe we need some other way to fetch argv0 then? or we could leave just an empty string for now -

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
Or just using linux_binprm-filename with basename() -- Fabio Erculiani

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Alexander Graf
On 03.01.2012, at 19:08, Fabio Erculiani wrote: Or just using linux_binprm-filename with basename() No, that'd be wrong since argv[0] can be different from the actual file name. Also it can be the full path or not depending on what the initiator defined. Alex

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Alexander Graf
On 03.01.2012, at 19:04, Fabio Erculiani wrote: On Tue, Jan 3, 2012 at 6:41 PM, Alexander Graf ag...@suse.de wrote: On 03.01.2012, at 17:07, Fabio Erculiani wrote: ts-bprm-argv seems NULL here. Isn't it supposed to be set? Good question. Maybe we need some other way to fetch argv0

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
How about setting ts-bprm-argv = target_argv; ? I'm not a qemu codebase expert, but if it's always NULL (why is it NULL?) or can be NULL... It looks like can be done easily from main.c... without making a variable global. -- Fabio Erculiani

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
Mumble, that is what happens already... Let me see why I get NULL here... -- Fabio Erculiani

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Alexander Graf
On 03.01.2012, at 19:46, Fabio Erculiani wrote: How about setting ts-bprm-argv = target_argv; ? I'm not a qemu codebase expert, but if it's always NULL (why is it NULL?) or can be NULL... It should already be set it loader_exec. I don't know why it's NULL there for you. I suppose some debug

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
Yeah, debugging. Moreover we have this scenario: $ /bin/cat /proc/self/stat 32297 (cat) .. I guess we should use basename() anyway...? -- Fabio Erculiani

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Alexander Graf
On 03.01.2012, at 19:54, Fabio Erculiani wrote: Yeah, debugging. Moreover we have this scenario: $ /bin/cat /proc/self/stat 32297 (cat) .. I guess we should use basename() anyway...? argv[0] can be an arbitrary value passed in through execve. In qemu's linux-user emulation you

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
Ok, I've found the reason, i guess it's a bug. target_argv pointer is placed in bprm-argv; But then target_argv is freed and nullified. loader_exec should just allocate a new char** and copy target_argv. I tried that and it worked. The problem is, where do I free() it? Am i supposed to do it or

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Alexander Graf
On 03.01.2012, at 20:11, Fabio Erculiani wrote: Ok, I've found the reason, i guess it's a bug. target_argv pointer is placed in bprm-argv; But then target_argv is freed and nullified. loader_exec should just allocate a new char** and copy target_argv. I tried that and it worked. The

Re: [Qemu-devel] [PATCH] linux-user: improve fake /proc/self/stat making `ps` not segfault.

2012-01-03 Thread Fabio Erculiani
Done, it all works now ;-) ! -- Fabio Erculiani