Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3528596pxf; Mon, 15 Mar 2021 11:34:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJwXiaokASKUo2AN5I49c9CH+6qb/u91LhmtXNZtO9iltq2Kg7wFlvVMsNCJIevPnAdJnb X-Received: by 2002:a17:906:3c18:: with SMTP id h24mr24961832ejg.435.1615833254801; Mon, 15 Mar 2021 11:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833254; cv=none; d=google.com; s=arc-20160816; b=xYs7hLw1cum3EAO/TdSLZ8tT94N3cCO+dvs6Pj3YcxncWJkc3j9H3R+YEMaKrR3Z92 dmtR+fCh2NNIpbQQgZHYH+Df+me8vkourmt1WAPtUpdo3mo3+Mjf30sg/quh6gblO7Rr 81CoeupRL0w1kEWkpK9GkYVOPREJeAbCb2WdWxh5p3cDbcA4wUAOw2Fwad8st6IR4mLx vcTwlkvgBDjdThe2Q7nwamlmR9QWvAmjXLwI/eYI1GASRlMY9tJQAyWO+pzwtcHu9pHj qosIJrf9AyXEMmV607lXwhkVbG8z1aYH49wrthjLHSC9cNBPOeTSgYIT4M8jqmYHm1VN 9Pfg== 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=n+TVl2CbCqavsH6FMPWvAn5BHbJmqiD/8UouF2KZqDY=; b=WNdqbZ3M8haYp5s4EPbG9CFfD+GZeNxfKonujk408vewn6HzgUG3Z8/oZAkxFX0OiY 1qBzGANYMEVbVqb/eZUcN9po3NfSsA212gtSedQRUaQYBDQzvF0wD3MoV9rtJePO2MtD yUrQcR0GJBg8fr7eksNtS3UP58h+m4QOyXfzy3VMpOeGb2ZugV9QrkQxbLn4yPwHJLnU gjaPZC8ZDzPySq4Hg8uggxkl7OMnKT2ynWGUxqr0v478zSvN5Lluzb/eMMQJgzlize2w Q+7UaLFYFbDJtubZaSrTWDlxMT+zNvXObEwepjOdd0EIqgXMU8OANJlHBqGuymKVtKpI TiIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bTFx5AvJ; 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 j10si12123823ejs.556.2021.03.15.11.33.52; Mon, 15 Mar 2021 11:34:14 -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=bTFx5AvJ; 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 S239128AbhCOOp6 (ORCPT + 99 others); Mon, 15 Mar 2021 10:45:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:52488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234595AbhCOOE1 (ORCPT ); Mon, 15 Mar 2021 10:04:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A7C4664EF1; Mon, 15 Mar 2021 14:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817066; bh=oqEf25nvMNpzF7bOgfDJbXuzXtb2BZEjztG/ZKz2/Tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bTFx5AvJbhpOksRNqBurA/UNIpwEPuHgVGQq80kmInzRLCdaw0kyB4Mv5LKK4oJmB Aw5wYZs1Ov0aYGWoyp+cEE0il8+aSL/lIBfT8m9vLMPYQKV+EXqXreVD1LKJuGuiSU 0x/OHrzClxbSykxQYpaiKolcGjN3dASsAd+5VS4c= 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.10 271/290] x86/sev-es: Check regs->sp is trusted before adjusting #VC IST stack Date: Mon, 15 Mar 2021 14:56:04 +0100 Message-Id: <20210315135551.180280688@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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(-) diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c index 84c1821819af..301f20f6d4dd 100644 --- 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 cpu) 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 pt_regs *regs) 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); -- 2.30.2