From patchwork Tue May 10 13:30:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Heyne X-Patchwork-Id: 12845061 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45F3FC433F5 for ; Tue, 10 May 2022 13:32:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.325640.548316 (Exim 4.92) (envelope-from ) id 1noPyV-0001Cq-1G; Tue, 10 May 2022 13:32:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 325640.548316; Tue, 10 May 2022 13:32:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noPyU-0001Cj-UG; Tue, 10 May 2022 13:32:26 +0000 Received: by outflank-mailman (input) for mailman id 325640; Tue, 10 May 2022 13:32:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1noPyT-0007QY-Rf for xen-devel@lists.xenproject.org; Tue, 10 May 2022 13:32:25 +0000 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9f69fde0-d065-11ec-a406-831a346695d4; Tue, 10 May 2022 15:32:24 +0200 (CEST) Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1a-b27d4a00.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP; 10 May 2022 13:31:25 +0000 Received: from EX13D08EUB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1a-b27d4a00.us-east-1.amazon.com (Postfix) with ESMTPS id 236BC81236; Tue, 10 May 2022 13:31:15 +0000 (UTC) Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D08EUB001.ant.amazon.com (10.43.166.236) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 10 May 2022 13:31:14 +0000 Received: from dev-dsk-mheyne-1b-c1524648.eu-west-1.amazon.com (10.15.60.66) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.32 via Frontend Transport; Tue, 10 May 2022 13:31:14 +0000 Received: by dev-dsk-mheyne-1b-c1524648.eu-west-1.amazon.com (Postfix, from userid 5466572) id E83F641131; Tue, 10 May 2022 13:31:13 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Inumbo-ID: 9f69fde0-d065-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1652189544; x=1683725544; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fXdsCza0w8qNDoFrKMYkMnUAwI+hskYjRxqBpTNbyyY=; b=Q+en0i+uN9Ewn4HE01M9eacVUESE3pgE5cwho5e5IWi62pH9e/u5Mfja mrtT5oOq4z60NqPkk4psDxexwiumYpTdv3Q9NxgWVMHg7CZaRXT9ahmi2 UzXFeQN7WKSztv61XndBk4+G7gNYfKdXjfnDq3kKJHc2KsvBj/7XbCnQb g=; X-IronPort-AV: E=Sophos;i="5.91,214,1647302400"; d="scan'208";a="87035422" From: Maximilian Heyne To: CC: Masami Hiramatsu , Peter Zijlstra , Juergen Gross , , Boris Ostrovsky , Ingo Molnar , Stefano Stabellini , Andrew Cooper , Borislav Petkov , , Randy Dunlap , Josh Poimboeuf , Maximilian Heyne , , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Sasha Levin , , Subject: [PATCH 4/4] x86: kprobes: Prohibit probing on instruction which has emulate prefix Date: Tue, 10 May 2022 13:30:33 +0000 Message-ID: <20220510133036.46767-5-mheyne@amazon.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220510133036.46767-1-mheyne@amazon.de> References: <20220510133036.46767-1-mheyne@amazon.de> MIME-Version: 1.0 Precedence: Bulk From: Masami Hiramatsu commit 004e8dce9c5595697951f7cd0e9f66b35c92265e upstream Prohibit probing on instruction which has XEN_EMULATE_PREFIX or KVM's emulate prefix. Since that prefix is a marker for Xen and KVM, if we modify the marker by kprobe's int3, that doesn't work as expected. Signed-off-by: Masami Hiramatsu Signed-off-by: Peter Zijlstra (Intel) Cc: Juergen Gross Cc: x86@kernel.org Cc: Boris Ostrovsky Cc: Ingo Molnar Cc: Stefano Stabellini Cc: Andrew Cooper Cc: Borislav Petkov Cc: xen-devel@lists.xenproject.org Cc: Randy Dunlap Cc: Josh Poimboeuf Link: https://lkml.kernel.org/r/156777566048.25081.6296162369492175325.stgit@devnote2 Signed-off-by: Maximilian Heyne Cc: stable@vger.kernel.org # 5.4.x --- arch/x86/kernel/kprobes/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index c205d77d57da..3700dc94847c 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -358,6 +358,10 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn) kernel_insn_init(insn, dest, MAX_INSN_SIZE); insn_get_length(insn); + /* We can not probe force emulate prefixed instruction */ + if (insn_has_emulate_prefix(insn)) + return 0; + /* Another subsystem puts a breakpoint, failed to recover */ if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION) return 0;