Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7931877pxb; Fri, 19 Feb 2021 03:10:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBeEGugkcVacQSalXFByPkAcpaoaQBrMW0w33hy4052QSlzskAJksUUcyHrvdjvp9MmUJ0 X-Received: by 2002:a17:906:c010:: with SMTP id e16mr8183025ejz.91.1613733022275; Fri, 19 Feb 2021 03:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613733022; cv=none; d=google.com; s=arc-20160816; b=0tzdi01NvKmrb2L0+KpAIUe52OVBEVJDNO7uNoblawVB77JOdrznRExxwZ8GUSydcH qTHtcI3FB2XSS4SivOcb/nX/MxeqpgRwxI5He484b6Io3hzJZhGlCGiQH1GwIb+jsbot TbfmodnaIWqH/D89Jkz+4uXZSfy2JXm3kswS8Sc2J2jjGbl/SnlqFh5ePyOxmib7GSGK 2GRL6RIzdy0SHqD4w+WucVsLU9zyCXLeLxn2CVuxlw37LYquW6wvNYp0TxVO3hermPUP P4bGUeHoTndTpPBLfMWztmP8hiL3Ds6fuU+33ep4zFTt5t/ijO/trn5GRiSpmz/cJnwW YNCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=x4O4zL31GpoCCYZmwEVEl5maoMIlL8lmfyjKEW/s1Tc=; b=TPZrhJTl8fUIygTAVrQF6O3y342F5HE8SLPYT/GZ/KD/aLOMhzIzJpnbGxe4muKgft M7wq8lqkwxP/9Ljaudppe2SzIT5Xi/n+jHkRB7Bi0PHoCrwiKASLFqvruQRO/Zn+H4Bn O0Mj/2a4zsKq8XK4RNunpjQpgNFC/cPIJgRj943nHx/jOPWoC7w6bVUXZGVOgdi681sy Ugs5zItn+HgVKnKM4Cb9e2XGxeQGm8ygaOjTJYtE/R8P+W3tSwNIg0qbX+qdKsOjemnS q32rtTifmPgqu6Eky8OWh/nR/+ZPfDeEypn4Wy707HY4V6OM0zMwNrv/ljV1e6BmZ6HK ktZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs1si6085014edb.502.2021.02.19.03.09.58; Fri, 19 Feb 2021 03:10:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbhBSLGk (ORCPT + 99 others); Fri, 19 Feb 2021 06:06:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbhBSLGh (ORCPT ); Fri, 19 Feb 2021 06:06:37 -0500 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5589CC061574; Fri, 19 Feb 2021 03:05:57 -0800 (PST) Received: by theia.8bytes.org (Postfix, from userid 1000) id AAE9A295; Fri, 19 Feb 2021 12:05:54 +0100 (CET) Date: Fri, 19 Feb 2021 12:05:49 +0100 From: Joerg Roedel To: Andy Lutomirski Cc: Joerg Roedel , X86 ML , stable , "H. Peter Anvin" , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , Arvind Sankar , LKML , kvm list , Linux Virtualization Subject: Re: [PATCH 2/3] x86/sev-es: Check if regs->sp is trusted before adjusting #VC IST stack Message-ID: <20210219110549.GI7302@8bytes.org> References: <20210217120143.6106-1-joro@8bytes.org> <20210217120143.6106-3-joro@8bytes.org> <20210218112500.GH7302@8bytes.org> <20210218192117.GL12716@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 18, 2021 at 04:28:36PM -0800, Andy Lutomirski wrote: > On Thu, Feb 18, 2021 at 11:21 AM Joerg Roedel wrote: > Can you give me an example, even artificial, in which the linked-list > logic is useful? So here we go, its of course artificial, but still: 1. #VC happens, not important where 2. NMI in the #VC prologue before it moved off its IST stack - first VC IST adjustment happening here 3. #VC in the NMI handler 4. #HV in the #VC prologue again - second VC IST adjustment happening here, so the #HV handler can cause its own #VC exceptions. Can only happen if the #HV handler is allowed to cause #VC exceptions. But even if its not allowed, it can happen with SNP and a malicious Hypervisor. But in this case the only option is to reliably panic. > Can you explain your reasoning in considering the entry stack unsafe? > It's 4k bytes these days. I wasn't aware that it is 4k in size now. I still thought it was just these 64 words large and one can not simply execute C code on it. > You forgot about entry_SYSCALL_compat. Right, thanks for pointing this out. > Your 8-byte alignment is confusing to me. In valid kernel code, SP > should be 8-byte-aligned already, and, if you're trying to match > architectural behavior, the CPU aligns to 16 bytes. Yeah, I was just being cautious. The explicit alignment can be removed, Boris also pointed this out. > We're not robust against #VC, NMI in the #VC prologue before the magic > stack switch, and a new #VC in the NMI prologue. Nor do we appear to > have any detection of the case where #VC nests directly inside its own > prologue. Or did I miss something else here? No, you don't miss anything here. At the moment #VC can't happen at those places, so this is not handled yet. With SNP it can happen and needs to be handled in a way to at least allow a reliable panic (because if it really happens the Hypervisor is messing with us). > If we get NMI and get #VC in the NMI *asm*, the #VC magic stack switch > looks like it will merrily run itself in the NMI special-stack-layout > section, and that sounds really quite bad. Yes, I havn't looked at the details yet, but if a #VC happens there it probably better not returns. > I mean that, IIRC, a malicious hypervisor can inject inappropriate > vectors at inappropriate times if the #HV mechanism isn't enabled. > For example, it could inject a page fault or an interrupt in a context > in which we have the wrong GSBASE loaded. Yes, a malicious Hypervisor can do that, and without #HV there is no real protection against this besides turning all vectors (even IRQs) into paranoid entries. Maybe even more care is needed, but I think its not worth to care about this. > But the #DB issue makes this moot. We have to use IST unless we turn > off SCE. But I admit I'm leaning toward turning off SCE until we have > a solution that seems convincingly robust. Turning off SCE might be tempting, but I guess doing so would break a quite some user-space code, no? Regards, Joerg