Commit 6d855b1d83c980c1283d98d2d63a2bd3a87e21b7

Authored by Jason Wessel
1 parent 55751145dc

gdbstub: do not directly use dbg_reg_def[] in gdb_cmd_reg_set()

Presently the usable registers definitions on x86 are not contiguous
for kgdb.  The x86 kgdb uses a case statement for the sparse register
accesses.  The array which defines the registers (dbg_reg_def) should
not be used directly in order to safely work with sparse register
definitions.

Specifically there was a problem when gdb accesses ORIG_AX, which is
accessed only through the case statement.

This patch encodes register memory using the size information provided
from the debugger which avoids the need to look up the size of the
register.  The dbg_set_reg() function always further validates the
inputs from the debugger.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Dongdong Deng <dongdong.deng@windriver.com>

Showing 1 changed file with 9 additions and 1 deletions Side-by-side Diff

kernel/debug/gdbstub.c
... ... @@ -604,6 +604,7 @@
604 604 {
605 605 unsigned long regnum;
606 606 char *ptr = &remcom_in_buffer[1];
  607 + int i = 0;
607 608  
608 609 kgdb_hex2long(&ptr, &regnum);
609 610 if (*ptr++ != '=' ||
... ... @@ -612,7 +613,14 @@
612 613 error_packet(remcom_out_buffer, -EINVAL);
613 614 return;
614 615 }
615   - kgdb_hex2mem(ptr, (char *)gdb_regs, dbg_reg_def[regnum].size);
  616 + memset(gdb_regs, 0, sizeof(gdb_regs));
  617 + while (i < sizeof(gdb_regs) * 2)
  618 + if (hex_to_bin(ptr[i]) >= 0)
  619 + i++;
  620 + else
  621 + break;
  622 + i = i / 2;
  623 + kgdb_hex2mem(ptr, (char *)gdb_regs, i);
616 624 dbg_set_reg(regnum, gdb_regs, ks->linux_regs);
617 625 strcpy(remcom_out_buffer, "OK");
618 626 }