From nobody Wed Sep 17 01:18:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E438C46467 for ; Tue, 27 Dec 2022 12:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231951AbiL0MA1 (ORCPT ); Tue, 27 Dec 2022 07:00:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232098AbiL0L73 (ORCPT ); Tue, 27 Dec 2022 06:59:29 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF98BB876; Tue, 27 Dec 2022 03:59:17 -0800 (PST) Date: Tue, 27 Dec 2022 11:59:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672142356; 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=NcqP92Xi8AJEM26zMaSzANKml99y3YPuVOyvJ6h1uCo=; b=HXlypL+dSMqfH4bIUIsnMe7cCzVzBLkGLvOVWhu8jz/J2cx2oGvHItWqp9qDlQCTtKy5de uTwSNxOGA4joJDakhYwrC0m4yVy2e3e5R0DTjSMvmLyIC17ZWFEk/spT7hfr19v0nape/9 sha7IKKo2LwckHqqJaUQQk/1AKCbObBsSB+XvwA6rVFQI0+Q2JlkNyPfyZ/s2Y/f0d/Rwm WpMLQLRhYRbDt7/yUw9WUbeudA5ImstYQhOLn832ShvX96R0Mv6Aufj9wUOEKl+0Uf0lHh OBiF4hrQxdhNl0FSxjRAjVMXnJrWqVBADR6TLu6IWybeqiZ0B8a/KrdzbbtXNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672142356; 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=NcqP92Xi8AJEM26zMaSzANKml99y3YPuVOyvJ6h1uCo=; b=zIS6TBvK7bxy5/TXbCqlMhd/a0Yb9fIs3VzPl8Zp9TcB1boDm5D5Az/+QI5cneEwpnkmU1 fDN4CbI65y8RsDAA== From: "tip-bot2 for Masami Hiramatsu (Google)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK Cc: Peter Zijlstra , "Masami Hiramatsu (Google)" , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <167146051929.1374301.7419382929328081706.stgit@devnote3> References: <167146051929.1374301.7419382929328081706.stgit@devnote3> MIME-Version: 1.0 Message-ID: <167214235589.4906.14264782682251794595.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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 63dc6325ff41ee9e570bde705ac34a39c5dbeb44 Gitweb: https://git.kernel.org/tip/63dc6325ff41ee9e570bde705ac34a39c= 5dbeb44 Author: Masami Hiramatsu (Google) AuthorDate: Mon, 19 Dec 2022 23:35:19 +09:00 Committer: Peter Zijlstra CommitterDate: Tue, 27 Dec 2022 12:51:58 +01:00 x86/kprobes: Fix optprobe optimization check with CONFIG_RETHUNK Since the CONFIG_RETHUNK and CONFIG_SLS will use INT3 for stopping speculative execution after function return, kprobe jump optimization always fails on the functions with such INT3 inside the function body. (It already checks the INT3 padding between functions, but not inside the function) To avoid this issue, as same as kprobes, check whether the INT3 comes from kgdb or not, and if so, stop decoding and make it fail. The other INT3 will come from CONFIG_RETHUNK/CONFIG_SLS and those can be treated as a one-byte instruction. Fixes: e463a09af2f0 ("x86: Add straight-line-speculation mitigation") Suggested-by: Peter Zijlstra Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/167146051929.1374301.7419382929328081706.st= git@devnote3 --- arch/x86/kernel/kprobes/opt.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index e6b8c53..e57e07b 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -279,19 +280,6 @@ static int insn_is_indirect_jump(struct insn *insn) return ret; } =20 -static bool is_padding_int3(unsigned long addr, unsigned long eaddr) -{ - unsigned char ops; - - for (; addr < eaddr; addr++) { - if (get_kernel_nofault(ops, (void *)addr) < 0 || - ops !=3D INT3_INSN_OPCODE) - return false; - } - - return true; -} - /* Decode whole function to ensure any instructions don't jump into target= */ static int can_optimize(unsigned long paddr) { @@ -334,15 +322,15 @@ static int can_optimize(unsigned long paddr) ret =3D insn_decode_kernel(&insn, (void *)recovered_insn); if (ret < 0) return 0; - +#ifdef CONFIG_KGDB /* - * In the case of detecting unknown breakpoint, this could be - * a padding INT3 between functions. Let's check that all the - * rest of the bytes are also INT3. + * If there is a dynamically installed kgdb sw breakpoint, + * this function should not be probed. */ - if (insn.opcode.bytes[0] =3D=3D INT3_INSN_OPCODE) - return is_padding_int3(addr, paddr - offset + size) ? 1 : 0; - + if (insn.opcode.bytes[0] =3D=3D INT3_INSN_OPCODE && + kgdb_has_hit_break(addr)) + return 0; +#endif /* Recover address */ insn.kaddr =3D (void *)addr; insn.next_byte =3D (void *)(addr + insn.length);