From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6B0CC433E1 for ; Thu, 25 Mar 2021 11:09:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65A7361A25 for ; Thu, 25 Mar 2021 11:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbhCYLJa (ORCPT ); Thu, 25 Mar 2021 07:09:30 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:47070 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbhCYLIt (ORCPT ); Thu, 25 Mar 2021 07:08:49 -0400 Date: Thu, 25 Mar 2021 11:08:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1616670528; 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=MQks5ZUGP7v2tV0VUT7qXT5vWaLsL2oK8QkD6CZ0mo0=; b=VImVqSA31/dsLHk99GjSx1rOOuSkdSxiAgIw2ithVdmu0qtSY4QysNeqDCLkI8N+hA9hEM hKgkQYXM0hYuW4LAo0deoe/dmQFdazPlF7dUgyGdm79GIj5JK8iWFzeCL25zKVO2Cx1uTR 8T3jbeZe/APbqJI05UFy8Aojl2KtW/mOvAAGrT9G7ogac8afUAAEjv4Y896YqqZwvMU+nG u6lbr103d4a76M/e0L4C8JKmyrJt1o/LlD4+HYNpUvhm7A7M5sXWmZz4kYCt5x2PX8dz4Z HgLOaeXBVlz2u/cGPGqdCXHfe/xjmGWJlOW8RXoWWpNCwMjI64WY400t0B2p7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1616670528; 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=MQks5ZUGP7v2tV0VUT7qXT5vWaLsL2oK8QkD6CZ0mo0=; b=qdlo5MHl1DnO0TeMBr61RNF/wlWmU0/fSBi86eoq8bHirJmuYQ5mBZxt/VU9N3ocIIEOh7 p3FKphD1KpuWIDAQ== From: "tip-bot2 for Masami Hiramatsu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/kprobes: Fix to identify indirect jmp and others using range case Cc: Colin Ian King , Masami Hiramatsu , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <161666692308.1120877.4675552834049546493.stgit@devnote2> References: <161666692308.1120877.4675552834049546493.stgit@devnote2> MIME-Version: 1.0 Message-ID: <161667052779.398.5074470038473644947.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/core branch of tip: Commit-ID: 2f706e0e5e263c0d204e37ea496cbb0e98aac2d2 Gitweb: https://git.kernel.org/tip/2f706e0e5e263c0d204e37ea496cbb0e98aac2d2 Author: Masami Hiramatsu AuthorDate: Thu, 25 Mar 2021 19:08:43 +09:00 Committer: Ingo Molnar CommitterDate: Thu, 25 Mar 2021 11:37:22 +01:00 x86/kprobes: Fix to identify indirect jmp and others using range case Fix can_boost() to identify indirect jmp and others using range case correctly. Since the condition in switch statement is opcode & 0xf0, it can not evaluate to 0xff case. This should be under the 0xf0 case. However, there is no reason to use the conbinations of the bit-masked condition and lower bit checking. Use range case to clean up the switch statement too. Fixes: 6256e668b7 ("x86/kprobes: Use int3 instead of debug trap for single-step") Reported-by: Colin Ian King Signed-off-by: Masami Hiramatsu Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/161666692308.1120877.4675552834049546493.stgit@devnote2 --- arch/x86/kernel/kprobes/core.c | 44 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 81e1432..922a6e2 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -164,32 +164,28 @@ int can_boost(struct insn *insn, void *addr) opcode = insn->opcode.bytes[0]; - switch (opcode & 0xf0) { - case 0x60: - /* can't boost "bound" */ - return (opcode != 0x62); - case 0x70: - return 0; /* can't boost conditional jump */ - case 0x90: - return opcode != 0x9a; /* can't boost call far */ - case 0xc0: - /* can't boost software-interruptions */ - return (0xc1 < opcode && opcode < 0xcc) || opcode == 0xcf; - case 0xd0: - /* can boost AA* and XLAT */ - return (opcode == 0xd4 || opcode == 0xd5 || opcode == 0xd7); - case 0xe0: - /* can boost in/out and absolute jmps */ - return ((opcode & 0x04) || opcode == 0xea); - case 0xf0: - /* clear and set flags are boostable */ - return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe)); - case 0xff: - /* indirect jmp is boostable */ + switch (opcode) { + case 0x62: /* bound */ + case 0x70 ... 0x7f: /* Conditional jumps */ + case 0x9a: /* Call far */ + case 0xc0 ... 0xc1: /* Grp2 */ + case 0xcc ... 0xce: /* software exceptions */ + case 0xd0 ... 0xd3: /* Grp2 */ + case 0xd6: /* (UD) */ + case 0xd8 ... 0xdf: /* ESC */ + case 0xe0 ... 0xe3: /* LOOP*, JCXZ */ + case 0xe8 ... 0xe9: /* near Call, JMP */ + case 0xeb: /* Short JMP */ + case 0xf0 ... 0xf4: /* LOCK/REP, HLT */ + case 0xf6 ... 0xf7: /* Grp3 */ + case 0xfe: /* Grp4 */ + /* ... are not boostable */ + return 0; + case 0xff: /* Grp5 */ + /* Only indirect jmp is boostable */ return X86_MODRM_REG(insn->modrm.bytes[0]) == 4; default: - /* call is not boostable */ - return opcode != 0x9a; + return 1; } }