Skip to contentSkip to conversation

FAILED: patch "[PATCH] riscv: kprobes: Fix incorrect address calculation" failed to apply to 6.6-stable tree

PATCH In review [email protected] 3 participants 3 messages Jan 12, 2025 – Jan 13, 2025

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 13134cc949148e1dfa540a0fe5dc73569bc62155
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025011231-bakery-sterling-1f23@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 13134cc949148e1dfa540a0fe5dc73569bc62155 Mon Sep 17 00:00:00 2001
From: Nam Cao <[email protected]>
Date: Tue, 19 Nov 2024 12:10:56 +0100
Subject: [PATCH] riscv: kprobes: Fix incorrect address calculation

p->ainsn.api.insn is a pointer to u32, therefore arithmetic operations are multiplied by four. This is clearly undesirable for this case.

Cast it to (void *) first before any calculation.

Below is a sample before/after. The dumped memory is two kprobe slots, the first slot has

- c.addiw a0, 0x1c (0x7125)
- ebreak (0x00100073)

and the second slot has:

- c.addiw a0, -4 (0x7135)
- ebreak (0x00100073)

Before this patch:

(gdb) x/16xh 0xff20000000135000
0xff20000000135000: 0x7125 0x0000 0x0000 0x0000 0x7135 0x0010 0x0000 0x0000
0xff20000000135010: 0x0073 0x0010 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000

After this patch:

(gdb) x/16xh 0xff20000000125000
0xff20000000125000: 0x7125 0x0073 0x0010 0x0000 0x7135 0x0073 0x0010 0x0000
0xff20000000125010: 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000

Fixes b1756750a397 ("riscv: kprobes: Use patch_text_nosync() for insn slots")
arch/riscv/kernel/probes/kprobes.c +1 -1
index 380a0e8cecc0..c0738d6c6498 100644
@@ -30,7 +30,7 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
 	p->ainsn.api.restore = (unsigned long)p->addr + len;
 
 	patch_text_nosync(p->ainsn.api.insn, &p->opcode, len);
-	patch_text_nosync(p->ainsn.api.insn + len, &insn, GET_INSN_LENGTH(insn));
+	patch_text_nosync((void *)p->ainsn.api.insn + len, &insn, GET_INSN_LENGTH(insn));
 }
 
 static void __kprobes arch_prepare_simulate(struct kprobe *p)
#1 lore raw

PATCH 1/1 riscv: kprobes: Fix incorrect address calculation

commit 13134cc949148e1dfa540a0fe5dc73569bc62155 upstream.

p->ainsn.api.insn is a pointer to u32, therefore arithmetic operations are multiplied by four. This is clearly undesirable for this case.

Cast it to (void *) first before any calculation.

Below is a sample before/after. The dumped memory is two kprobe slots, the first slot has

- c.addiw a0, 0x1c (0x7125)
- ebreak (0x00100073)

and the second slot has:

- c.addiw a0, -4 (0x7135)
- ebreak (0x00100073)

Before this patch:

(gdb) x/16xh 0xff20000000135000
0xff20000000135000: 0x7125 0x0000 0x0000 0x0000 0x7135 0x0010 0x0000 0x0000
0xff20000000135010: 0x0073 0x0010 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000

After this patch:

(gdb) x/16xh 0xff20000000125000
0xff20000000125000: 0x7125 0x0073 0x0010 0x0000 0x7135 0x0073 0x0010 0x0000
0xff20000000125010: 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000

Fixes b1756750a397 ("riscv: kprobes: Use patch_text_nosync() for insn slots")
[rebase to v6.6]
---
 arch/riscv/kernel/probes/kprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/probes/kprobes.c +1 -1
index fecbbcf40ac3..4fbc70e823f0 100644
@@ -29,7 +29,7 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
 	p->ainsn.api.restore = (unsigned long)p->addr + offset;
 
 	patch_text_nosync(p->ainsn.api.insn, &p->opcode, 1);
-	patch_text_nosync(p->ainsn.api.insn + offset, &insn, 1);
+	patch_text_nosync((void *)p->ainsn.api.insn + offset, &insn, 1);
 }
 
 static void __kprobes arch_prepare_simulate(struct kprobe *p)
Signature · 1 line
2.39.5
maintainer
#2 lore raw

Re: [PATCH 6.6.y] riscv: kprobes: Fix incorrect address calculation

[ Sasha's backport helper bot ]

Hi,

The upstream commit SHA1 provided is correct: 13134cc949148e1dfa540a0fe5dc73569bc62155

Status in newer kernel trees:
6.12.y | Present (different SHA1: 79be3a64d83c)
6.6.y | Present (different SHA1: e9d56f517630)

Note: The patch differs from the upstream commit:
---

1:  13134cc94914 < -:  ------------ riscv: kprobes: Fix incorrect address calculation
-:  ------------ > 1:  bc6c56837c1b riscv: kprobes: Fix incorrect address calculation

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y        |  Success    |  Success   |