Skip to contentSkip to conversation

arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'?

PATCH In review kernel test robot 3 participants 9 messages Apr 12, 2022 – Apr 29, 2022 Stable branch

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw

Hi Masami,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git queue/4.19
head:   bdfbd5df0daf1748bef4501ce255ce594ee8d55f
commit: d3380de483d55d904fb94a241406b34ed2fada7d [3886/9999] ia64: kprobes: Use generic kretprobe trampoline handler
config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20220413/[email protected]/config)
compiler: ia64-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/commit/?id=d3380de483d55d904fb94a241406b34ed2fada7d
git remote add linux-stable-rc https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
git fetch --no-tags linux-stable-rc queue/4.19
git checkout d3380de483d55d904fb94a241406b34ed2fada7d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=ia64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

arch/ia64/kernel/kprobes.c: In function 'get_kprobe_inst':
arch/ia64/kernel/kprobes.c:338:22: warning: variable 'template' set but not used [-Wunused-but-set-variable]

     338 |         unsigned int template;
         |                      ^~~~~~~~
   arch/ia64/kernel/kprobes.c: At top level:
   arch/ia64/kernel/kprobes.c:412:15: warning: no previous prototype for 'trampoline_probe_handler' [-Wmissing-prototypes]
     412 | int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
         |               ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/ia64/kernel/kprobes.c: In function 'trampoline_probe_handler':
>> arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? [-Werror=implicit-function-declaration]
     414 |         regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                        kretprobe_trampoline

At top level:
arch/ia64/kernel/kprobes.c:928:13: warning: 'ia64_get_bsp_cfm' defined but not used [-Wunused-function]
928 | static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg)
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for FRAME_POINTER
Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
Selected by
- FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC && !X86

vim +414 arch/ia64/kernel/kprobes.c

333
334 static void __kprobes get_kprobe_inst(bundle_t *bundle, uint slot,
335 unsigned long *kprobe_inst, uint *major_opcode)
336 {
337 unsigned long kprobe_inst_p0, kprobe_inst_p1;

 > 338		unsigned int template;
   339	
   340		template = bundle->quad0.template;
   341	
   342		switch (slot) {
   343		  case 0:
   344			*major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT);
   345			*kprobe_inst = bundle->quad0.slot0;
   346			  break;
   347		  case 1:
   348			*major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT);
   349			kprobe_inst_p0 = bundle->quad0.slot1_p0;
   350			kprobe_inst_p1 = bundle->quad1.slot1_p1;
   351			*kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46));
   352			break;
   353		  case 2:
   354			*major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT);
   355			*kprobe_inst = bundle->quad1.slot2;
   356			break;
   357		}
   358	}
   359	
   360	/* Returns non-zero if the addr is in the Interrupt Vector Table */
   361	static int __kprobes in_ivt_functions(unsigned long addr)
   362	{
   363		return (addr >= (unsigned long)__start_ivt_text
   364			&& addr < (unsigned long)__end_ivt_text);
   365	}
   366	
   367	static int __kprobes valid_kprobe_addr(int template, int slot,
   368					       unsigned long addr)
   369	{
   370		if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
   371			printk(KERN_WARNING "Attempting to insert unaligned kprobe "
   372					"at 0x%lx\n", addr);
   373			return -EINVAL;
   374		}
   375	
   376		if (in_ivt_functions(addr)) {
   377			printk(KERN_WARNING "Kprobes can't be inserted inside "
   378					"IVT functions at 0x%lx\n", addr);
   379			return -EINVAL;
   380		}
   381	
   382		return 0;
   383	}
   384	
   385	static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
   386	{
   387		unsigned int i;
   388		i = atomic_add_return(1, &kcb->prev_kprobe_index);
   389		kcb->prev_kprobe[i-1].kp = kprobe_running();
   390		kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
   391	}
   392	
   393	static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
   394	{
   395		unsigned int i;
   396		i = atomic_read(&kcb->prev_kprobe_index);
   397		__this_cpu_write(current_kprobe, kcb->prev_kprobe[i-1].kp);
   398		kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
   399		atomic_sub(1, &kcb->prev_kprobe_index);
   400	}
   401	
   402	static void __kprobes set_current_kprobe(struct kprobe *p,
   403				struct kprobe_ctlblk *kcb)
   404	{
   405		__this_cpu_write(current_kprobe, p);
   406	}
   407	
   408	static void kretprobe_trampoline(void)
   409	{
   410	}
   411	
   412	int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
   413	{
 > 414		regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);

