From patchwork Wed Oct 11 16:55:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 10000095 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 AB2EE602BF for ; Wed, 11 Oct 2017 16:55:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD62D28ADC for ; Wed, 11 Oct 2017 16:55:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A232628AE2; Wed, 11 Oct 2017 16:55:43 +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=unavailable 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 B650128ADC for ; Wed, 11 Oct 2017 16:55:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751642AbdJKQzi (ORCPT ); Wed, 11 Oct 2017 12:55:38 -0400 Received: from mail-dm3nam03on0078.outbound.protection.outlook.com ([104.47.41.78]:40456 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751147AbdJKQzg (ORCPT ); Wed, 11 Oct 2017 12:55:36 -0400 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=oCCVbRgLpwPt/ES9LVJzoQOx5pa75/YM62qjqg6nWfw=; b=OH57sbnqPYQaKJRI30jCI8rqKGwtxlwFSMD+45Ysb9TWl93wKNRQPie+PSPOpnp2kAy1MzR3fmCdeq57Rf9b2ZTQr88rdks0c0IP5xPtzAotejE/FMrjgT22yDNHLJahHteGMnAdAibROiz7HJ3dCGgn+0Ittzpirkk53qCwmao= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 11 Oct 2017 16:55:32 +0000 From: Brijesh Singh To: bp@suse.de Cc: Brijesh Singh , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Herbert Xu , Gary Hook , Tom Lendacky , linux-crypto@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Part2 PATCH v5.2 12.3/31] crypto: ccp: Implement SEV_FACTORY_RESET ioctl command Date: Wed, 11 Oct 2017 11:55:21 -0500 Message-Id: <20171011165521.115904-1-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171007010607.78088-3-brijesh.singh@amd.com> References: <20171007010607.78088-3-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR04CA0033.namprd04.prod.outlook.com (10.172.163.19) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5fbc8ff-7359-4488-51cc-08d510c8e384 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:lcYtkisZgTOFZvJVBvn/xNjZRc4IWuSTgh/+3Q2ZNhFksg2jy/gzw9a0XPOpmoIDjlEc37szC8vXpEiiNOoWe4iffdkzKHyJL/mM5CSdp1AJG+oati2JABa6AeQ6iIuRmdmm+whGyLTKCp7qtI2lUXjB6caNNgVqH2+CeR0gl8cnfl+i1Ftk8NM0ge3H+5dRGcCYj1J2b/xuNkdE1iCFRu6BtT32qpYZud592A6HV9v4NM0ZhkHoihllurwPjor+; 25:m9keEPwuuEO8tnh3DRVxJdxXF9CVu77fG+QIWJAL3AUv7wRS1UJD994P8tqWCYxjpcSClO84g5HuUBkl/2MnFLvDcDhuP8smHUBp5aMbLZZg9/a6mUV+j3DGgi60VCX5lQhJCDZS60Eqsheu5Ju04Xw+hNyiG98x6rgihl+4gv5MFigY0kzyt2fQMkQ0skZ2kxkYTgpl70tjJVORiVVlJY2gzb6RBQMmvYlisNkFe7Ph5tyQF/3bgziWsei9RixKYhykmuL9FZm5wznu77N6JRn50aHlqI+YCmV4SZ5aFNaT6yQ+uVkyLgdBH+sNywr+19DXQ2/MeV50SztJSfJWkQ==; 31:DRZZMiP44H35UmSxjH2XfvXKThWW3XsjooS3C29tAONYXtn0yWckOZR3Pvyl3TMAGARq7kxHIuHQzsqmhr+Hc4kTpSybAAlzg6czyuhurNJsTaOTzusf9imXyZkwOCVKoHgL4LVlgb/JGgvphbn6w7pEQvhA3EJSYHl5YIFcua428npjeBYFoROVs9y3sfwdAun3IyOwFEC3hxDKTUAD5PbpmiRGZ7LCayPr0nPlcEw= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:n1zVhLbeXdNKnX9S3Gznlbz907wSBWTNU4UyLCRWi64pMVQm86Cz8gBfyVUSDKFK3RajIIdPyudDT9g8qEYjdBgRRtZobEg/tdD2ClNmsuvK5KIjN1Wr1v65+oY+qDt0NtjWhIEN5FWLxheswe/bxD2BDGfNYketkWkK6n4dzVzCnT9v7rwLogc0dKOE0JMZJq3XHqTwJyPRuqaPDcG0fy8xgkGTS+YzKG6TMRDQzLLFV+NSzeMYHlgJ7Yuz8ye0PnwIe9oPZDM/cmnmt2Cmxa2KbtzdSBi7jjDP+s8/pQXtgA7Dq7l9OyeiP8b5dq9HAVYLrINHHnccPD9kiH/yImEfRimoMXxDQ5xvaXBiDrA+vbLiXH1bLt4C6UWNvJdZaIhGuQreLBi+4GYM5oqACoQ9QcD0fsfKwyflpagMZgX2uwJbJMopaVrTTX79VWQvTPKOjTF8MJFjalMz41I48IDpNT6gS4dL/8g21Hc6r5S6kVOGOInpAke/ZByxxtcc; 4:YZwaC0eBltCDBUzgdhV5+EInvwYvhJlRuw4/IWOFEVDR5nogGuZ1jUSvxNUnteY7OL/5HIuJRfMK1tXGcudQfW7Djf9EiH40lO4FOFZyy4vbRBgyMpIB4DGtEpFkmFUkiVUYosYxj7Kk7hsD8iv38QpGXrEZskorVVM1r4ZzDPAyMuwLnXe6PAq1wwdXM7wS9qKQWi5C+4Kse0cazUUa18CCoQ8i1aYlr+P6Z+KBCsUYwMc/KPyPhUEQgvAcenpvbWIYKdk4iQreHdO0dx3eyc6t5jFKaAPs+4eRvOKqvQjZ75nwTFH+U3OY+C3QgbG4IqV4Gja18IfwSbaLXTTd5w== X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123564025)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 0457F11EAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(39860400002)(199003)(5423002)(189002)(68736007)(76176999)(53416004)(8936002)(50226002)(305945005)(50986999)(47776003)(478600001)(33646002)(7736002)(50466002)(2361001)(189998001)(105586002)(2351001)(81166006)(106356001)(2870700001)(8676002)(6486002)(53936002)(54906003)(3846002)(6116002)(66066001)(316002)(97736004)(5660300001)(101416001)(4326008)(6666003)(86362001)(36756003)(81156014)(2906002)(2950100002)(23676002)(1076002)(16526018)(25786009)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtTTjFQUjEyTUIwMTU4OzIzOmdiYzMyalNTWkFZQUwxMXpCRXIzeTFHdXda?= =?utf-8?B?enA5NGJpZnl1RUVGaEx2WDQ2SUxZSm5PY0RMLzZLY0I4U1d3c0sxbVF3RDNp?= =?utf-8?B?MUNqVGhhS0pUbitHS3JDRmFPeFI0bXk0Z0FVd1JydHoyZHFYdUpvREdvS2to?= =?utf-8?B?eE56eTNZSkNjRVJ6VTVOKzY4MHhJQnZhNjFNcnMrNWd0ZDFGTUtncFFaWTAz?= =?utf-8?B?clI1UTB2Rk4xOXZ4WGRoeFVkWUFjWlBDZ0s2cGo0WHRKTEhPMmt0MW03VFBE?= =?utf-8?B?VVhsbzcxVzd1Z3lVVVF4eWRwbEFZZ2Vwdi92Y0Q1OFdJcmVUcEc0U2FLUmg1?= =?utf-8?B?cnN2YWRyQ2pIUFZxK01iSjIwcm5kVmdHZTkvL2FwWjBTbDRVb2R2a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jqWl6OXv7t4OF41q9ddAPPl8qhz/iqhw/DwW3X4WLAB3fg3Ry3OXOexzNfqI1YG/1W+PfO3GDNwO7MKEVGCB7MImZjM+OjXRqGMGsxb1k81Xn48Zwh08kHYa+s9exgf9W04AD3q3HYya8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:bnRebie6QZGEpvk9qmdSni844Vl9uyYpohcGdvsCepkE2O8HQbVdzxNtCDS8QpM4SF/mZrKZwers1jA1LfXF2nKgcwGBcYUVfD6pYEf3dVhXRFxVqcnz0pSmxPcMXTdV7/B+fxjKfLIo8xzT5YeSVlMpHQHsb9XlrAM1kZzVWN6kAOPYl36WkN7U4Nmv4pnINrPp88uo3CYcRb5lW0KB7PHi7g3MY8OVQ9tq+ECmfRk1xfu/SA7IZ97mCIiklPnR X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2017 16:55:32.5802 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 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_FACTORY_RESET command can be used by the platform owner to reset the non-volatile SEV related data. The command is defined in SEV spec section 5.4 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 --- Changes since v5.1: * rename sev_handle_cmd -> sev_do_cmd (from Boris) * skip copy_to_user when invalid cmd id is passed (from Boris) * use SEV_MAX instead of SEV_CMD_MAX to check for invalid command drivers/crypto/ccp/psp-dev.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c index 175cb3c3b8ef..a9c885a39910 100644 --- a/drivers/crypto/ccp/psp-dev.c +++ b/drivers/crypto/ccp/psp-dev.c @@ -179,7 +179,34 @@ static int sev_do_cmd(int cmd, void *data, int *psp_ret) static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg) { - return -ENOTTY; + void __user *argp = (void __user *)arg; + struct sev_issue_cmd input; + int ret = -EFAULT; + + if (ioctl != SEV_ISSUE_CMD) + return -EINVAL; + + if (copy_from_user(&input, argp, sizeof(struct sev_issue_cmd))) + return -EFAULT; + + if (input.cmd > SEV_MAX) + return -EINVAL; + + switch (input.cmd) { + + case SEV_FACTORY_RESET: { + ret = sev_do_cmd(SEV_CMD_FACTORY_RESET, 0, &input.error); + break; + } + default: + ret = -EINVAL; + goto out; + } + + if (copy_to_user(argp, &input, sizeof(struct sev_issue_cmd))) + ret = -EFAULT; +out: + return ret; } static const struct file_operations sev_fops = {