Received: by 10.223.176.46 with SMTP id f43csp2647399wra; Mon, 22 Jan 2018 00:50:02 -0800 (PST) X-Google-Smtp-Source: AH8x225ZCL4m1dv4b3P+4j/KQnswPvgLKUG6Z1GVk9VQzwLCi7w0E5NVxjOqnyhAksqbKv3Tqn/c X-Received: by 10.101.96.6 with SMTP id m6mr7045171pgu.131.1516611002212; Mon, 22 Jan 2018 00:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516611002; cv=none; d=google.com; s=arc-20160816; b=cAz6mjJ1LRgUnovnBnPVNR5c+51kdjZHJnXAOMHt/o3EZw3MeweGp3aBPXHMMksqHo Wq57DGoIuW6OLr3mNEyiRy1LARqHPD8rRgABTeo7ZPMynOFxMZ1gjlbxls4+zZNGx1Ld j7U8R0dFdGCs0xh0Lxp3Ojxu07TwVPEKoeDeR7NoGzxTd3NJg2yryKt5szo+9lMMCkc3 BH2Tas4ZMQ6xWA5niS0t0H3ycBh6R/2fD6xqYXWFEWyyGGO/0vW2ttsDAPK8/8AXwThw SqNoW/FHWCEx+/afavUKitoFOMISkIH9WLvzJuH8t5/E8V2Md1kgtzT4i+tszPARiP1K uNvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=d2xkXxgj56nync48gC3rg/oyTs223WQvjbRgBpIO1Wc=; b=CqR7osrwRQdp4K4gDbyAXGhYAfS1IzPBVtFKLkp2sPl0CXzEHVRHALbi/8VHxOdu9U A4XQe1kZnuRExVy5QgRC0+S3CuxjWJeVldivecMgZBjzeCGsK8h5hIXOGg+3hSi2xW1m KJ0UHHGfaeptjucnoTKJDsFKlobXuUUhKW8hIdTkvi+voAy9RGUUWsfRJaTA82i5VIDn Ww96+wTQe5jtEDQTppiO1KxpK0pII8WbA7vzJWT/83hFMtYRR3JRsboSjfA4dlgtj65/ Tl/DSCzq0gEuuPC+m/wTEWxpTR2Ex+1LhTeOxNMIbHcAN1V6fP2JzfezJDb2zUIwQPjq lSXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si13936250pga.371.2018.01.22.00.49.48; Mon, 22 Jan 2018 00:50:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539AbeAVIt2 (ORCPT + 99 others); Mon, 22 Jan 2018 03:49:28 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:60700 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752494AbeAVItZ (ORCPT ); Mon, 22 Jan 2018 03:49:25 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A4E9EE9A; Mon, 22 Jan 2018 08:49:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , Thomas Gleixner , David Woodhouse , Andi Kleen , Peter Zijlstra , Ananth N Mavinakayanahalli , Arjan van de Ven , Greg Kroah-Hartman Subject: [PATCH 4.9 45/47] kprobes/x86: Disable optimizing on the function jumps to indirect thunk Date: Mon, 22 Jan 2018 09:45:56 +0100 Message-Id: <20180122083928.981757729@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083925.568134913@linuxfoundation.org> References: <20180122083925.568134913@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu commit c86a32c09f8ced67971a2310e3b0dda4d1749007 upstream. Since indirect jump instructions will be replaced by jump to __x86_indirect_thunk_*, those jmp instruction must be treated as an indirect jump. Since optprobe prohibits to optimize probes in the function which uses an indirect jump, it also needs to find out the function which jump to __x86_indirect_thunk_* and disable optimization. Add a check that the jump target address is between the __indirect_thunk_start/end when optimizing kprobe. Signed-off-by: Masami Hiramatsu Signed-off-by: Thomas Gleixner Acked-by: David Woodhouse Cc: Andi Kleen Cc: Peter Zijlstra Cc: Ananth N Mavinakayanahalli Cc: Arjan van de Ven Cc: Greg Kroah-Hartman Link: https://lkml.kernel.org/r/151629212062.10241.6991266100233002273.stgit@devbox Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/kprobes/opt.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "common.h" @@ -192,7 +193,7 @@ static int copy_optimized_instructions(u } /* Check whether insn is indirect jump */ -static int insn_is_indirect_jump(struct insn *insn) +static int __insn_is_indirect_jump(struct insn *insn) { return ((insn->opcode.bytes[0] == 0xff && (X86_MODRM_REG(insn->modrm.value) & 6) == 4) || /* Jump */ @@ -226,6 +227,26 @@ static int insn_jump_into_range(struct i return (start <= target && target <= start + len); } +static int insn_is_indirect_jump(struct insn *insn) +{ + int ret = __insn_is_indirect_jump(insn); + +#ifdef CONFIG_RETPOLINE + /* + * Jump to x86_indirect_thunk_* is treated as an indirect jump. + * Note that even with CONFIG_RETPOLINE=y, the kernel compiled with + * older gcc may use indirect jump. So we add this check instead of + * replace indirect-jump check. + */ + if (!ret) + ret = insn_jump_into_range(insn, + (unsigned long)__indirect_thunk_start, + (unsigned long)__indirect_thunk_end - + (unsigned long)__indirect_thunk_start); +#endif + return ret; +} + /* Decode whole function to ensure any instructions don't jump into target */ static int can_optimize(unsigned long paddr) {