415 /*
416 * By returning a non-zero value, we are telling
417 * kprobe_handler() that we don't want the post_handler
418 * to run (and have re-enabled preemption)
419 */
420 return 1;
421 }
422

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#1 lore raw

Hi Greg,

Can you revert/drop this patch from 4.19 stable tree?
This patch is a part of bigger series, which introduces a generic arch-independent kretprobe trampoline handler, but that is not for the stable tree.

Also, the commit f5f96e3643dc33d6117cf7047e73512046e4858b is in the 4.19 stable tree, which fixes this commit. Thus that must be removed too.

Thank you,

Quoted 147 lines · On Wed, 13 Apr 2022 01:59:56 +0800 kernel test robot <[email protected]> wrote:

Hi Masami,

FYI, the error/warning still remains.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git queue/4.19
head:   bdfbd5df0daf1748bef4501ce255ce594ee8d55f
commit: d3380de483d55d904fb94a241406b34ed2fada7d [3886/9999] ia64: kprobes: Use generic kretprobe trampoline handler
config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20220413/202204130102.JZPa6KCQ-lkp(a)intel.com/config)
compiler: ia64-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/commit/?id=d3380de483d55d904fb94a241406b34ed2fada7d
git remote add linux-stable-rc https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
git fetch --no-tags linux-stable-rc queue/4.19
git checkout d3380de483d55d904fb94a241406b34ed2fada7d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=ia64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

arch/ia64/kernel/kprobes.c: In function 'get_kprobe_inst':
arch/ia64/kernel/kprobes.c:338:22: warning: variable 'template' set but not used [-Wunused-but-set-variable]

     338 |         unsigned int template;
         |                      ^~~~~~~~

arch/ia64/kernel/kprobes.c: At top level:
arch/ia64/kernel/kprobes.c:412:15: warning: no previous prototype for 'trampoline_probe_handler' [-Wmissing-prototypes]
412 | int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
| ^~~~~~~~~~~~~~~~~~~~~~~~
arch/ia64/kernel/kprobes.c: In function 'trampoline_probe_handler':

Quoted 1 line
Quoted 1 line

arch/ia64/kernel/kprobes.c:414:24: error: implicit declaration of function '__kretprobe_trampoline_handler'; did you mean 'kretprobe_trampoline'? [-Werror=implicit-function-declaration]

     414 |         regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
         |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                        kretprobe_trampoline

At top level:
arch/ia64/kernel/kprobes.c:928:13: warning: 'ia64_get_bsp_cfm' defined but not used [-Wunused-function]
928 | static void ia64_get_bsp_cfm(struct unw_frame_info *info, void *arg)
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for FRAME_POINTER
Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
Selected by
- FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC && !X86

