Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2330818pxk; Mon, 14 Sep 2020 10:23:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd3Uow0UWvIKr5u8Ed+9ZNOq0h6UNbBtsignCmvOrsKsHnmo3AKkqRYtsu9WZ4hqXwRjWC X-Received: by 2002:a17:906:f150:: with SMTP id gw16mr15031921ejb.528.1600104198753; Mon, 14 Sep 2020 10:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600104198; cv=none; d=google.com; s=arc-20160816; b=KN1N2kCCxjl+0sLMaR8MEcSTZrgYj4KN7MnzBUNp99AnlJhAw9TsKGoHbynqPJyI6y Cnsi2sgft7DAbBh+69sY+CRy9B7sLZCUKfQvIcuUpl1bluSu4iMl8kX18n5z8Akdv9NB eoXhrN4gRNWPr2bcx4gSbTWd0aaItPGdDFKgkhIkUR5pEzLwUEk+unr29ym07AQ1S0L6 ck2XdQ8v0ao9YLEUpbY2YDpt77phRAjBNVRPFDhqfGQyBNqVkzLuDFTMj7rNPMtYWgf6 bwYFmE75erimZRUG4SqQfbuxf8MQkzQff9sggJ2n9UcE1PrllFL/JX2+hJbsPVmWWCrs r2GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=tCq1LjRMfGK4M3E4+AQlK7SrbpIss9CsneRfLUYaTp8=; b=lAsJJdDw1+//0x1i9XV2E9+roco206y95rbQz2qNoqh0RI0vzHTp0zDODFbVgl9o78 Rph0a9X1zZk5p7sVNiaPcfCoIzlPwwRD6xN9i8OlwYGLdNblod1boF0OvIsF+mavH3/w cOl7VUUUge3DJwrZpKj+uYda1rVyAp8QD/rvKhyFoO6Ag1oBXVE50R4wyiRzEdkfnI4z bRJCIXUDeYjWM0KwKoU5ByCKd54RVBlQ8SrtqK4HHfptxyQzalipZSyct/aQQyvmUt/c d9StKBVvY89eyf96xmGMo5pt8YSuBsFL+GMxumkdCpiJro5xXEv6gbnagQgpZHeW/ml2 RQJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=xSVJxMXu; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si6131099edy.300.2020.09.14.10.22.55; Mon, 14 Sep 2020 10:23:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=xSVJxMXu; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726031AbgINRT1 (ORCPT + 99 others); Mon, 14 Sep 2020 13:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726341AbgINRQ2 (ORCPT ); Mon, 14 Sep 2020 13:16:28 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79704C06174A; Mon, 14 Sep 2020 10:16:25 -0700 (PDT) Date: Mon, 14 Sep 2020 17:16:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600103784; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tCq1LjRMfGK4M3E4+AQlK7SrbpIss9CsneRfLUYaTp8=; b=xSVJxMXu4wL5GJ8VMHgYdQoGWxvovYz7vScXAaLq7q9sY68IIqlMpc/SxoS0x2hZbTe7zG o+AXy45+ZHlqpwD+tHHeYmZbTAb8JEvNFsHWbFgCoFgu3Thg5qMLMq8UZvDp9pzIoknelm ZbdSH6PuRZ3ZaP7o3D2S/mybpSv5k5GAwCl6kDktmvmp0QrDAPKowhA2QeylG6y1albtMd Y/9YVAGmXVxjePPpQ/k/vzoKDK/uouWT7i2VcrY/B+uJ8RqS9NhQEsXuaUzfN9mWj4/39Q OO++EAGV8y0Esv2KrHEgn+2o+Q/JTKp7U0L2T8fI7lLal+Xcsbw2jn5zOxJwwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600103784; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tCq1LjRMfGK4M3E4+AQlK7SrbpIss9CsneRfLUYaTp8=; b=85qE06q0Cg9a2ZQ5EfbT9DGHLmmKReQ7wa/gPFHrTFbymFvX9Tw4ezAb8xhQtakzkjr9eo 7PTQGMgTdOpmVJBw== From: "tip-bot2 for Masami Hiramatsu" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/kprobes] x86/kprobes: Use generic kretprobe trampoline handler Cc: Masami Hiramatsu , Ingo Molnar , x86 , LKML In-Reply-To: <159870601250.1229682.14598707734683575237.stgit@devnote2> References: <159870601250.1229682.14598707734683575237.stgit@devnote2> MIME-Version: 1.0 Message-ID: <160010378334.15536.3468204530252580556.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/kprobes branch of tip: Commit-ID: d7641289dad95df3531f573112778c548331ab83 Gitweb: https://git.kernel.org/tip/d7641289dad95df3531f573112778c548331ab83 Author: Masami Hiramatsu AuthorDate: Sat, 29 Aug 2020 22:00:12 +09:00 Committer: Ingo Molnar CommitterDate: Tue, 08 Sep 2020 11:52:32 +02:00 x86/kprobes: Use generic kretprobe trampoline handler Use the generic kretprobe trampoline handler. Use regs->sp for framepointer verification. [ mingo: Minor edits. ] Signed-off-by: Masami Hiramatsu Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/159870601250.1229682.14598707734683575237.stgit@devnote2 --- arch/x86/kernel/kprobes/core.c | 108 +-------------------------------- 1 file changed, 3 insertions(+), 105 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index fdadc37..882b953 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -767,124 +767,22 @@ asm( NOKPROBE_SYMBOL(kretprobe_trampoline); STACK_FRAME_NON_STANDARD(kretprobe_trampoline); + /* * Called from kretprobe_trampoline */ __used __visible void *trampoline_handler(struct pt_regs *regs) { - 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 = (unsigned long)&kretprobe_trampoline; - kprobe_opcode_t *correct_ret_addr = NULL; - void *frame_pointer; - bool skipped = false; - - /* - * Set a dummy kprobe for avoiding kretprobe recursion. - * Since kretprobe never run in kprobe handler, kprobe must not - * be running at this point. - */ - kprobe_busy_begin(); - - INIT_HLIST_HEAD(&empty_rp); - kretprobe_hash_lock(current, &head, &flags); /* fixup registers */ regs->cs = __KERNEL_CS; #ifdef CONFIG_X86_32 regs->cs |= get_kernel_rpl(); regs->gs = 0; #endif - /* We use pt_regs->sp for return address holder. */ - frame_pointer = ®s->sp; - regs->ip = trampoline_address; + regs->ip = (unsigned long)&kretprobe_trampoline; regs->orig_ax = ~0UL; - /* - * It is possible to have multiple instances associated with a given - * task either because multiple functions in the call path have - * return probes installed on them, and/or more than one - * return probe was registered for a target function. - * - * We can handle this because: - * - instances are always pushed into the head of the list - * - when multiple return probes are registered for the same - * function, the (chronologically) first instance's ret_addr - * will be the real return address, and all the rest will - * point to kretprobe_trampoline. - */ - hlist_for_each_entry(ri, head, hlist) { - if (ri->task != current) - /* another task is sharing our hash bucket */ - continue; - /* - * Return probes must be pushed on this hash list correct - * order (same as return order) so that it can be popped - * correctly. However, if we find it is pushed it incorrect - * order, this means we find a function which should not be - * probed, because the wrong order entry is pushed on the - * path of processing other kretprobe itself. - */ - if (ri->fp != frame_pointer) { - if (!skipped) - pr_warn("kretprobe is stacked incorrectly. Trying to fixup.\n"); - skipped = true; - continue; - } - - orig_ret_address = (unsigned long)ri->ret_addr; - if (skipped) - pr_warn("%ps must be blacklisted because of incorrect kretprobe order\n", - ri->rp->kp.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; - if (ri->fp != frame_pointer) - continue; - - orig_ret_address = (unsigned long)ri->ret_addr; - if (ri->rp && ri->rp->handler) { - __this_cpu_write(current_kprobe, &ri->rp->kp); - ri->ret_addr = correct_ret_addr; - ri->rp->handler(ri, regs); - __this_cpu_write(current_kprobe, &kprobe_busy); - } - - 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_hash_unlock(current, &flags); - - kprobe_busy_end(); - - hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) { - hlist_del(&ri->hlist); - kfree(ri); - } - return (void *)orig_ret_address; + return (void *)kretprobe_trampoline_handler(regs, &kretprobe_trampoline, ®s->sp); } NOKPROBE_SYMBOL(trampoline_handler);