All of lore.kernel.org
 help / color / mirror / Atom feed
* ptrace PTRACE_PEEKUSER behavior
@ 2008-05-05 11:01 Anoop
  2008-05-05 11:55 ` Andi Kleen
  2008-05-05 19:04 ` Roland McGrath
  0 siblings, 2 replies; 6+ messages in thread
From: Anoop @ 2008-05-05 11:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: roland


The call ptrace(PTRACE_PEEKUSER, <pid>, ...) does not work as described in the
man page.

Specifically, the man page states:
PTRACE_PEEKUSER
	Reads a word at offset addr in the child's USER area, which
	holds the registers and other information about the process (see
	<linux/user.h> and <sys/user.h>). The word is returned as the
	result of the ptrace() call. Typically the offset must be word-
	aligned, though this might vary by architecture. (data is
	ignored.)

Using the PTRACE_PEEKUSER action, the "regs" component can be read, but the
values past regs are not obtained. Even the reg values are not  
retrieved from a
'user' structure, but from the 'task_struct' of the process.

linux-2.6.26-rc1/include/asm-x86/user_32.h defines struct user like this.

/* When the kernel dumps core, it starts by dumping the user struct -
this will be used by gdb to figure out where the data and stack segments
are within the file, and what virtual addresses to use. */
struct user{
	/* We start with the registers, to mimic the way that "memory" is returned
	from the ptrace(3,...) function. */
	struct user_regs_struct regs; /* Where the registers are actually stored
	*/
	/* ptrace does not yet supply these. Someday.... */ <===================
	int u_fpvalid; /* True if math co-processor being used. */
	/* for this mess. Not yet used. */
	struct user_i387_struct i387; /* Math Co-processor registers. */
	/* The rest of this junk is to help gdb figure out what goes where */
	unsigned long int u_tsize; /* Text segment size (pages). */
	unsigned long int u_dsize; /* Data segment size (pages). */
	unsigned long int u_ssize; /* Stack segment size (pages). */
	unsigned long start_code; /* Starting virtual address of text. */
	unsigned long start_stack; /* Starting virtual address of stack area.
	This is actually the bottom of the stack, the top of the stack is always
	found in the	esp register. */
	long int signal; /* Signal that caused the core dump. */
	int reserved; /* No longer used */
	struct user_pt_regs * u_ar0; /* Used by gdb to help find the values for */
	/* the registers. */
	struct user_i387_struct* u_fpstate; /* Math Co-processor pointer. */
	unsigned long magic; /* To uniquely identify a core file */
	char u_comm[32]; /* User command that was responsible */
	int u_debugreg[8];
};

Noting the comment after 'struct user_regs_struct regs', is there any specific
reason why ptrace doesn't provide the rest of the members of this  
structure? In
that case shouldn't the man pages be corrected?

- Anoop



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ptrace PTRACE_PEEKUSER behavior
  2008-05-05 11:01 ptrace PTRACE_PEEKUSER behavior Anoop
