Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2390403pxf; Sat, 3 Apr 2021 23:34:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2SidyGmdvmwRgPAMPK+1MxLt/FfpYJb9GSCI1/VnHFvWmRY34KIe5gbrA/bUr8IbS8f04 X-Received: by 2002:aa7:ca04:: with SMTP id y4mr24411455eds.339.1617518072726; Sat, 03 Apr 2021 23:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617518072; cv=none; d=google.com; s=arc-20160816; b=arMpX5FPGzx44JwUULUkxcjbWj2SNcdKKb7OabKcZqjnTenhwA7NPR6zpOJpzH/X6E 4N1TNb50Xaam+0ZLrP8TYR01rLtMFluD21jxroatf3JyBPaEc0x0dbkklG6iBrUZhcTb vRaXbzaikSvoUYcG3Pb26DeD2j6dpJsPQyqJVWJ5kLqwA9o5PEwy07v6taJZJX12QL8V IiqoDvc3CKzyYhSr8SPR3bTOLxwwC3DF97M1VhXyiOAkMsj1xQPS9BDokGrOhR27XTes zQyeqbjQpvGHvWMARaRAO8+qiSgZxLhGX3HMF2exEzqcbU4XqBUi0uhSfNjVhVWwmjVF Kt8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=/vlISrpUa7qDE9a0ktIq30uGnTb4tEEz0fOPH+GfCmA=; b=lxus0uiRVZyQzU8TbP88ahp5OfY8scTR83FY7tYlCoLdsbc9EkdVo4BCSkaPgefsxk aFgCX1SRB2PcPXZ6yJntCvtugIFzhB54mlmlYbC9eF7uHKKCGlzXJndboHNfxv4dUxRm jjMyqSjzhU+TlfKCgShOzymoOHNDDQbb14RRUCWWb80KE2dVw14ReDJb3VK6yetTWPAi OGZeZnZk+8qBHbb9HkeAD6eV86+mOq84fmrzu7AyB8L5RQZC2/kYMUjULEMoN4nqxCUv LYb4sAdrLzx/8IWotdpo+gIACE2HvkBwCPlGWi0QhdQL8CWndIf6JLrhBUcgoIaOhhnp qRqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si10975472edr.347.2021.04.03.23.33.55; Sat, 03 Apr 2021 23:34:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbhDDGcA (ORCPT + 99 others); Sun, 4 Apr 2021 02:32:00 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:30496 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbhDDGcA (ORCPT ); Sun, 4 Apr 2021 02:32:00 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4FCkTg6gdbz9v3gc; Sun, 4 Apr 2021 08:31:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id Wu3DjiSg0knV; Sun, 4 Apr 2021 08:31:51 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4FCkTg5Rd4z9v3gb; Sun, 4 Apr 2021 08:31:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 435258B76F; Sun, 4 Apr 2021 08:31:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id b4wLpnXD92A7; Sun, 4 Apr 2021 08:31:54 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 92D088B76A; Sun, 4 Apr 2021 08:31:53 +0200 (CEST) Subject: Re: [PATCH 1/5] crypto: ccp: Detect and reject vmalloc addresses destined for PSP To: Sean Christopherson , Paolo Bonzini , Brijesh Singh , Tom Lendacky , John Allen Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov References: <20210402233702.3291792-1-seanjc@google.com> <20210402233702.3291792-2-seanjc@google.com> From: Christophe Leroy Message-ID: Date: Sun, 4 Apr 2021 08:31:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210402233702.3291792-2-seanjc@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Le 03/04/2021 à 01:36, Sean Christopherson a écrit : > Explicitly reject vmalloc'd data as the source for SEV commands that are > sent to the PSP. The PSP works with physical addresses, and __pa() will > not return the correct address for a vmalloc'd pionter, which at best > will cause the command to fail, and at worst lead to system instability. > > While it's unlikely that callers will deliberately use vmalloc() for SEV > buffers, a caller can easily use a vmalloc'd pointer unknowingly when > running with CONFIG_VMAP_STACK=y as it's not obvious that putting the > command buffers on the stack would be bad. The command buffers are > relative small and easily fit on the stack, and the APIs to do not > document that the incoming pointer must be a physically contiguous, > __pa() friendly pointer. > > Cc: Brijesh Singh > Cc: Borislav Petkov > Cc: Tom Lendacky > Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support") > Signed-off-by: Sean Christopherson > --- > drivers/crypto/ccp/sev-dev.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c > index cb9b4c4e371e..6556d220713b 100644 > --- a/drivers/crypto/ccp/sev-dev.c > +++ b/drivers/crypto/ccp/sev-dev.c > @@ -150,6 +150,9 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) > > sev = psp->sev_data; > > + if (data && WARN_ON_ONCE(is_vmalloc_addr(data))) > + return -EINVAL; > + I hadn't seen this patch when I commented the 2 other ones, I received it only this night. As commented in the other patches, is_vmalloc_addr() is not the best way to test that __pa() can be safely used. For that, you have virt_addr_valid() > /* Get the physical address of the command buffer */ > phys_lsb = data ? lower_32_bits(__psp_pa(data)) : 0; > phys_msb = data ? upper_32_bits(__psp_pa(data)) : 0; >