vim +414 arch/ia64/kernel/kprobes.c

   333	
   334	static void __kprobes get_kprobe_inst(bundle_t *bundle, uint slot,
   335		       	unsigned long *kprobe_inst, uint *major_opcode)
   336	{
   337		unsigned long kprobe_inst_p0, kprobe_inst_p1;
Quoted 1 line

338 unsigned int template;

339

   340		template = bundle->quad0.template;
   341	
   342		switch (slot) {
   343		  case 0:
   344			*major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT);
   345			*kprobe_inst = bundle->quad0.slot0;
   346			  break;
   347		  case 1:
   348			*major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT);
   349			kprobe_inst_p0 = bundle->quad0.slot1_p0;
   350			kprobe_inst_p1 = bundle->quad1.slot1_p1;
   351			*kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46));
   352			break;
   353		  case 2:
   354			*major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT);
   355			*kprobe_inst = bundle->quad1.slot2;
   356			break;
   357		}
   358	}
   359	
   360	/* Returns non-zero if the addr is in the Interrupt Vector Table */
   361	static int __kprobes in_ivt_functions(unsigned long addr)
   362	{
   363		return (addr >= (unsigned long)__start_ivt_text
   364			&& addr < (unsigned long)__end_ivt_text);
   365	}
   366	
   367	static int __kprobes valid_kprobe_addr(int template, int slot,
   368					       unsigned long addr)
   369	{
   370		if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
   371			printk(KERN_WARNING "Attempting to insert unaligned kprobe "
   372					"at 0x%lx\n", addr);
   373			return -EINVAL;
   374		}
   375	
   376		if (in_ivt_functions(addr)) {
   377			printk(KERN_WARNING "Kprobes can't be inserted inside "
   378					"IVT functions at 0x%lx\n", addr);
   379			return -EINVAL;
   380		}
   381	
   382		return 0;
   383	}
   384	
   385	static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
   386	{
   387		unsigned int i;
   388		i = atomic_add_return(1, &kcb->prev_kprobe_index);
   389		kcb->prev_kprobe[i-1].kp = kprobe_running();
   390		kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
   391	}
   392	
   393	static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
   394	{
   395		unsigned int i;
   396		i = atomic_read(&kcb->prev_kprobe_index);
   397		__this_cpu_write(current_kprobe, kcb->prev_kprobe[i-1].kp);
   398		kcb->kprobe_status = kcb->prev_kprobe[i-1].status;
   399		atomic_sub(1, &kcb->prev_kprobe_index);
   400	}
   401	
   402	static void __kprobes set_current_kprobe(struct kprobe *p,
   403				struct kprobe_ctlblk *kcb)
   404	{
   405		__this_cpu_write(current_kprobe, p);
   406	}
   407	
   408	static void kretprobe_trampoline(void)
   409	{
   410	}
   411	
   412	int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
   413	{
Quoted 1 line

414 regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);

415 /*
416 * By returning a non-zero value, we are telling
417 * kprobe_handler() that we don't want the post_handler
418 * to run (and have re-enabled preemption)
419 */

   420		return 1;
   421	}
   422	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
Signature · 1 line
Masami Hiramatsu <[email protected]>
#2 lore raw
Quoted 3 lines · Masami Hiramatsu

Hi Greg,

Can you revert/drop this patch from 4.19 stable tree?

Can you please send a revert as I do not know what commit you are referring to exactly.

Quoted 6 lines

This patch is a part of bigger series, which introduces a generic arch-independent kretprobe trampoline handler, but that is not for the stable tree.

Also, the commit f5f96e3643dc33d6117cf7047e73512046e4858b is in the 4.19 stable tree, which fixes this commit. Thus that must be removed too.

Same for this, can you send a revert?

thanks,

greg k-h

#3 lore raw
Quoted 8 lines · On Mon, 25 Apr 2022 17:54:59 +0200 Greg Kroah-Hartman…
Quoted 3 lines · Masami Hiramatsu

Hi Greg,

Can you revert/drop this patch from 4.19 stable tree?

Can you please send a revert as I do not know what commit you are referring to exactly.

Quoted 8 lines
Quoted 6 lines

This patch is a part of bigger series, which introduces a generic arch-independent kretprobe trampoline handler, but that is not for the stable tree.

Also, the commit f5f96e3643dc33d6117cf7047e73512046e4858b is in the 4.19 stable tree, which fixes this commit. Thus that must be removed too.

Same for this, can you send a revert?

OK, let me send it.

Thanks!

Quoted 4 lines

thanks,

greg k-h

Signature · 1 line
Masami Hiramatsu <[email protected]>
#4 lore raw

cover ia64: kprobes: Fix build error on ia64

In reply to kernel test robot

Hi,

Kernel test bot reported that the ia64 build error on stable 4.19.y because of the commit d3380de483d5 ("ia64: kprobes: Use generic kretprobe trampoline handler").
I also found that this commit was involved by the backporting of commit f5f96e3643dc ("ia64: kprobes: Fix to pass correct trampoline address to the handler"), and this 2nd commit was backported wrong way. Actually, this 2nd commit aimed to use dereference_function_descriptor() in kprobes@ia64, but the comment (and Fixes tag) points the 1st commit. Thus I guess this mistake happened.

So I re-backport the upstream commit a7fe2378454c ("ia64: kprobes: Fix to pass correct trampoline address to the handler") correctly, without involving the 1st commit.

Thank you,

---

Masami Hiramatsu (3):
Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler" Revert "ia64: kprobes: Use generic kretprobe trampoline handler"
ia64: kprobes: Fix to pass correct trampoline address to the handler

 arch/ia64/kernel/kprobes.c |   78 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 3 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

#5 lore raw