@ 2008-05-05 11:55 ` Andi Kleen
  2008-05-05 12:45   ` Michael Kerrisk
  2008-05-05 19:04 ` Roland McGrath
  1 sibling, 1 reply; 6+ messages in thread
From: Andi Kleen @ 2008-05-05 11:55 UTC (permalink / raw)
  To: Anoop; +Cc: linux-kernel, roland, mtk.manpages

Anoop <acv@linux.vnet.ibm.com> writes:

[intentional fullquote]

> The call ptrace(PTRACE_PEEKUSER, <pid>, ...) does not work as described in the
> man page.
>
> Specifically, the man page states:
> PTRACE_PEEKUSER
> 	Reads a word at offset addr in the child's USER area, which
> 	holds the registers and other information about the process (see
> 	<linux/user.h> and <sys/user.h>). The word is returned as the
> 	result of the ptrace() call. Typically the offset must be word-
> 	aligned, though this might vary by architecture. (data is
> 	ignored.)
>
> Using the PTRACE_PEEKUSER action, the "regs" component can be read, but the
> values past regs are not obtained. Even the reg values are not  
> retrieved from a
> 'user' structure, but from the 'task_struct' of the process.
>
> linux-2.6.26-rc1/include/asm-x86/user_32.h defines struct user like this.

[..]
>
> /* When the kernel dumps core, it starts by dumping the user struct -

[..]
> 	*/
> 	/* ptrace does not yet supply these. Someday.... */ <===================
> 	/* for this mess. Not yet used. */
> 	struct user_i387_struct i387; /* Math Co-processor registers. */
> 	/* The rest of this junk is to help gdb figure out what goes where */
> 	unsigned long int u_tsize; /* Text segment size (pages). */
> 	unsigned long int u_dsize; /* Data segment size (pages). */
> 	unsigned long int u_ssize; /* Stack segment size (pages). */
> 	unsigned long start_code; /* Starting virtual address of text. */
> 	unsigned long start_stack; /* Starting virtual address of stack area.
> 	This is actually the bottom of the stack, the top of the stack is always
> 	found in the	esp register. */
> 	long int signal; /* Signal that caused the core dump. */
> 	int reserved; /* No longer used */
> 	struct user_pt_regs * u_ar0; /* Used by gdb to help find the values for */
> 	/* the registers. */
> 	struct user_i387_struct* u_fpstate; /* Math Co-processor pointer. */
> 	unsigned long magic; /* To uniquely identify a core file */
> 	char u_comm[32]; /* User command that was responsible */
> 	int u_debugreg[8];
> };
>
> Noting the comment after 'struct user_regs_struct regs', is there any specific
> reason why ptrace doesn't provide the rest of the members of this  
> structure?

Since Linux internally has no "struct user" all of this has to be
implemented by special case code (in particularly a big switch statement)
While that could be done if nobody uses it (and that seems
to be the case) it would be just a waste of code.

> In
> that case shouldn't the man pages be corrected?

Probably. cc mtk.

-Andi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ptrace PTRACE_PEEKUSER behavior
  2008-05-05 11:55 ` Andi Kleen
@ 2008-05-05 12:45   ` Michael Kerrisk
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Kerrisk @ 2008-05-05 12:45 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Anoop, linux-kernel, roland, mtk.manpages

On 5/5/08, Andi Kleen <andi@firstfloor.org> wrote:
> Anoop <acv@linux.vnet.ibm.com> writes:
>
>  [intentional fullquote]
>
>
>  > The call ptrace(PTRACE_PEEKUSER, <pid>, ...) does not work as described in the
>  > man page.
>  >
>  > Specifically, the man page states:
>  > PTRACE_PEEKUSER
>  >       Reads a word at offset addr in the child's USER area, which
>  >       holds the registers and other information about the process (see
>  >       <linux/user.h> and <sys/user.h>). The word is returned as the
>  >       result of the ptrace() call. Typically the offset must be word-
>  >       aligned, though this might vary by architecture. (data is
>  >       ignored.)
>  >
>  > Using the PTRACE_PEEKUSER action, the "regs" component can be read, but the
>  > values past regs are not obtained. Even the reg values are not
>  > retrieved from a
>  > 'user' structure, but from the 'task_struct' of the process.
>  >
>  > linux-2.6.26-rc1/include/asm-x86/user_32.h defines struct user like this.
>
>  [..]
>  >
>  > /* When the kernel dumps core, it starts by dumping the user struct -
>
>
> [..]
>
> >       */
>  >       /* ptrace does not yet supply these. Someday.... */ <===================
>
> >       /* for this mess. Not yet used. */
>  >       struct user_i387_struct i387; /* Math Co-processor registers. */
>  >       /* The rest of this junk is to help gdb figure out what goes where */
>  >       unsigned long int u_tsize; /* Text segment size (pages). */
>  >       unsigned long int u_dsize; /* Data segment size (pages). */
>  >       unsigned long int u_ssize; /* Stack segment size (pages). */
>  >       unsigned long start_code; /* Starting virtual address of text. */
>  >       unsigned long start_stack; /* Starting virtual address of stack area.
>  >       This is actually the bottom of the stack, the top of the stack is always
>  >       found in the    esp register. */
>  >       long int signal; /* Signal that caused the core dump. */
>  >       int reserved; /* No longer used */
>  >       struct user_pt_regs * u_ar0; /* Used by gdb to help find the values for */
>  >       /* the registers. */
>  >       struct user_i387_struct* u_fpstate; /* Math Co-processor pointer. */
>  >       unsigned long magic; /* To uniquely identify a core file */
>  >       char u_comm[32]; /* User command that was responsible */
>  >       int u_debugreg[8];
>  > };
>  >
>  > Noting the comment after 'struct user_regs_struct regs', is there any specific
>  > reason why ptrace doesn't provide the rest of the members of this
>  > structure?
>
>
> Since Linux internally has no "struct user" all of this has to be
>  implemented by special case code (in particularly a big switch statement)
>  While that could be done if nobody uses it (and that seems
>  to be the case) it would be just a waste of code.
>
>
>  > In
>  > that case shouldn't the man pages be corrected?
>
>
> Probably. cc mtk.

Anoop would you be able to write a patch for the the man page?  (Yoou
can get the latest page in a tarball at the location below.

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ptrace PTRACE_PEEKUSER behavior
  2008-05-05 11:01 ptrace PTRACE_PEEKUSER behavior Anoop
  2008-05-05 11:55 ` Andi Kleen
