UML - use correct register file size everywhere
PATCH 1/1 UML - use correct register file size everywhere
This patch uses MAX_REG_NR consistently to refer to the register file size. FRAME_SIZE isn't sufficient because on x86_64, it is smaller than the ptrace register file size. MAX_REG_NR was introduced as a consistent way to get the number of registers, but wasn't used everywhere it should be.
When this causes a problem, it makes PTRACE_SETREGS fail on x86_64 because of a corrupted segment register value in the known-good register file. The patch also adds a register dump at that point in case there are any future problems here.
--
arch/um/include/sysdep-x86_64/ptrace.h | 4 ---- arch/um/os-Linux/skas/mem.c | 10 +++++++--- arch/um/os-Linux/skas/process.c | 6 +++--- arch/um/os-Linux/sys-i386/registers.c | 5 +++-- arch/um/os-Linux/sys-x86_64/registers.c | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-)
arch/um/include/sysdep-x86_64/ptrace.h +0 -4
@@ -104,10 +104,6 @@ union uml_pt_regs {#endif #ifdef UML_CONFIG_MODE_SKAS struct skas_regs { - /* x86_64 ptrace uses sizeof(user_regs_struct) as its register - * file size, while i386 uses FRAME_SIZE. Therefore, we need - * to use UM_FRAME_SIZE here instead of HOST_FRAME_SIZE. - */ unsigned long regs[MAX_REG_NR]; unsigned long fp[HOST_FP_SIZE]; struct faultinfo faultinfo;
arch/um/os-Linux/skas/mem.c +7 -3
@@ -48,7 +48,7 @@ int multi_op_count = 0;static inline long do_syscall_stub (struct mm_id * mm_idp,void **addr) {unsigned long regs[MAX_REG_NR ]; -int n; +int n, i;long ret, offset;unsigned long * data;unsigned long * syscall;
@@ -66,9 +66,13 @@ static inline long do_syscall_stub(struc (unsigned long) &__syscall_stub_start); n =ptrace_setregs (pid, regs); -if (n <0 ) +if (n <0 ){ +printk ("Registers - \n" ); +for (i =0 ; i <MAX_REG_NR ; i++) +printk ("\t%d\t0x%lx\n" , i, regs[i]);panic ("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n" , - n); + -n); + }wait_stub_done (pid,0 ,"do_syscall_stub" );
arch/um/os-Linux/skas/process.c +3 -3
@@ -67,7 +67,7 @@ void wait_stub_done(int pid, int sig, chif ((n <0 ) || !WIFSTOPPED (status) || (WSTOPSIG (status) !=SIGUSR1 &&WSTOPSIG (status) !=SIGTRAP )){ -unsigned long regs[HOST_FRAME_SIZE ]; +unsigned long regs[MAX_REG_NR ];if (ptrace (PTRACE_GETREGS , pid,0 , regs) <0 ) printk("Failed to get registers from stub, "
@@ -76,7 +76,7 @@ void wait_stub_done(int pid, int sig, chint i;printk ("Stub registers -\n" ); -for (i =0 ; i <HOST_FRAME_SIZE ; i++) +for (i =0 ; i <ARRAY_SIZE (regs); i++)printk ("\t%d - %lx\n" , i, regs[i]); } panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
@@ -328,7 +328,7 @@ void userspace(union uml_pt_regs *regs)int copy_context_skas0 (unsigned long new_stack,int pid) {int err; -unsigned long regs[HOST_FRAME_SIZE ]; +unsigned long regs[MAX_REG_NR ];unsigned long fp_regs[HOST_FP_SIZE ];unsigned long current_stack =current_stub_stack ();struct stub_data *data = (struct stub_data *) current_stack;
arch/um/os-Linux/sys-i386/registers.c +3 -2
@@ -15,7 +15,7 @@/* These are set once at boot time and not changed thereafter */ -static unsigned long exec_regs[HOST_FRAME_SIZE ]; +static unsigned long exec_regs[MAX_REG_NR ];static unsigned long exec_fp_regs[HOST_FP_SIZE ];static unsigned long exec_fpx_regs[HOST_XFP_SIZE ];static int have_fpx_regs =1 ;
@@ -101,6 +101,7 @@ void init_registers(int pid) {int err; +memset (exec_regs,0 ,sizeof (exec_regs)); err =ptrace (PTRACE_GETREGS , pid,0 , exec_regs);if (err) panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
@@ -124,7 +125,7 @@ void init_registers(int pid)void get_safe_registers (unsigned long *regs,unsigned long *fp_regs) { -memcpy (regs, exec_regs,HOST_FRAME_SIZE *sizeof (unsigned long )); +memcpy (regs, exec_regs,sizeof (exec_regs));if (fp_regs !=NULL )memcpy (fp_regs, exec_fp_regs,HOST_FP_SIZE *sizeof (unsigned long ));
arch/um/os-Linux/sys-x86_64/registers.c +2 -2
@@ -14,7 +14,7 @@/* These are set once at boot time and not changed thereafter */ -static unsigned long exec_regs[HOST_FRAME_SIZE ]; +static unsigned long exec_regs[MAX_REG_NR ];static unsigned long exec_fp_regs[HOST_FP_SIZE ];void init_thread_registers (union uml_pt_regs *to)
@@ -72,7 +72,7 @@ void init_registers(int pid)void get_safe_registers (unsigned long *regs,unsigned long *fp_regs) { -memcpy (regs, exec_regs,HOST_FRAME_SIZE *sizeof (unsigned long )); +memcpy (regs, exec_regs,sizeof (exec_regs));if (fp_regs !=NULL )memcpy (fp_regs, exec_fp_regs,HOST_FP_SIZE *sizeof (unsigned long ));
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
[uml-devel] patch uml-use-correct-register-file-size-everywhere.patch queued to -stable tree
This is a note to let you know that we have just queued up the patch titled
Subject: UML - use correct register file size everywhere
to the 2.6.20-stable tree. Its filename is
uml-use-correct-register-file-size-everywhere.patch
A git repo of this tree can be found at
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
From [email protected] Sun Mar 25 10:06:00 2007
From: Jeff Dike <[email protected]>
Date: Sun, 25 Mar 2007 13:01:44 -0400
Subject: UML - use correct register file size everywhere
To: Andrew Morton <[email protected]>, [email protected]
Cc: Davide Brini <[email protected]>, uml-devel <[email protected]>
Message-ID: <[email protected]>
Content-Disposition: inline
From: Jeff Dike <[email protected]>
This patch uses MAX_REG_NR consistently to refer to the register file size. FRAME_SIZE isn't sufficient because on x86_64, it is smaller than the ptrace register file size. MAX_REG_NR was introduced as a consistent way to get the number of registers, but wasn't used everywhere it should be.
When this causes a problem, it makes PTRACE_SETREGS fail on x86_64 because of a corrupted segment register value in the known-good register file. The patch also adds a register dump at that point in case there are any future problems here.
arch/um/include/sysdep-x86_64/ptrace.h +0 -4
@@ -104,10 +104,6 @@ union uml_pt_regs {#endif #ifdef UML_CONFIG_MODE_SKAS struct skas_regs { - /* x86_64 ptrace uses sizeof(user_regs_struct) as its register - * file size, while i386 uses FRAME_SIZE. Therefore, we need - * to use UM_FRAME_SIZE here instead of HOST_FRAME_SIZE. - */ unsigned long regs[MAX_REG_NR]; unsigned long fp[HOST_FP_SIZE]; struct faultinfo faultinfo;
arch/um/os-Linux/skas/mem.c +7 -3
@@ -48,7 +48,7 @@ int multi_op_count = 0;static inline long do_syscall_stub (struct mm_id * mm_idp,void **addr) {unsigned long regs[MAX_REG_NR ]; -int n; +int n, i;long ret, offset;unsigned long * data;unsigned long * syscall;
@@ -66,9 +66,13 @@ static inline long do_syscall_stub(struc (unsigned long) &__syscall_stub_start); n =ptrace_setregs (pid, regs); -if (n <0 ) +if (n <0 ){ +printk ("Registers - \n" ); +for (i =0 ; i <MAX_REG_NR ; i++) +printk ("\t%d\t0x%lx\n" , i, regs[i]);panic ("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n" , - n); + -n); + }wait_stub_done (pid,0 ,"do_syscall_stub" );
arch/um/os-Linux/skas/process.c +3 -3
@@ -67,7 +67,7 @@ void wait_stub_done(int pid, int sig, chif ((n <0 ) || !WIFSTOPPED (status) || (WSTOPSIG (status) !=SIGUSR1 &&WSTOPSIG (status) !=SIGTRAP )){ -unsigned long regs[HOST_FRAME_SIZE ]; +unsigned long regs[MAX_REG_NR ];if (ptrace (PTRACE_GETREGS , pid,0 , regs) <0 ) printk("Failed to get registers from stub, "
@@ -76,7 +76,7 @@ void wait_stub_done(int pid, int sig, chint i;printk ("Stub registers -\n" ); -for (i =0 ; i <HOST_FRAME_SIZE ; i++) +for (i =0 ; i <ARRAY_SIZE (regs); i++)printk ("\t%d - %lx\n" , i, regs[i]); } panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
@@ -328,7 +328,7 @@ void userspace(union uml_pt_regs *regs)int copy_context_skas0 (unsigned long new_stack,int pid) {int err; -unsigned long regs[HOST_FRAME_SIZE ]; +unsigned long regs[MAX_REG_NR ];unsigned long fp_regs[HOST_FP_SIZE ];unsigned long current_stack =current_stub_stack ();struct stub_data *data = (struct stub_data *) current_stack;
arch/um/os-Linux/sys-i386/registers.c +3 -2
@@ -15,7 +15,7 @@/* These are set once at boot time and not changed thereafter */ -static unsigned long exec_regs[HOST_FRAME_SIZE ]; +static unsigned long exec_regs[MAX_REG_NR ];static unsigned long exec_fp_regs[HOST_FP_SIZE ];static unsigned long exec_fpx_regs[HOST_XFP_SIZE ];static int have_fpx_regs =1 ;
@@ -101,6 +101,7 @@ void init_registers(int pid) {int err; +memset (exec_regs,0 ,sizeof (exec_regs)); err =ptrace (PTRACE_GETREGS , pid,0 , exec_regs);if (err) panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
@@ -124,7 +125,7 @@ void init_registers(int pid)void get_safe_registers (unsigned long *regs,unsigned long *fp_regs) { -memcpy (regs, exec_regs,HOST_FRAME_SIZE *sizeof (unsigned long )); +memcpy (regs, exec_regs,sizeof (exec_regs));if (fp_regs !=NULL )memcpy (fp_regs, exec_fp_regs,HOST_FP_SIZE *sizeof (unsigned long ));
arch/um/os-Linux/sys-x86_64/registers.c +2 -2
@@ -14,7 +14,7 @@/* These are set once at boot time and not changed thereafter */ -static unsigned long exec_regs[HOST_FRAME_SIZE ]; +static unsigned long exec_regs[MAX_REG_NR ];static unsigned long exec_fp_regs[HOST_FP_SIZE ];void init_thread_registers (union uml_pt_regs *to)
@@ -72,7 +72,7 @@ void init_registers(int pid)void get_safe_registers (unsigned long *regs,unsigned long *fp_regs) { -memcpy (regs, exec_regs,HOST_FRAME_SIZE *sizeof (unsigned long )); +memcpy (regs, exec_regs,sizeof (exec_regs));if (fp_regs !=NULL )memcpy (fp_regs, exec_fp_regs,HOST_FP_SIZE *sizeof (unsigned long ));
_______________________________________________
stable mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/stable
Patches currently in stable-queue which might be from [email protected] are
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel