Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4634336pxj; Wed, 12 May 2021 09:42:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh95YyqyiH08hovxIxOtCXW1vTMp7zAY1rpKaGSS5VzLugjh0fbr6Ef9WGtOcfziaeocb6 X-Received: by 2002:a05:6808:1401:: with SMTP id w1mr2657494oiv.52.1620837738953; Wed, 12 May 2021 09:42:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837738; cv=none; d=google.com; s=arc-20160816; b=Gx5uj5B7RI25yrSMxVFhBTRisc78D2JK/ilwnJSirjmHAMMoAPQdzmGGc4bpRbFsVJ htxNSBlnnfLLExwR86O5XplMJ+tyMk8rQw9ZYUw2AGpJh9l7+uWMNprx81+q4gaEz31i eWGqMfD8Z4v5nv6u5UiTVZsxW0hfsIxAEZWnw48Wxv2UQvr9sL1zDb3Yyche/l+L0DqP wkTwhELx0ix9LUh1dpOYfmwA1dRM1TsUZXpxe/ssQNcC5pGP1Pq9zU+zzgs+ZVHDeytJ bUgNFJvZGTc7uSjPv8wrvsBhWenIj6/qiT0dfAZ0fapSmLc0MDLorXkyZBJIn1mYxEhw 1J6Q== 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=IaNZSPWaCV1HnQ1xLWn0lvS6qeWJXBLUC7eo2KA+hy8=; b=wiHtYe/coIJpSbuINQsEBnqXfergpRdRBLu39yG6cOpF7orcypZ0/X0DEl7aMKP4El dElwDBNSAl2x/iougGJk2hSGu7jACdvVxYFM3Vgi0kr4j4dpjqHRDQrzvQ0NLVxrK1aq inp8aBxW1DIYe4mQd6Y1C7tJhm4ANaHR45gY89tPDzLr+FSsethYmnTTgla3f6XM+wxz WDryidh4rOLOd2PEa2CggCi1+VXUYEK4k7lpZejdgrH2FO2nDWza5ZGH1rrduDpa5qHU DsC7d9XbKbdu3YHFp77YDnyVr0RT7Qnc3eVmBIM5GIRcqMZx7svoYd59zCsSsN0zx/bm noHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RJznjfTF; 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 b128si531605oif.208.2021.05.12.09.41.55; Wed, 12 May 2021 09:42: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=RJznjfTF; 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 S242948AbhELQkL (ORCPT + 99 others); Wed, 12 May 2021 12:40:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:41718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236888AbhELPrI (ORCPT ); Wed, 12 May 2021 11:47:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2452E61C99; Wed, 12 May 2021 15:23:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833033; bh=Ou5baM93maEufZ1Up8/JrftESuCW3fNu8L4LME2rSRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJznjfTFkrFqZ1qGelI9octwrpxqXuZULps/Q5suPGOv5DLnITvStV1aAjZbb0odn /4pb5ip2HJqkJDgf0J1rc2qX7zImar+Q0d9MtQZrq6zm2e04fF8eUhQCZHz0YyQWN1 PI9z7CZUZSyu6M3zXNa5exTqHNywGa8XGykrmo28= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brijesh Singh , Borislav Petkov , Tom Lendacky , Christophe Leroy , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 478/530] crypto: ccp: Detect and reject "invalid" addresses destined for PSP Date: Wed, 12 May 2021 16:49:48 +0200 Message-Id: <20210512144835.468166158@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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: Sean Christopherson [ Upstream commit 74c1f1366eb7714b8b211554f6c5cee315ff3fbc ] Explicitly reject using pointers that are not virt_to_phys() friendly as the source for SEV commands that are sent to the PSP. The PSP works with physical addresses, and __pa()/virt_to_phys() will not return the correct address in these cases, e.g. for a vmalloc'd pointer. At best, the bogus address will cause the command to fail, and at worst lead to system instability. While it's unlikely that callers will deliberately use a bad pointer 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 Cc: Christophe Leroy Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support") Signed-off-by: Sean Christopherson Message-Id: <20210406224952.4177376-3-seanjc@google.com> Reviewed-by: Brijesh Singh Acked-by: Tom Lendacky Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- 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 476113e12489..5b82ba7acc7c 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -149,6 +149,9 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret) sev = psp->sev_data; + if (data && WARN_ON_ONCE(!virt_addr_valid(data))) + return -EINVAL; + /* 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; -- 2.30.2