mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: alexander.levin@verizon.com
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	KUMANO Syuhei <kumano.prog@gmail.com>,
	Jon Medhurst <tixy@linaro.org>,
	alexander.levin@verizon.com
Subject: [PATCH AUTOSEL for 4.9 007/100] arm: kprobes: Fix the return address of multiple kretprobes
Date: Wed, 13 Dec 2017 01:56:15 +0000	[thread overview]
Message-ID: <20171213015606.6568-7-alexander.levin@verizon.com> (raw)
In-Reply-To: <20171213015606.6568-1-alexander.levin@verizon.com>

From: Masami Hiramatsu <mhiramat@kernel.org>

[ Upstream commit 06553175f585b52509c7df37d6f4a50aacb7b211 ]

This is arm port of commit 737480a0d525 ("kprobes/x86:
Fix the return address of multiple kretprobes").

Fix the return address of subsequent kretprobes when multiple
kretprobes are set on the same function.

For example:

  # cd /sys/kernel/debug/tracing
  # echo "r:event1 sys_symlink" > kprobe_events
  # echo "r:event2 sys_symlink" >> kprobe_events
  # echo 1 > events/kprobes/enable
  # ln -s /tmp/foo /tmp/bar

 (without this patch)

  # cat trace | grep -v ^#
              ln-82    [000] dn.2    68.446525: event1: (kretprobe_trampoline+0x0/0x18 <- SyS_symlink)
              ln-82    [000] dn.2    68.447831: event2: (ret_fast_syscall+0x0/0x1c <- SyS_symlink)

 (with this patch)

  # cat trace | grep -v ^#
              ln-81    [000] dn.1    39.463469: event1: (ret_fast_syscall+0x0/0x1c <- SyS_symlink)
              ln-81    [000] dn.1    39.464701: event2: (ret_fast_syscall+0x0/0x1c <- SyS_symlink)

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: KUMANO Syuhei <kumano.prog@gmail.com>
Signed-off-by: Jon Medhurst <tixy@linaro.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 arch/arm/probes/kprobes/core.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/arm/probes/kprobes/core.c b/arch/arm/probes/kprobes/core.c
index a4ec240ee7ba..3eb018fa1a1f 100644
--- a/arch/arm/probes/kprobes/core.c
+++ b/arch/arm/probes/kprobes/core.c
@@ -433,6 +433,7 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
 	struct hlist_node *tmp;
 	unsigned long flags, orig_ret_address = 0;
 	unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
+	kprobe_opcode_t *correct_ret_addr = NULL;
 
 	INIT_HLIST_HEAD(&empty_rp);
 	kretprobe_hash_lock(current, &head, &flags);
@@ -455,14 +456,34 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
 			/* 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;
+	}
+
+	kretprobe_assert(ri, orig_ret_address, trampoline_address);
+
+	correct_ret_addr = ri->ret_addr;
+	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 (ri->rp && ri->rp->handler) {
 			__this_cpu_write(current_kprobe, &ri->rp->kp);
 			get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
+			ri->ret_addr = correct_ret_addr;
 			ri->rp->handler(ri, regs);
 			__this_cpu_write(current_kprobe, NULL);
 		}
 
-		orig_ret_address = (unsigned long)ri->ret_addr;
 		recycle_rp_inst(ri, &empty_rp);
 
 		if (orig_ret_address != trampoline_address)
@@ -474,7 +495,6 @@ static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
 			break;
 	}
 
-	kretprobe_assert(ri, orig_ret_address, trampoline_address);
 	kretprobe_hash_unlock(current, &flags);
 
 	hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
-- 
2.11.0

  parent reply	other threads:[~2017-12-13  1:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13  1:56 [PATCH AUTOSEL for 4.9 001/100] cxl: Route eeh events to all slices for pci_channel_io_perm_failure state alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 002/100] ALSA: hda - add support for docking station for HP 820 G2 alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 004/100] kvm: fix usage of uninit spinlock in avic_vm_destroy() alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 003/100] ALSA: hda - add support for docking station for HP 840 G3 alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 005/100] HID: corsair: support for K65-K70 Rapidfire and Scimitar Pro RGB alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 008/100] arm: kprobes: Align stack to 8-bytes in test code alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 006/100] HID: corsair: Add driver Scimitar Pro RGB gaming mouse 1b1c:1b3e support to hid-corsair alexander.levin
2017-12-13  1:56 ` alexander.levin [this message]
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 011/100] r8152: fix the list rx_done may be used without initialization alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 010/100] cpuidle: Validate cpu_dev in cpuidle_add_sysfs() alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 009/100] nvme-loop: handle cpu unplug when re-establishing the controller alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 014/100] vhost-vsock: add pkt cancel capability alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 012/100] crypto: deadlock between crypto_alg_sem/rtnl_mutex/genl_mutex alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 015/100] vsock: cancel packets when failing to connect alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 013/100] vsock: track pkt owner vsock alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 019/100] net: qmi_wwan: Add USB IDs for MDM6600 modem on Motorola Droid 4 alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 017/100] bna: integer overflow bug in debugfs alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 018/100] sctp: out_qlen should be updated when pruning unsent queue alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 016/100] sch_dsmark: fix invalid skb_cow() usage alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 023/100] netfilter: nfnl_cthelper: fix runtime expectation policy updates alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 022/100] usb: gadget: udc: remove pointer dereference after free alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 020/100] hwmon: (max31790) Set correct PWM value alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 021/100] usb: gadget: f_uvc: Sanity check wMaxPacketSize for SuperSpeed alexander.levin
2017-12-13  1:56 ` [PATCH AUTOSEL for 4.9 024/100] netfilter: nfnl_cthelper: Fix memory leak alexander.levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171213015606.6568-7-alexander.levin@verizon.com \
    --to=alexander.levin@verizon.com \
    --cc=kumano.prog@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tixy@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®