Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2758841ybh; Mon, 5 Aug 2019 06:23:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtNJxyBMjWQwa58tYtxFMgD+w6VZSkXPbWn2ByfqLLIkO7SGzvAmc0Ar3CKTyjBxrMBKqV X-Received: by 2002:a17:902:7c90:: with SMTP id y16mr146780349pll.238.1565011433199; Mon, 05 Aug 2019 06:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565011433; cv=none; d=google.com; s=arc-20160816; b=QX31SxwH+syCzwLNniXsOw2+TCO54Nq3OX/PU4OehCaEYCPNPSBXGfiVHTCr/S2d99 xtggDXFDK0R4or3M/EhfPVQOOdeAb3mmz8PtGrvF81vc8pLiQ74L73v10z4byxxmmZxb 0y7EUZ/fxrIEV3WGn7cYQTV4rlqmZRzFNIs0C9pTjF3wFhlyjmPGtaXRn58i3l4sCJwd Vo6eAPBDIS67MFNArRQ4kOfNnVet5MVc+tEIlxKRIn+HVbjE9l6H3bsrCbOiDj/1/loX FaTMaUzQiypxfusjCyDpTs0q37W5WrflRDTr0LPi+kMd0lXE5iHBVHuLvUbA7cUEaXpv w0ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mmbwUOcohkW9OW3RqxJV+xcYCPCx/RgmyHCVvuLAnJE=; b=ZNaAVwh8tIhDmNUff8flto7+jKHV/G0tAKsh2QRI/EcvdRce93GdvBAQCU5uMydGng Dx9WC03RNbAP+I04biPmvIrSgBBJ6nFdE0JDrVq1cAhhrKuYXhC8hXPs1KFk2Vtc2NHV 5DaAy2bGNZbhsoIZYfFyfrowWISAlQ36O58nh/09K57TkHoX2+EG9n1QxK77EJJ7F/uF 4IyMhw/if0pJ8ML1hKSaeOAI5MClPCnFyqmfiesfIciMItgfrtmYJx5XLvUygY8qwVKD gJonb4gvWEpTewt5zdNS/tjetOYS+SmR5mKDMUoljfB8mx0sgh8/slZ1/cY1EWu9uRQQ wQnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ULwbZgxL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2si46195569pfp.113.2019.08.05.06.23.37; Mon, 05 Aug 2019 06:23:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ULwbZgxL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730768AbfHENWu (ORCPT + 99 others); Mon, 5 Aug 2019 09:22:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:59456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730760AbfHENWs (ORCPT ); Mon, 5 Aug 2019 09:22:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC1F52067D; Mon, 5 Aug 2019 13:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011367; bh=ZSE3dFkGhmtS4G/zJCdfivvA+aFzvFaTfpakk9idhlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ULwbZgxLLtzQ4agOQQUFPrz7nnTLV82xQDSw+z4aTwJv+NnQtIOotbAT/l66ScO2U ZJu/nmRycG7OTbVDN1QH06K/C2iVpj+QjUCyok9qv5q5ZAFZaOTHF5haTSBqb6B0fe 76HRUz8r5TBncYtV88DUkEH/la6qISasG5ntQvIQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cfir Cohen , David Rientjes , Tom Lendacky , Gary R Hook , Herbert Xu , Sasha Levin Subject: [PATCH 5.2 066/131] crypto: ccp - Fix SEV_VERSION_GREATER_OR_EQUAL Date: Mon, 5 Aug 2019 15:02:33 +0200 Message-Id: <20190805124955.894262734@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124951.453337465@linuxfoundation.org> References: <20190805124951.453337465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 83bf42510d7f7e1daa692c096e8e9919334d7b57 ] SEV_VERSION_GREATER_OR_EQUAL() will fail if upgrading from 2.2 to 3.1, for example, because the minor version is not equal to or greater than the major. Fix this and move to a static inline function for appropriate type checking. Fixes: edd303ff0e9e ("crypto: ccp - Add DOWNLOAD_FIRMWARE SEV command") Reported-by: Cfir Cohen Signed-off-by: David Rientjes Acked-by: Tom Lendacky Acked-by: Gary R Hook Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/ccp/psp-dev.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index de5a8ca70d3da..6b17d179ef8a0 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -24,10 +24,6 @@ #include "sp-dev.h" #include "psp-dev.h" -#define SEV_VERSION_GREATER_OR_EQUAL(_maj, _min) \ - ((psp_master->api_major) >= _maj && \ - (psp_master->api_minor) >= _min) - #define DEVICE_NAME "sev" #define SEV_FW_FILE "amd/sev.fw" #define SEV_FW_NAME_SIZE 64 @@ -47,6 +43,15 @@ MODULE_PARM_DESC(psp_probe_timeout, " default timeout value, in seconds, during static bool psp_dead; static int psp_timeout; +static inline bool sev_version_greater_or_equal(u8 maj, u8 min) +{ + if (psp_master->api_major > maj) + return true; + if (psp_master->api_major == maj && psp_master->api_minor >= min) + return true; + return false; +} + static struct psp_device *psp_alloc_struct(struct sp_device *sp) { struct device *dev = sp->dev; @@ -588,7 +593,7 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp) int ret; /* SEV GET_ID is available from SEV API v0.16 and up */ - if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16)) + if (!sev_version_greater_or_equal(0, 16)) return -ENOTSUPP; if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) @@ -651,7 +656,7 @@ static int sev_ioctl_do_get_id(struct sev_issue_cmd *argp) int ret; /* SEV GET_ID available from SEV API v0.16 and up */ - if (!SEV_VERSION_GREATER_OR_EQUAL(0, 16)) + if (!sev_version_greater_or_equal(0, 16)) return -ENOTSUPP; /* SEV FW expects the buffer it fills with the ID to be @@ -1053,7 +1058,7 @@ void psp_pci_init(void) psp_master->sev_state = SEV_STATE_UNINIT; } - if (SEV_VERSION_GREATER_OR_EQUAL(0, 15) && + if (sev_version_greater_or_equal(0, 15) && sev_update_firmware(psp_master->dev) == 0) sev_get_api_version(); -- 2.20.1