Skip to contentSkip to conversation

powerpc/xmon: Fix tmpstr length check in scanhex

PATCH Applied Madhavan Srinivasan 2 participants 2 messages Aug 26, 2024 – Sep 6, 2024 PowerPC

lore
Share & tools
lore

Madhavan Srinivasan

author maintainer
#0 lore raw

PATCH v3 1/1 powerpc/xmon: Fix tmpstr length check in scanhex

If a function name is greater than 63 char 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 name >63 char 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 the scanhex(), tmpstr loop index is checked only for a upper bound of 63. Proposed fix is to replace 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

.....

---
Changelog v2:
- Fixed the loop upper limit from KSYM_NAME_LEN to (KSYM_NAME_LEN - 1) since last index is initialized with zero at the end of the loop. Thanks mpe for pointing it out.
- Checkpatch script was complaining about the format style

	ERROR: spaces required around that '=' (ctx:VxV)
	#67: FILE: arch/powerpc/xmon/xmon.c:3546:
	+		for (i=0; i < (KSYM_NAME_LEN - 1); i++) {
			      ^

so have fixed the same.

Changelog v1:
- Updated commit message based on Miguel's review comments

 arch/powerpc/xmon/xmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/xmon/xmon.c +1 -1
index bd4813bad317..e6cddbb2305f 100644
@@ -3543,7 +3543,7 @@ scanhex(unsigned long *vp)
 		}
 	} else if (c == '$') {
 		int i;
-		for (i=0; i<63; i++) {
+		for (i = 0; i < (KSYM_NAME_LEN - 1); i++) {
 			c = inchar();
 			if (isspace(c) || c == '\0') {
 				termch = c;
Signature · 1 line
2.45.2
#1 lore raw
Quoted 18 lines · Madhavan Srinivasan

If a function name is greater than 63 char 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 name >63 char 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

Quoted 1 line

[...]

Applied to powerpc/next.

[1/1] powerpc/xmon: Fix tmpstr length check in scanhex

      https://git.kernel.org/powerpc/c/0405e128110d47a40443936e68dc32d7bc4ccc0b

cheers