Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3530080pxf; Mon, 15 Mar 2021 11:36:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhlsIX5CLQgI2vK8LA+W0ZuywRZumGfGtraiD/GXBtWCwcediWywV7QHXZcKO4qOjF3jE3 X-Received: by 2002:a17:907:3e92:: with SMTP id hs18mr24664045ejc.396.1615833378053; Mon, 15 Mar 2021 11:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833378; cv=none; d=google.com; s=arc-20160816; b=YxeocZIxPknyhZSEP8vVJwKrksJEHZqRhzckmCRfuliclsSQXkWN+7brguv+2Hscji /jMnra7TgUiCnnRfrIUG9EadDpx3vWSfC+ydXCdMwwquXA0oM+Euw+yE0H9OKrsa+gDe UUcx78vySYEtqUbAROj3GJoLEqhs29wwyNmAYZd/WyEHEgrDYiqszAi3Jb0obWzUfFtE GRxSiDhvniNP7IhMpom/p5Cs5PRE8udDrUZ2A0p3Pmx02DsmSLLZYgwRnBuJdNOgtZ/w R6swSnp4JACwbB4PAsuTmWghMoR9q+jCXmZqXoUpJ+UBIzI8xBy9MQ4erM/8CeZST1rj YSuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8dQ2lTlVjCwI+E+fHlxWdMGXOvMGmpc0zg1mUDhwMKk=; b=YLpwqYOhXQIjGmEoRUgJl8AFTQ48jRPZ9q68UsHwyiG/D/LkDBUs+pYoFAvE7LEzrf HqQ8vsaiq95zcQEdDqfec1h4RyOmfEjw1NTDucTZ2v3ff9n/es6sTvEOhqD3VCVFFLFV 21kXgR/86mmPf0JaD8Tl/aecsSn5HXhD3bhrn8keKvcESktQsU4LUsRSVcoXQaywLh+1 TIxh/9RIVX6pAQMZiJe1nLbaJtqP35gHmwYvkeAkCWIiMtSrqf3pcFQE/N120GKZYKWq cqbqvUFaO4IYzfo2PeeQCu5nH4d3PE1yY+PkzdSYlMLNi/qPWMY9aS1ZzbXvdcYCEAlT kfng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DU+bPJSq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb41si11240766ejc.90.2021.03.15.11.35.55; Mon, 15 Mar 2021 11:36:18 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DU+bPJSq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239395AbhCOOqt (ORCPT + 99 others); Mon, 15 Mar 2021 10:46:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:52972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234635AbhCOOEi (ORCPT ); Mon, 15 Mar 2021 10:04:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EF2A264EE3; Mon, 15 Mar 2021 14:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817077; bh=5gBcwOLFuIb3qSYWTghwAo8YrGPi2BXQ9tvkKU8XT9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DU+bPJSq7pOGn4qf8F/v1/hbJ74JmhMQvdFv6VfjcZvC7rLFuRtXCn751UfZqKl0Y bS1vo03UWNZ9I2QvEhappP+hVtUOu8r2zp/fN7sF/ZtFl23Fzdmso7OV8RslHPVzMW uboOonBKQVzGMlskzg1FGSqtyxIvaMsgKHD+Lsgc= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Joerg Roedel , Borislav Petkov Subject: [PATCH 5.11 288/306] x86/sev-es: Check regs->sp is trusted before adjusting #VC IST stack Date: Mon, 15 Mar 2021 14:55:51 +0100 Message-Id: <20210315135517.422810187@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Joerg Roedel commit 545ac14c16b5dbd909d5a90ddf5b5a629a40fa94 upstream. The code in the NMI handler to adjust the #VC handler IST stack is needed in case an NMI hits when the #VC handler is still using its IST stack. But the check for this condition also needs to look if the regs->sp value is trusted, meaning it was not set by user-space. Extend the check to not use regs->sp when the NMI interrupted user-space code or the SYSCALL gap. Fixes: 315562c9af3d5 ("x86/sev-es: Adjust #VC IST Stack on entering NMI handler") Reported-by: Andy Lutomirski Signed-off-by: Joerg Roedel Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org # 5.10+ Link: https://lkml.kernel.org/r/20210303141716.29223-3-joro@8bytes.org Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/sev-es.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/sev-es.c +++ b/arch/x86/kernel/sev-es.c @@ -121,8 +121,18 @@ static void __init setup_vc_stacks(int c cea_set_pte((void *)vaddr, pa, PAGE_KERNEL); } -static __always_inline bool on_vc_stack(unsigned long sp) +static __always_inline bool on_vc_stack(struct pt_regs *regs) { + unsigned long sp = regs->sp; + + /* User-mode RSP is not trusted */ + if (user_mode(regs)) + return false; + + /* SYSCALL gap still has user-mode RSP */ + if (ip_within_syscall_gap(regs)) + return false; + return ((sp >= __this_cpu_ist_bottom_va(VC)) && (sp < __this_cpu_ist_top_va(VC))); } @@ -144,7 +154,7 @@ void noinstr __sev_es_ist_enter(struct p old_ist = __this_cpu_read(cpu_tss_rw.x86_tss.ist[IST_INDEX_VC]); /* Make room on the IST stack */ - if (on_vc_stack(regs->sp)) + if (on_vc_stack(regs)) new_ist = ALIGN_DOWN(regs->sp, 8) - sizeof(old_ist); else new_ist = old_ist - sizeof(old_ist);