PATCH 1/3 Revert "ia64: kprobes: Fix to pass correct trampoline address to the handler"

This reverts commit f5f96e3643dc33d6117cf7047e73512046e4858b.

The commit f5f96e3643dc ("ia64: kprobes: Fix to pass correct trampoline address to the handler") was wrongly backported. It involves another commit which is a part of another bigger series, so it should not be backported to the stable tree.

---
 arch/ia64/kernel/kprobes.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/ia64/kernel/kprobes.c +4 -5
index 9cfd3ac027b7..8207b897b49d 100644
@@ -411,8 +411,7 @@ static void kretprobe_trampoline(void)
 
 int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 {
-	regs->cr_iip = __kretprobe_trampoline_handler(regs,
-		dereference_function_descriptor(kretprobe_trampoline), NULL);
+	regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
 	/*
 	 * By returning a non-zero value, we are telling
 	 * kprobe_handler() that we don't want the post_handler
@@ -428,7 +427,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
 	ri->fp = NULL;
 
 	/* Replace the return addr with trampoline addr */
-	regs->b0 = (unsigned long)dereference_function_descriptor(kretprobe_trampoline);
+	regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
 }
 
 /* Check the instruction in the slot is break */
@@ -958,14 +957,14 @@ static struct kprobe trampoline_p = {
 int __init arch_init_kprobes(void)
 {
 	trampoline_p.addr =
-		dereference_function_descriptor(kretprobe_trampoline);
+		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
 	return register_kprobe(&trampoline_p);
 }
 
 int __kprobes arch_trampoline_kprobe(struct kprobe *p)
 {
 	if (p->addr ==
-		dereference_function_descriptor(kretprobe_trampoline))
+		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip)
 		return 1;
 
 	return 0;
#6 lore raw

PATCH 2/3 Revert "ia64: kprobes: Use generic kretprobe trampoline handler"

In reply to Masami Hiramatsu

This reverts commit d3380de483d55d904fb94a241406b34ed2fada7d.

Since this commit is a part of generic kretprobe trampoline handler series, without the other patches in that series, this causes a build error on ia64.

---
 arch/ia64/kernel/kprobes.c |   77 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)
arch/ia64/kernel/kprobes.c +75 -2
index 8207b897b49d..aa41bd5cf9b7 100644
@@ -409,9 +409,83 @@ static void kretprobe_trampoline(void)
 {
 }
 
+/*
+ * At this point the target function has been tricked into
+ * returning into our trampoline.  Lookup the associated instance
+ * and then:
+ *    - call the handler function
+ *    - cleanup by marking the instance as unused
+ *    - long jump back to the original return address
+ */
 int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 {
-	regs->cr_iip = __kretprobe_trampoline_handler(regs, kretprobe_trampoline, NULL);
+	struct kretprobe_instance *ri = NULL;
+	struct hlist_head *head, empty_rp;
+	struct hlist_node *tmp;
+	unsigned long flags, orig_ret_address = 0;
+	unsigned long trampoline_address =
+		((struct fnptr *)kretprobe_trampoline)->ip;
+
+	INIT_HLIST_HEAD(&empty_rp);
+	kretprobe_hash_lock(current, &head, &flags);
+
+	/*
+	 * It is possible to have multiple instances associated with a given
+	 * task either because an multiple functions in the call path
+	 * have a return probe installed on them, and/or more than one return
+	 * return probe was registered for a target function.
+	 *
+	 * We can handle this because:
+	 *     - instances are always inserted at the head of the list
+	 *     - when multiple return probes are registered for the same
+	 *       function, the first instance's ret_addr will point to the
+	 *       real return address, and all the rest will point to
+	 *       kretprobe_trampoline
+	 */
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->task != current)
+			/* another task is sharing our hash bucket */
+			continue;
+
+		orig_ret_address = (unsigned long)ri->ret_addr;
+		if (orig_ret_address != trampoline_address)
+			/*
+			 * This is the real return address. Any other
+			 * instances associated with this task are for
+			 * other calls deeper on the call stack
+			 */
+			break;
+	}
+
+	regs->cr_iip = orig_ret_address;
+
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->task != current)
+			/* another task is sharing our hash bucket */
+			continue;
+
+		if (ri->rp && ri->rp->handler)
+			ri->rp->handler(ri, regs);
+
+		orig_ret_address = (unsigned long)ri->ret_addr;
+		recycle_rp_inst(ri, &empty_rp);
+
+		if (orig_ret_address != trampoline_address)
+			/*
+			 * This is the real return address. Any other
+			 * instances associated with this task are for
+			 * other calls deeper on the call stack
+			 */
+			break;
+	}
+	kretprobe_assert(ri, orig_ret_address, trampoline_address);
+
+	kretprobe_hash_unlock(current, &flags);
+
+	hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
+		hlist_del(&ri->hlist);
+		kfree(ri);
+	}
 	/*
 	 * By returning a non-zero value, we are telling
 	 * kprobe_handler() that we don't want the post_handler
@@ -424,7 +498,6 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
 				      struct pt_regs *regs)
 {
 	ri->ret_addr = (kprobe_opcode_t *)regs->b0;
-	ri->fp = NULL;
 
 	/* Replace the return addr with trampoline addr */
 	regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
