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 89B77C369AB for ; Wed, 16 Apr 2025 00:08:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.954660.1348710 (Exim 4.92) (envelope-from ) id 1u4qKY-0005S3-FA; Wed, 16 Apr 2025 00:08:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 954660.1348710; Wed, 16 Apr 2025 00:08:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u4qKY-0005Rw-C2; Wed, 16 Apr 2025 00:08:42 +0000 Received: by outflank-mailman (input) for mailman id 954660; Tue, 15 Apr 2025 21:52:19 +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 1u4oCW-0000LC-RL for xen-devel@lists.xenproject.org; Tue, 15 Apr 2025 21:52:19 +0000 Received: from postout2.mail.lrz.de (postout2.mail.lrz.de [129.187.255.138]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e324bace-1a43-11f0-9eae-5ba50f476ded; Tue, 15 Apr 2025 23:52:13 +0200 (CEST) Received: from lxmhs52.srv.lrz.de (localhost [127.0.0.1]) by postout2.mail.lrz.de (Postfix) with ESMTP id 4ZcdDD2ymnzyWC for ; Tue, 15 Apr 2025 23:52:12 +0200 (CEST) Received: from postout2.mail.lrz.de ([127.0.0.1]) by lxmhs52.srv.lrz.de (lxmhs52.srv.lrz.de [127.0.0.1]) (amavis, port 20024) with LMTP id Cwlj-3_X8RcF for ; Tue, 15 Apr 2025 23:52:11 +0200 (CEST) Received: from [192.168.0.140] (unknown [46.128.11.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by postout2.mail.lrz.de (Postfix) with ESMTPSA id 4ZcdDC1cJnzyW9 for ; Tue, 15 Apr 2025 23:52:11 +0200 (CEST) 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 Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e324bace-1a43-11f0-9eae-5ba50f476ded Authentication-Results: postout.lrz.de (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=tum.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tum.de; h= subject:subject:from:from:content-language:user-agent :mime-version:date:date:message-id:content-type:content-type :received:received; s=tu-postout21; t=1744753931; bh=zQeDeQ0W1y6 wYnTX8FySKIhUdQH5ebIhmhLL6OmhJbc=; b=kXdmglTuGtQC0ujNlD+H410WduV xE0aeLVuUG6oUPJa7kYUfaVZDa5pp0kQnseDQTDAbd6U+FAfL/U4RLjQfBhd9QLZ o+zjur5zgQYKpip3DmsZ8OGEpl+oe4C96qRXY/ei7SXVHD1g+w4tD0JPv2UaHGGy 8vM/wLIKerOoVFHKazA8DD8bUitSPPKOOvCM4b3sFhJ3wm+oQhIn3toBESs1Ceng pxL16Zc5ivxOfHBVsJWflH+jXFbZJe0a7CjWmwKvRByXrdGN/untMVD8+uDm7R3F 4bLV9UmFhRZPnfpqZoXX2xe/5nCgVPLfFyRg6vTKUw0VYCrAPYunxxjWlOw== X-Virus-Scanned: by amavisd-new at lrz.de in lxmhs52.srv.lrz.de Content-Type: multipart/mixed; boundary="------------YdYylOs7HoDWEUUYS4zhUrGa" Message-ID: Date: Tue, 15 Apr 2025 23:52:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: xen-devel@lists.xenproject.org From: Manuel Andreas Subject: Assert in x86_emulate_wrapper triggerable by HVM domain Autocrypt: addr=manuel.andreas@tum.de; keydata= xjMEY9Zx/RYJKwYBBAHaRw8BAQdALWzRzW9a74DX4l6i8VzXGvv72Vz0qfvj9s7bjBD905nN Jk1hbnVlbCBBbmRyZWFzIDxtYW51ZWwuYW5kcmVhc0B0dW0uZGU+wokEExYIADEWIQQuSfNX 11QV6exAUmOqZGwY4LuingUCY9Zx/QIbAwQLCQgHBRUICQoLBRYCAwEAAAoJEKpkbBjgu6Ke McQBAPyP530S365I50I5rM2XjH5Hr9YcUQATD5dusZJMDgejAP9T/wUurwQSuRfm1rK8cNcf w4wP3+PLvL+J+kuVku93CM44BGPWcf0SCisGAQQBl1UBBQEBB0AmCAf31tLBD5tvtdZ0XX1B yGLUAxhgmFskGyPhY8wOKQMBCAfCeAQYFggAIBYhBC5J81fXVBXp7EBSY6pkbBjgu6KeBQJj 1nH9AhsMAAoJEKpkbBjgu6Kej6YA/RvJdXMjsD5csifolLw53KX0/ElM22SvaGym1+KiiVND AQDy+y+bCXI+J713/AwLBsDxTEXmP7Cp49ZqbAu83NnpBQ== This is a multi-part message in MIME format. --------------YdYylOs7HoDWEUUYS4zhUrGa Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Dear all, my fuzzing infrastructure discovered that an assert in x86_emulate_wrapper is able to be triggered by an HVM domain executing a specially crafted repeating movs instruction. Specifically, if the emulation of the rep movs instruction triggers an exception (e.g. by accessing invalid memory after some amount of iterations), the emulation will be halted at that point. However, the instruction manual requires that _some_ register state (namely the updated value of rcx) shall be commited, whereas the instruction pointer needs to be rolled back to point to the address of the instruction itself. The assert checks for the latter. Problematic is the fact that for these type of repeating instructions, Xen seems to eventually just commit all register state when it encounters an exception:    557  #define put_rep_prefix(reps_completed) ({                               \    558      if ( rep_prefix() )                                                 \    559 { \    560          __put_rep_prefix(&_regs, ctxt->regs, ad_bytes, reps_completed); \    561          if ( unlikely(rc == X86EMUL_EXCEPTION) )                        \    562              goto complete_insn;                                         \    563 } \    564  })   8356   complete_insn: /* Commit shadow register state. */   8357      put_fpu(fpu_type, false, state, ctxt, ops);   8358      fpu_type = X86EMUL_FPU_none;   8359   8360      /* Zero the upper 32 bits of %rip if not in 64-bit mode. */   8361      if ( !mode_64bit() )   8362          _regs.r(ip) = (uint32_t)_regs.r(ip);   8363   8364      /* Should a singlestep #DB be raised? */   8365      if ( rc == X86EMUL_OKAY && singlestep && !ctxt->retire.mov_ss )   8366      {   8367          ctxt->retire.singlestep = true;   8368          ctxt->retire.sti = false;   8369      }   8370   8371      if ( rc != X86EMUL_DONE )   8372          *ctxt->regs = _regs; // <- Incorrect RIP is commited I've attached an XTF test that should trigger the aforementioned assert on the latest release commit: 3ad5d648cda5add395f49fc3704b2552aae734f7 Best, Manuel --------------YdYylOs7HoDWEUUYS4zhUrGa Content-Type: application/gzip; name="poc-x86emul-assert-orig-ip.tar.gz" Content-Disposition: attachment; filename="poc-x86emul-assert-orig-ip.tar.gz" Content-Transfer-Encoding: base64 H4sIAAAAAAAAA+2WXU/bMBSGe+1f4WVUallDkzZJURnTGFS74UOiZdLEEEpttzUkdha7pWja f5/ttBobtN1EBUL4ufHXax/Hx+fEGUfudDsi6ThxYyFILl2e06FLs3ppXXiKVhjq0m+F3t1y TskPwlYz8luNICp5fqjGSzBc2w6WMBYyziEsCXk7FUt0q8ZfKNli/6cxZVtoDTa0g6MgWOR/ P1TO9oNWFDXDVqOh/R811ZWA3hpsr+SV+7++uQngJvw4oAmBkggp6iuvhJmQk4HRu4vlSmek WTwkq7Rw9TKSYw4POBJwwPN/tS3I/3xWHbylDCVjTOD7qRxsjT4AgDgTEqJRXNi8lFQm5PwC 7kKnp9pLNu7sADDhFBfztJGKblbBDwAVWU6ZvK44XXUBJWVDOM5gsQDUC1yqQ9ET33xjTlWt pKfEIoUTnsRSe6sCTZ/GSfkEbnhT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