From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8912C433ED for ; Sun, 4 Apr 2021 06:31:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A46036136A for ; Sun, 4 Apr 2021 06:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbhDDGcB (ORCPT ); Sun, 4 Apr 2021 02:32:01 -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: kvm@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; >