From patchwork Tue Dec 27 11:59:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 36839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1354848wrt; Tue, 27 Dec 2022 04:01:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXscRRrkz7qZwfVdU96gI5mXJl/UB8ANy+3o8h/4yS2RoHztBE4Q+RPBaALakuEUkgrrTR/G X-Received: by 2002:a17:907:d407:b0:7ad:f962:dba1 with SMTP id vi7-20020a170907d40700b007adf962dba1mr20658981ejc.53.1672142495266; Tue, 27 Dec 2022 04:01:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672142495; cv=none; d=google.com; s=arc-20160816; b=SbSB3Ivi0I3N+MJ965YxkZsf+/d5dfc9o9xDDAfFbNxdpiaLperYoGp2C19uos3ekd 04uLa0gi4weGABEIagE1F8Vkicf+WEUX7GX6LfSCg+ugDH28KNY6zfBZZF0bAmCK7B7M Wy4qDsXOlQLQehdqHBVnTk0unyqGv/R8TIrh4tBETxwkIj35fKVRYIc8mj8/369ctFrY wE+ackI6EpGAq0HaZEbMoLThN4srAlzM78u3N+hMQyva/lz0Kh2r9vDU8/sO0NDysxwC x94dc2U9DRINCbYwXq1ATy3MZfRzzcptGDyK5qJolRH+6/ERZdK1x7K4KY2yMpiVUShk 2OnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=NcqP92Xi8AJEM26zMaSzANKml99y3YPuVOyvJ6h1uCo=; b=Vhyi7Zhgosu7K98dw/HjvORqhmTJTCxlJvKpiG0GReA+V1uOI8CRQAcbJ0jlzfYNhZ cqqGntEFt7fFtWdoY58RNHQ3O9bSz1OTpxuE0ESN9eHzUikpwOa98u5mvEfQY4X5WNuF m0H41ONQ/kapku9KnYuYEFZIEtlJ59ggzaWRBhDf6MHYJ5hwrwGT22xcfgODq4kXZSEj IxtBeLpIhcaGuBqOnIrUprSLWqdF1mXg9s9ByO8SHl8Bkiul4VMJ6R9ncpYDyNzJLLtJ Q3+qhYfIGi2qrmT/e6tLxfAbhwvU+U4shEO8JpXQh0Aot02xyL5xnh3AmDmYUoeRrHoF TR/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HXlypL+d; dkim=neutral (no key) header.i=@linutronix.de header.b=zIS6TBvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du4-20020a17090772c400b007be53f03fa7si11364854ejc.211.2022.12.27.04.01.10; Tue, 27 Dec 2022 04:01:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HXlypL+d; dkim=neutral (no key) header.i=@linutronix.de header.b=zIS6TBvK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbiL0MA0 (ORCPT + 99 others); Tue, 27 Dec 2022 07:00:26 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752653491815967296?= X-GMAIL-MSGID: =?utf-8?q?1753368489356703696?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 63dc6325ff41ee9e570bde705ac34a39c5dbeb44 Gitweb: https://git.kernel.org/tip/63dc6325ff41ee9e570bde705ac34a39c5dbeb44 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.stgit@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; } -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 != 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 = 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] == INT3_INSN_OPCODE) - return is_padding_int3(addr, paddr - offset + size) ? 1 : 0; - + if (insn.opcode.bytes[0] == INT3_INSN_OPCODE && + kgdb_has_hit_break(addr)) + return 0; +#endif /* Recover address */ insn.kaddr = (void *)addr; insn.next_byte = (void *)(addr + insn.length);