#7 lore raw

PATCH 3/3 ia64: kprobes: Fix to pass correct trampoline address to the handler

In reply to Masami Hiramatsu

commit a7fe2378454cf46cd5e2776d05e72bbe8f0a468c upstream.

The following commit:

Commit e792ff804f49 ("ia64: kprobes: Use generic kretprobe trampoline handler")

Passed the wrong trampoline address to __kretprobe_trampoline_handler(): it passes the descriptor address instead of function entry address.

Pass the right parameter.

Also use correct symbol dereference function to get the function address from 'kretprobe_trampoline' - an IA64 special.

Fixes e792ff804f49 ("ia64: kprobes: Use generic kretprobe trampoline handler")
Cc Josh Poimboeuf <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc X86 ML <[email protected]>
Cc Daniel Xu <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Abhishek Sagar <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Paul McKenney <[email protected]>
---
 arch/ia64/kernel/kprobes.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/ia64/kernel/kprobes.c +4 -4
index aa41bd5cf9b7..7fc0806bbdc9 100644
@@ -424,7 +424,7 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 	struct hlist_node *tmp;
 	unsigned long flags, orig_ret_address = 0;
 	unsigned long trampoline_address =
-		((struct fnptr *)kretprobe_trampoline)->ip;
+		(unsigned long)dereference_function_descriptor(kretprobe_trampoline);
 
 	INIT_HLIST_HEAD(&empty_rp);
 	kretprobe_hash_lock(current, &head, &flags);
@@ -500,7 +500,7 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
 	ri->ret_addr = (kprobe_opcode_t *)regs->b0;
 
 	/* Replace the return addr with trampoline addr */
-	regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
+	regs->b0 = (unsigned long)dereference_function_descriptor(kretprobe_trampoline);
 }
 
 /* Check the instruction in the slot is break */
@@ -1030,14 +1030,14 @@ static struct kprobe trampoline_p = {
 int __init arch_init_kprobes(void)
 {
 	trampoline_p.addr =
-		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
+		dereference_function_descriptor(kretprobe_trampoline);
 	return register_kprobe(&trampoline_p);
 }
 
 int __kprobes arch_trampoline_kprobe(struct kprobe *p)
 {
 	if (p->addr ==
-		(kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip)
+		dereference_function_descriptor(kretprobe_trampoline))
 		return 1;
 
 	return 0;
#8 lore raw

Re: [PATCH 4.19.y 0/3] ia64: kprobes: Fix build error on ia64

In reply to Masami Hiramatsu
Quoted 12 lines · Masami Hiramatsu

Hi,

Kernel test bot reported that the ia64 build error on stable 4.19.y because of the commit d3380de483d5 ("ia64: kprobes: Use generic kretprobe trampoline handler").
I also found that this commit was involved by the backporting of commit f5f96e3643dc ("ia64: kprobes: Fix to pass correct trampoline address to the handler"), and this 2nd commit was backported wrong way. Actually, this 2nd commit aimed to use dereference_function_descriptor() in kprobes@ia64, but the comment (and Fixes tag) points the 1st commit. Thus I guess this mistake happened.

Quoted 5 lines

So I re-backport the upstream commit a7fe2378454c ("ia64: kprobes: Fix to pass correct trampoline address to the handler") correctly, without involving the 1st commit.

Thank you,

All now queued up, thanks.

greg k-h