kgdb 2.6.27-rc7 fixes
Subsystems (5)
Linus, please pull the kgdb git tree fixes for 2.6.27-rc7
git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb.git for_linus
Summary:
Several regressions have been fixed for which there was no automated test.
- Fix regression in flushing data/instruction cache on boundaries
- User space single stepping should be ignored by kgdb
- x86_64 had the BX and DX registers reversed in gdb
- x86_64 eflags, CS, SS, registers were not properly passed to gdb
- tty_io.c has one function repaired which is only used kgdboc to hook up to the tty system. The input args were not properly checked. Test case was:
"echo ffff0 > /sys/module/kgdboc/parameters/kgdboc"
Short log follows:
---
Atsuo Igarashi (1):
kgdb: could not write to the last of valid memory with kgdb
Jason Wessel (4):
kgdb, x86, arm, mips, powerpc: ignore user space single stepping kgdb, x86_64: gdb serial has BX and DX reversed
kgdb, x86_64: fix PS CS SS registers in gdb serial kgdboc,tty: Fix tty polling search to use name correctly
arch/arm/kernel/kgdb.c | 2 -- arch/mips/kernel/kgdb.c | 3 +-- arch/powerpc/kernel/kgdb.c | 5 ++--- arch/x86/kernel/kgdb.c | 43 ++++++++++++++++++++++++++++++++----------- drivers/char/tty_io.c | 14 ++++++++++++-- include/asm-x86/kgdb.h | 24 +++++++++++------------- kernel/kgdb.c | 10 +++++----- 7 files changed, 63 insertions(+), 38 deletions(-)
PATCH 1/5 kgdb: could not write to the last of valid memory with kgdb
From: Atsuo Igarashi <[email protected]>
On the ARM architecture, kgdb will crash the kernel if the last byte of valid memory is written due to a flush_icache_range flushing beyond the memory boundary.
--- kernel/kgdb.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/kgdb.c +1 -1
@@ -488,7 +488,7 @@ static int write_mem_msg(int binary)if (err)return err;if (CACHE_FLUSH_IS_SAFE ) -flush_icache_range (addr, addr + length +1 ); +flush_icache_range (addr, addr + length);return 0 ; }
Signature · 1 line
1.6.0.90.g436ed.dirty
PATCH 2/5 kgdb, x86, arm, mips, powerpc: ignore user space single stepping
On the x86 arch, user space single step exceptions should be ignored if they occur in the kernel space, such as ptrace stepping through a system call.
First check if it is kgdb that is executing a single step, then ensure it is not an accidental traversal into the user space, while in kgdb, any other time the TIF_SINGLESTEP is set, kgdb should ignore the exception.
On x86, arm, mips and powerpc, the kgdb_contthread usage was inconsistent with the way single stepping is implemented in the kgdb core. The arch specific stub should always set the kgdb_cpu_doing_single_step correctly if it is single stepping. This allows kgdb to correctly process an instruction steps if ptrace happens to be requesting an instruction step over a system call.
--- arch/arm/kernel/kgdb.c | 2 -- arch/mips/kernel/kgdb.c | 3 +-- arch/powerpc/kernel/kgdb.c | 5 ++--- arch/x86/kernel/kgdb.c | 18 +++++++++++------- kernel/kgdb.c | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-)
arch/arm/kernel/kgdb.c +0 -2
@@ -111,8 +111,6 @@ int kgdb_arch_handle_exception(int exception_vector, int signo,case 'D' :case 'k' :case 'c' : - kgdb_contthread =NULL ; -/* * Try to read optional parameter, pc unchanged if no parm. * If this was a compiled breakpoint, we need to move
arch/mips/kernel/kgdb.c +1 -2
@@ -236,8 +236,7 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,atomic_set (&kgdb_cpu_doing_single_step,-1 );if (remcom_in_buffer[0 ] =='s' ) -if (kgdb_contthread) -atomic_set (&kgdb_cpu_doing_single_step, cpu); +atomic_set (&kgdb_cpu_doing_single_step, cpu);return 0 ; }
arch/powerpc/kernel/kgdb.c +2 -3
@@ -347,9 +347,8 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code, linux_regs->msr |=MSR_SE ;#endif kgdb_single_step =1 ; -if (kgdb_contthread) -atomic_set (&kgdb_cpu_doing_single_step, -raw_smp_processor_id ()); +atomic_set (&kgdb_cpu_doing_single_step, +raw_smp_processor_id ()); }return 0 ; }
arch/x86/kernel/kgdb.c +11 -7
@@ -378,10 +378,8 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,if (remcomInBuffer[0 ] =='s' ) { linux_regs->flags |=X86_EFLAGS_TF ; kgdb_single_step =1 ; -if (kgdb_contthread) { -atomic_set (&kgdb_cpu_doing_single_step, -raw_smp_processor_id ()); - } +atomic_set (&kgdb_cpu_doing_single_step, +raw_smp_processor_id ()); }get_debugreg (dr6,6 );
@@ -466,9 +464,15 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)case DIE_DEBUG :if (atomic_read (&kgdb_cpu_doing_single_step) == -raw_smp_processor_id () && -user_mode (regs)) -return single_step_cont (regs, args); +raw_smp_processor_id ()) { +if (user_mode (regs)) +return single_step_cont (regs, args); +break ; + }else if (test_thread_flag (TIF_SINGLESTEP )) +/* This means a user thread is single stepping +* a system call which should be ignored +*/ +return NOTIFY_DONE ;/* fall through */ default :if (user_mode (regs))
kernel/kgdb.c +4 -4
@@ -1462,7 +1462,7 @@ acquirelock:* Get the passive CPU lock which will hold all the non-primary * CPU in a spin state while the debugger is active */ -if (!kgdb_single_step || !kgdb_contthread) { +if (!kgdb_single_step) {for (i =0 ; i <NR_CPUS ; i++)atomic_set (&passive_cpu_wait[i],1 ); }
@@ -1475,7 +1475,7 @@ acquirelock:#ifdef CONFIG_SMP /* Signal the other CPUs to enter kgdb_wait() */ -if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup) +if ((!kgdb_single_step) && kgdb_do_roundup)kgdb_roundup_cpus (flags);#endif
@@ -1494,7 +1494,7 @@ acquirelock:kgdb_post_primary_code (ks->linux_regs, ks->ex_vector, ks->err_code);kgdb_deactivate_sw_breakpoints (); kgdb_single_step =0 ; - kgdb_contthread =NULL ; + kgdb_contthread = current; exception_level =0 ;/* Talk to debugger with gdbserial protocol */
@@ -1508,7 +1508,7 @@ acquirelock: kgdb_info[ks->cpu].task =NULL ;atomic_set (&cpu_in_kgdb[ks->cpu],0 ); -if (!kgdb_single_step || !kgdb_contthread) { +if (!kgdb_single_step) {for (i =NR_CPUS -1 ; i >=0 ; i--)atomic_set (&passive_cpu_wait[i],0 );/*
Signature · 1 line
1.6.0.90.g436ed.dirty
PATCH 3/5 kgdb, x86_64: gdb serial has BX and DX reversed
The BX and DX registers in the gdb serial register packet need to be flipped for gdb to receive the correct data.
--- include/asm-x86/kgdb.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
include/asm-x86/kgdb.h +2 -2
@@ -42,9 +42,9 @@ enum regnames {#else /* ! CONFIG_X86_32 */ enum regnames {GDB_AX ,/* 0 */ -GDB_DX ,/* 1 */ +GDB_BX ,/* 1 */ GDB_CX ,/* 2 */ -GDB_BX ,/* 3 */ +GDB_DX ,/* 3 */ GDB_SI ,/* 4 */ GDB_DI ,/* 5 */ GDB_BP, /* 6 */
Signature · 1 line
1.6.0.90.g436ed.dirty
PATCH 4/5 kgdb, x86_64: fix PS CS SS registers in gdb serial
On x86_64 the gdb serial register structure defines the PS (also known as eflags), CS and SS registers as 4 bytes entities.
This patch splits the x86_64 regnames enum into a 32 and 64 version to account for the 32 bit entities in the gdb serial packets.
Also the program counter is properly filled in for the sleeping threads.
--- arch/x86/kernel/kgdb.c | 25 +++++++++++++++++++++---- include/asm-x86/kgdb.h | 20 +++++++++----------- 2 files changed, 30 insertions(+), 15 deletions(-)
arch/x86/kernel/kgdb.c +21 -4
@@ -69,6 +69,9 @@ static int gdb_x86vector = -1;*/ void pt_regs_to_gdb_regs (unsigned long *gdb_regs,struct pt_regs *regs) { +#ifndef CONFIG_X86_32 +u32 *gdb_regs32 = (u32 *)gdb_regs; +#endif gdb_regs[GDB_AX ] = regs->ax; gdb_regs[GDB_BX ] = regs->bx; gdb_regs[GDB_CX ] = regs->cx;
@@ -76,9 +79,9 @@ void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) gdb_regs[GDB_SI ] = regs->si; gdb_regs[GDB_DI ] = regs->di; gdb_regs[GDB_BP ] = regs->bp; - gdb_regs[GDB_PS ] = regs->flags; gdb_regs[GDB_PC ] = regs->ip;#ifdef CONFIG_X86_32 + gdb_regs[GDB_PS ] = regs->flags; gdb_regs[GDB_DS ] = regs->ds; gdb_regs[GDB_ES ] = regs->es; gdb_regs[GDB_CS ] = regs->cs;
@@ -94,6 +97,9 @@ void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) gdb_regs[GDB_R13 ] = regs->r13; gdb_regs[GDB_R14 ] = regs->r14; gdb_regs[GDB_R15 ] = regs->r15; + gdb_regs32[GDB_PS ] = regs->flags; + gdb_regs32[GDB_CS ] = regs->cs; + gdb_regs32[GDB_SS ] = regs->ss;#endif gdb_regs[GDB_SP ] = regs->sp; }
@@ -112,6 +118,9 @@ void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)*/ void sleeping_thread_to_gdb_regs (unsigned long *gdb_regs,struct task_struct *p) { +#ifndef CONFIG_X86_32 +u32 *gdb_regs32 = (u32 *)gdb_regs; +#endif gdb_regs[GDB_AX ] =0 ; gdb_regs[GDB_BX ] =0 ; gdb_regs[GDB_CX ] =0 ;
@@ -129,8 +138,10 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) gdb_regs[GDB_FS ] =0xFFFF ; gdb_regs[GDB_GS ] =0xFFFF ;#else - gdb_regs[GDB_PS ] = *(unsigned long *)(p->thread.sp +8 ); - gdb_regs[GDB_PC ] =0 ; + gdb_regs32[GDB_PS ] = *(unsigned long *)(p->thread.sp +8 ); + gdb_regs32[GDB_CS ] = __KERNEL_CS; + gdb_regs32[GDB_SS ] = __KERNEL_DS; + gdb_regs[GDB_PC ] = p->thread.ip; gdb_regs[GDB_R8 ] =0 ; gdb_regs[GDB_R9 ] =0 ; gdb_regs[GDB_R10 ] =0 ;
@@ -153,6 +164,9 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)*/ void gdb_regs_to_pt_regs (unsigned long *gdb_regs,struct pt_regs *regs) { +#ifndef CONFIG_X86_32 +u32 *gdb_regs32 = (u32 *)gdb_regs; +#endif regs->ax = gdb_regs[GDB_AX ]; regs->bx = gdb_regs[GDB_BX ]; regs->cx = gdb_regs[GDB_CX ];
@@ -160,9 +174,9 @@ void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) regs->si = gdb_regs[GDB_SI ]; regs->di = gdb_regs[GDB_DI ]; regs->bp = gdb_regs[GDB_BP ]; - regs->flags = gdb_regs[GDB_PS ]; regs->ip = gdb_regs[GDB_PC ];#ifdef CONFIG_X86_32 + regs->flags = gdb_regs[GDB_PS ]; regs->ds = gdb_regs[GDB_DS ]; regs->es = gdb_regs[GDB_ES ]; regs->cs = gdb_regs[GDB_CS ];
@@ -175,6 +189,9 @@ void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) regs->r13 = gdb_regs[GDB_R13 ]; regs->r14 = gdb_regs[GDB_R14 ]; regs->r15 = gdb_regs[GDB_R15 ]; + regs->flags = gdb_regs32[GDB_PS ]; + regs->cs = gdb_regs32[GDB_CS ]; + regs->ss = gdb_regs32[GDB_SS ];#endif }
include/asm-x86/kgdb.h +9 -11
@@ -39,8 +39,9 @@ enum regnames {GDB_FS ,/* 14 */ GDB_GS, /* 15 */ }; +#define NUMREGBYTES ((GDB_GS+1)*4)#else /* ! CONFIG_X86_32 */ -enum regnames { +enum regnames64 {GDB_AX ,/* 0 */ GDB_BX ,/* 1 */ GDB_CX, /* 2 */
@@ -58,18 +59,15 @@ enum regnames {GDB_R14 ,/* 14 */ GDB_R15 ,/* 15 */ GDB_PC, /* 16 */ - GDB_PS, /* 17 */ }; -#endif /* CONFIG_X86_32 */ -/* -* Number of bytes of registers: -*/ -#ifdef CONFIG_X86_32 -# define NUMREGBYTES 64 -#else -# define NUMREGBYTES ((GDB_PS+1)*8) -#endif +enum regnames32 { +GDB_PS =34 , +GDB_CS , +GDB_SS , +}; +#define NUMREGBYTES ((GDB_SS+1)*4) +#endif /* CONFIG_X86_32 */ static inline void arch_kgdb_breakpoint (void ) {
Signature · 1 line
1.6.0.90.g436ed.dirty
PATCH 5/5 kgdboc,tty: Fix tty polling search to use name correctly
The tty_find_polling_driver() routine did not correctly check the base part of the tty name. This can lead to kgdboc selecting an incorrect driver, as well as accepting a completely invalid tty such as "echo ffff0 > /sys/module/kgdboc/parameters/kgdboc".
--- drivers/char/tty_io.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
drivers/char/tty_io.c +12 -2
@@ -695,13 +695,23 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line) {struct tty_driver *p, *res =NULL ;int tty_line =0 ; +int len;char *str; +for (str = name; *str; str++) +if ((*str >='0' && *str <='9' ) || *str ==',' ) +break ; +if (!*str) +return NULL ; + + len = str - name; + tty_line =simple_strtoul (str, &str,10 ); +mutex_lock (&tty_mutex);/* Search through the tty devices to look for a match */ list_for_each_entry (p, &tty_drivers, tty_drivers) { - str = name +strlen (p->name); - tty_line =simple_strtoul (str, &str,10 ); +if (strncmp (name, p->name, len) !=0 ) +continue ;if (*str ==',' ) str++;if (*str =='\0' )
Signature · 1 line
1.6.0.90.g436ed.dirty