Received: by 10.223.176.46 with SMTP id f43csp2653737wra; Mon, 22 Jan 2018 00:58:40 -0800 (PST) X-Google-Smtp-Source: AH8x224ANrTp5GArS8ljyCK4agUdiDF8QbtQFoQsLMHnaTikiNz1ZfQ7OnrVrcB5uzTHzqFiVGAr X-Received: by 10.98.242.77 with SMTP id y13mr7739841pfl.156.1516611520048; Mon, 22 Jan 2018 00:58:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516611520; cv=none; d=google.com; s=arc-20160816; b=B62u1hRS41umg+gbKzm0/ep2ZfMmamptKiMhSmVBMFOV6ob5SJ5lOVd/mHkXM7Ylok zgWCF9bO3XgPDD36Ej6SadtR9xVwJ6qAh4IyRiRdMgD5zkZnvqnJEAIeQu6IxUFokl5m Lxd2JuYAfVIdGHMOMe8B1WEGYN+6qW83Ljx1ksGytjEPN/Jr+s2Hur3OGTUhkBfu3woa kjfGS1vFXYuiEF4h2tw3cwJsZcAgNZlRLJ0adhSym/ONVSU4cMpcX1AWMkQ/gaaTWH25 jHLZ4uLRiLBnzKCuEWR0Y0kpNl1vxKXIzVFZy7Bq+2QR5sKUq4OivKl97JjMXt/3hbsz HzQw== 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=THhfoziyNtETbELPv+BZrKtbVqVBtUQFx7+f9YvW6Fo=; b=e5PG+DGcIwAGCkyAYKWnhmedftImiKxBMplz9vBrXckG5uG2k3vGo+wsW1hIucTDZf 4Uy1fsWFl1q9W8z2QtHixDnaUYyegKwcgnNRfyY7rp5bA/scfSEgFnSRYui0ps29b9fs VmmPkb2+yZTfUMk+abYfpxai/5lpKbrC7BoBdHg62pqTAd5+7FFB+NDNkXCdDcC/8Zh3 f6PH0/uyGbxed/2nQHcPtfhqhBmykAmC9r99tdWLUeVt25VwOgckx4WXzwJ2iRGsgQIF KfnrZhROwgtWvgTasN7sUCzx0VrYO+DNtzZHQ7W0yM5ah2uUm/yTSqEQUEbC6oqgL3fh cOPg== 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 g21si13871533pgn.58.2018.01.22.00.58.26; Mon, 22 Jan 2018 00:58:40 -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 S1753667AbeAVI53 (ORCPT + 99 others); Mon, 22 Jan 2018 03:57:29 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34250 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932144AbeAVIyX (ORCPT ); Mon, 22 Jan 2018 03:54:23 -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 147A3F00; Mon, 22 Jan 2018 08:54:23 +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.14 84/89] kprobes/x86: Disable optimizing on the function jumps to indirect thunk Date: Mon, 22 Jan 2018 09:46:04 +0100 Message-Id: <20180122084002.911688066@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083954.683903493@linuxfoundation.org> References: <20180122083954.683903493@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.14-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 @@ -40,6 +40,7 @@ #include #include #include +#include #include "common.h" @@ -205,7 +206,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 */ @@ -239,6 +240,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) {