@ 2008-05-05 19:04 ` Roland McGrath
  1 sibling, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2008-05-05 19:04 UTC (permalink / raw)
  To: Anoop; +Cc: linux-kernel

'struct user' is really a virtual structure layout, and never exists
anywhere as an actual struct.  It's really just defining the argument
values that can be used in PEEKUSR/POKEUSR calls.  Its details are
completely machine-specific.  On x86, only the user_regs_struct parts at
the beginning, and the u_debugreg parts near the end, are offsets that are
valid in ptrace calls.  The other elements in x86's 'struct user' are just
historical cruft now.  Any documentation of the details would have to be
given for all the different arch layouts.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ptrace PTRACE_PEEKUSER behavior
@ 2008-05-08  6:51 Anoop
  2008-05-08 19:44 ` Roland McGrath
  0 siblings, 1 reply; 6+ messages in thread
From: Anoop @ 2008-05-08  6:51 UTC (permalink / raw)
  To: Roland McGrath; +Cc: linux-kernel, andi, mtk.manpages


Quoting Roland McGrath <roland@redhat.com>:

> 'struct user' is really a virtual structure layout, and never exists
> anywhere as an actual struct.  It's really just defining the argument
> values that can be used in PEEKUSR/POKEUSR calls.

But the powerpc ptrace code returns the FPRs & FPSCR though they are  
not part of user struct.

CHECK_FULL_REGS(child->thread.regs);
if (index < PT_FPR0) {
		tmp = ptrace_get_reg(child, (int) index);
} else { <=============
		flush_fp_to_thread(child);
		tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0];
}
ret = put_user(tmp,(unsigned long __user *) data);

Does this mandate inclusion of floating point set in powerpc user struct?

Regards,
- Anoop


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: ptrace PTRACE_PEEKUSER behavior
  2008-05-08  6:51 Anoop
@ 2008-05-08 19:44 ` Roland McGrath
  0 siblings, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2008-05-08 19:44 UTC (permalink / raw)
  To: Anoop; +Cc: linux-kernel, andi, mtk.manpages

> 
> Quoting Roland McGrath <roland@redhat.com>:
> 
> > 'struct user' is really a virtual structure layout, and never exists
> > anywhere as an actual struct.  It's really just defining the argument
> > values that can be used in PEEKUSR/POKEUSR calls.
> 
> But the powerpc ptrace code returns the FPRs & FPSCR though they are  
> not part of user struct.

I guess I was too strong in describing 'struct user' as useful even in that
sense.  Each arch defines the offset values for its PEEKUSR/POKEUSR, and on
powerpc the asm/ptrace.h PT_* macros are the only true definition of that ABI.

'struct user' is used in a.out core dumps, if those can even still be
generated on powerpc.  Other than that, the struct is actually meaningless
cruft on powerpc.  On other machines it's almost that, except that e.g. on
x86 there is no other definition than offsetof(struct user, u_debugreg[0])
to supply that offset for PTRACE_POKEUSR.

> Does this mandate inclusion of floating point set in powerpc user struct?

I think what it mandates is dropping any idea that 'struct user' is
necessarily meaningful in any generic sense.  The only use it has is
arch-specific cases where offsetof(struct user, something) is part of the
ptrace ABI.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-05-08 19:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-05 11:01 ptrace PTRACE_PEEKUSER behavior Anoop
2008-05-05 11:55 ` Andi Kleen
2008-05-05 12:45   ` Michael Kerrisk
2008-05-05 19:04 ` Roland McGrath
  -- strict thread matches above, loose matches on Subject: below --
2008-05-08  6:51 Anoop
2008-05-08 19:44 ` Roland McGrath

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.