linux/arch/powerpc/xmon
Madhavan Srinivasan 0405e12811 powerpc/xmon: Fix tmpstr length check in scanhex
If a function name is greater than 63 characters long, xmon command
may not find them. For example, here is a test that executed an illegal
instruction in a kernel function and one of call stack function has a
name greater than 63 characters long:

  cpu 0x0: Vector: 700 (Program Check) at [c00000000a6577e0]
      pc: c0000000001aacb8: check__allowed__function__name__for__symbol__r4+0x8/0x10
      lr: c00000000019c1e0: check__allowed__function__name__for__symbol__r1+0x20/0x40
      sp: c00000000a657a80
     msr: 800000000288b033
    current = 0xc00000000a439900
    paca    = 0xc000000003e90000	 irqmask: 0x03	 irq_happened: 0x01
  .....
  [link register   ] c00000000019c1e0 check__allowed__function__name__for__symbol__r1+0x20/0x40
  [c00000000a657a80] c00000000a439900 (unreliable)
  [c00000000a657aa0] c0000000001021d8 check__allowed__function__name__for__symbol__r2_resolution_symbol+0x38/0x4c
  [c00000000a657ac0] c00000000019b424 power_pmu_event_init+0xa4/0xa50

and when executing a dump instruction (di) command for long function
name, xmon fails to find the function symbol:

  0:mon> di $check__allowed__function__name__for__symbol__r2_resolution_symbol
  unknown symbol 'check__allowed__function__name__for__symbol__r2_resolution_symb'
  0000000000000000  ********

This is because in scanhex(), tmpstr loop index is checked only for
a upper bound of 63.

Fix it by replacing the upper bound value with (KSYM_NAME_LEN-1).

With fix:

  0:mon> di $check__allowed__function__name__for__symbol__r2_resolution_symbol
  c0000000001021a0  3c4c0249	addis   r2,r12,585
  c0000000001021a4  3842ae60	addi    r2,r2,-20896
  c0000000001021a8  7c0802a6	mflr    r0
  c0000000001021ac  60000000	nop
  .....

Reported-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Closes: https://lore.kernel.org/linuxppc-dev/CANiq72=QeTgtZL4k9=4CJP6C_Hv=rh3fsn3B9S3KFoPXkyWk3w@mail.gmail.com/
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240826064217.46658-1-maddy@linux.ibm.com
2024-08-27 17:10:55 +10:00
..
ansidecl.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
dis-asm.h powerpc/xmon: Fix compile error in print_insn* functions 2020-01-26 00:11:35 +11:00
Makefile powerpc/Makefile: Remove bits related to the previous use of -mcmodel=large 2024-05-07 23:48:45 +10:00
nonstdio.c powerpc/xmon: Change printk() to pr_cont() 2020-12-04 21:56:30 +11:00
nonstdio.h powerpc/xmon: Add __printf annotation to xmon_printf() 2018-05-25 12:04:36 +10:00
ppc-dis.c powerpc/xmon: Fix disassembly CPU feature checks 2024-07-11 17:31:54 +10:00
ppc-opc.c powerpc: fix typos in comments 2022-05-05 22:12:44 +10:00
ppc.h powerpc/xmon: remove unused ppc_parse_cpu() declaration 2022-09-15 22:55:45 +10:00
spr_access.S powerpc/64: asm use consistent global variable declaration and access 2022-09-28 19:22:12 +10:00
spu-dis.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
spu-insns.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
spu-opc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
spu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
xmon_bpts.h powerpc/inst: Define ppc_inst_t 2021-12-09 22:41:21 +11:00
xmon_bpts.S powerpc: Add prefixed instructions to instruction data type 2020-05-19 00:10:39 +10:00
xmon.c powerpc/xmon: Fix tmpstr length check in scanhex 2024-08-27 17:10:55 +10:00