From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from theia.8bytes.org (8bytes.org [81.169.241.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CC0A72 for ; Wed, 19 May 2021 13:16:41 +0000 (UTC) Received: by theia.8bytes.org (Postfix, from userid 1000) id 63C252FA; Wed, 19 May 2021 15:16:39 +0200 (CEST) Date: Wed, 19 May 2021 15:16:38 +0200 From: Joerg Roedel To: Sean Christopherson Cc: x86@kernel.org, Hyunwook Baek , Joerg Roedel , stable@vger.kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH 2/6] x86/sev-es: Forward page-faults which happen during emulation Message-ID: References: <20210512075445.18935-1-joro@8bytes.org> <20210512075445.18935-3-joro@8bytes.org> X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Hi Sean, On Wed, May 12, 2021 at 05:31:03PM +0000, Sean Christopherson wrote: > This got me looking at the flows that "inject" #PF, and I'm pretty sure there > are bugs in __vc_decode_user_insn() + insn_get_effective_ip(). > > Problem #1: __vc_decode_user_insn() assumes a #PF if insn_fetch_from_user_inatomic() > fails, but the majority of failure cases in insn_get_seg_base() are #GPs, not #PF. > > res = insn_fetch_from_user_inatomic(ctxt->regs, buffer); > if (!res) { > ctxt->fi.vector = X86_TRAP_PF; > ctxt->fi.error_code = X86_PF_INSTR | X86_PF_USER; > ctxt->fi.cr2 = ctxt->regs->ip; > return ES_EXCEPTION; > } > > Problem #2: Using '0' as an error code means a legitimate effective IP of '0' > will be misinterpreted as a failure. Practically speaking, I highly doubt anyone > will ever actually run code at address 0, but it's technically possible. The > most robust approach would be to pass a pointer to @ip and return an actual error > code. Using a non-canonical magic value might also work, but that could run afoul > of future shenanigans like LAM. > > ip = insn_get_effective_ip(regs); > if (!ip) > return 0; Your observations are all correct. I put some changes onto this patch-set to fix these problems. Regards, Joerg