From patchwork Tue Dec 5 01:04:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10091913 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AFEB660327 for ; Tue, 5 Dec 2017 01:12:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A270828BA1 for ; Tue, 5 Dec 2017 01:12:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 972A3294F5; Tue, 5 Dec 2017 01:12:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 252A828BA1 for ; Tue, 5 Dec 2017 01:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752325AbdLEBMr (ORCPT ); Mon, 4 Dec 2017 20:12:47 -0500 Received: from mail-by2nam03on0057.outbound.protection.outlook.com ([104.47.42.57]:42880 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752484AbdLEBFk (ORCPT ); Mon, 4 Dec 2017 20:05:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=lGu8BkU2UKkeGFcOoNlFbpQvD7yqASwQY8CDr6KO0HU=; b=iF9ztxazQ0163/FtjaCBuipLx3RY5BOn+Ogus/asoHxPahbpiFo/4L3HcA1Ul/L9v57KWEw7yRzIFwK50N/EesOLzZQKTKTddyNH8ZM5iJA1eMuhAkNctqpk6yYm+5kdou65GAO7cGwahgPTbyY/MSEU0u4X8XE8NHO+Rd0uiQo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from wsp141597wss.amd.com (165.204.78.1) by CY1PR12MB0149.namprd12.prod.outlook.com (10.161.173.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Tue, 5 Dec 2017 01:05:10 +0000 From: Brijesh Singh To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: bp@alien8.de, Brijesh Singh , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Borislav Petkov , Herbert Xu , Gary Hook , Tom Lendacky , linux-crypto@vger.kernel.org Subject: [Part2 PATCH v9 18/38] crypto: ccp: Implement SEV_PEK_CSR ioctl command Date: Mon, 4 Dec 2017 19:04:18 -0600 Message-Id: <20171205010438.5773-19-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171205010438.5773-1-brijesh.singh@amd.com> References: <20171205010438.5773-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: CY4PR0601CA0087.namprd06.prod.outlook.com (52.132.96.156) To CY1PR12MB0149.namprd12.prod.outlook.com (10.161.173.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 449c407b-d273-4708-c819-08d53b7c3c12 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603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KPcNmEJyDlhm5Xy/ugyQuuGt/nzDvBvVlDfPqtleaZ/x9VuIChrTxB6ziVkQMwFHstFcoU2uXn8GLKMwhfWWm2SiclA9jDPzY3PxV/0uk/dO7ghja+IEnAWojp48cLXzBXE6MqkXpGpPvlI4A+Vtn68J2pvizr7FL1nuCBP7cm+2n7PkCMJ7t3DUmmVGkgAuhocNRFs7tjwQx2vau1ik9XwzdQ37aoEWyIayAc+/r1rBL4eqcJppqeRJw4sI1mwTiLWlgNR+YwcmqVuwuuF9PkpjMBykplrjhP0fOa+JH6izma22JWX1DhTf2I2T6jI6/hlSp3W5P7AsOXPoU4m9sKuPAz/cKzfg7yqEOYw8FrBmNEuxfW1V9/LqKo3vJtwdkue6+ymmgS8mCbmoJZyGjuugZz5q; 4:StC+SEinv+oknQUJgMQrtRKyZfmIMLrx4h2Om7Fj57qVOE0SAjXzuWAI5RGnPPblJ7inLMcNzrVcPXvFaky5cnohxvJcEjgdlJpmzRZQGlPWWpIRel72ZdkG5qa5+HmuABKchnzUijMlrxDIKIKPTbU27Gqoyz9oYzsP8nz1ImyFnVGDeGIifAERMf2QMIzgLaL5eRD4mXzZA4FSeL1dvXpqllnrKyBNGRkGXfgouyAPN6U69eNpsZCiW0Hueze0jYGuUrY89v/ZclFqTP9lX2JwaTmxqhnbwP+LHnf1G+mZgKWOrgSbBQkWHRpo8Dx1LQgsA720YNTp6cLyUxE0ag== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231022)(6055026)(6041248)(20161123558100)(20161123555025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(6072148)(201708071742011); SRVR:CY1PR12MB0149; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY1PR12MB0149; X-Forefront-PRVS: 0512CC5201 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(366004)(39860400002)(346002)(376002)(189002)(199003)(16526018)(189998001)(106356001)(478600001)(2870700001)(101416001)(23676004)(52116002)(97736004)(86362001)(575784001)(7696005)(33646002)(54906003)(25786009)(105586002)(76176011)(316002)(2950100002)(7736002)(2906002)(6486002)(50226002)(81166006)(81156014)(8936002)(53936002)(8676002)(4326008)(1076002)(305945005)(66066001)(6116002)(53416004)(5660300001)(47776003)(68736007)(3846002)(50466002)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0149; H:wsp141597wss.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjEyTUIwMTQ5OzIzOjl1cUhDaXVOaVp0ZWsxWHBCQXBJcEZHelVE?= =?utf-8?B?RitZR2NsS0g0bkw2R1ZSQmEvM3QxeGMyd0NVcHhRc2IwSzhiVWdrV3MzY0Rv?= =?utf-8?B?V3FMRXJldFpXeWtPN0VzaExsMlJBUldCTFAzbkd5WC9wV0w0OURPUzlPM2lC?= =?utf-8?B?bVdvSzNFTFUxcWJiRjdWNTVneURuRyt5QmJlYmR4UnhEVkkvMTFDbFpYeHNw?= =?utf-8?B?OURIUW5PbG1WVDlhNnFEdUJ0Mms3dHNubUZJVUk2NXdLOFR4OHQ0K3ltYS9J?= =?utf-8?B?UWZTYklPRlJIL3ZqY25Oa1Q4T0NLRy9KTVkxc1pwL25uRTBpMGdYRUxVSStw?= =?utf-8?B?V1BMbTF1ZnczaU84U0Q4dy9JUiswSzYvUE1CaWVXUUxwTWZuNmtTQ21Bekcy?= =?utf-8?B?cHd3SWhZMUNmVUkrdFdQQ09KNHVla09uTVVpM2R6Tm5PaWtBT1gxQTF4Smoz?= =?utf-8?B?T3ZHcklkWE9Sa2JxaGhQb3lpazdZdENVdHRZ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xd1vnKJC7LE SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0149; 20:3qyG8r6tBnceCsCkoqR1EcACKXTIo+hCWPmDytZdUNwgrlMG54zsyIPJgPdpcANWae+icqu8EG00eDk06RTmyCCqYKxBFmP+lben5WXwfWkF39z4OpRmiWM+DamikJ6wYtacnHoaW40BKwJ/OegbzbgVWES065lcy/RDqj1+Hc54byTmJYWZT1t9IUhp/WtgEIR7MgbWHEhKwy95Pdz7sjsXlv0sb07EGfaDEq2OGFXRkQt15EHDeJT2UkADHSYP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2017 01:05:10.7015 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 449c407b-d273-4708-c819-08d53b7c3c12 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0149 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SEV_PEK_CSR command can be used to generate a PEK certificate signing request. The command is defined in SEV spec section 5.7. Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Borislav Petkov Cc: Herbert Xu Cc: Gary Hook Cc: Tom Lendacky Cc: linux-crypto@vger.kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Improvements-by: Borislav Petkov Signed-off-by: Brijesh Singh Acked-by: Gary R Hook --- drivers/crypto/ccp/psp-dev.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index fd3daf0a1176..c3906bbdb69b 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -302,6 +302,69 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp) return __sev_do_cmd_locked(cmd, 0, &argp->error); } +static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp) +{ + struct sev_user_data_pek_csr input; + struct sev_data_pek_csr *data; + void *blob = NULL; + int ret; + + if (copy_from_user(&input, (void __user *)argp->data, sizeof(input))) + return -EFAULT; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + /* userspace wants to query CSR length */ + if (!input.address || !input.length) + goto cmd; + + /* allocate a physically contiguous buffer to store the CSR blob */ + if (!access_ok(VERIFY_WRITE, input.address, input.length) || + input.length > SEV_FW_BLOB_MAX_SIZE) { + ret = -EFAULT; + goto e_free; + } + + blob = kmalloc(input.length, GFP_KERNEL); + if (!blob) { + ret = -ENOMEM; + goto e_free; + } + + data->address = __psp_pa(blob); + data->len = input.length; + +cmd: + if (psp_master->sev_state == SEV_STATE_UNINIT) { + ret = __sev_platform_init_locked(&argp->error); + if (ret) + goto e_free_blob; + } + + ret = __sev_do_cmd_locked(SEV_CMD_PEK_CSR, data, &argp->error); + + /* If we query the CSR length, FW responded with expected data. */ + input.length = data->len; + + if (copy_to_user((void __user *)argp->data, &input, sizeof(input))) { + ret = -EFAULT; + goto e_free_blob; + } + + if (blob) { + if (copy_to_user((void __user *)input.address, blob, input.length)) + ret = -EFAULT; + } + +e_free_blob: + kfree(blob); +e_free: + kfree(data); + return ret; +} + static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) { void __user *argp = (void __user *)arg; @@ -336,6 +399,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) case SEV_PDH_GEN: ret = sev_ioctl_do_pek_pdh_gen(SEV_CMD_PDH_GEN, &input); break; + case SEV_PEK_CSR: + ret = sev_ioctl_do_pek_csr(&input); + break; default: ret = -EINVAL; goto out;