From patchwork Fri Apr 28 13:02:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 9704613 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 49F2E60225 for ; Fri, 28 Apr 2017 13:02:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A53628681 for ; Fri, 28 Apr 2017 13:02:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BE2728684; Fri, 28 Apr 2017 13:02: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,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 4872B28681 for ; Fri, 28 Apr 2017 13:02:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165326AbdD1NCg (ORCPT ); Fri, 28 Apr 2017 09:02:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59957 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1165320AbdD1NCe (ORCPT ); Fri, 28 Apr 2017 09:02:34 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3SCwd7H096991 for ; Fri, 28 Apr 2017 09:02:33 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a3sh1j14s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 28 Apr 2017 09:02:33 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 28 Apr 2017 07:02:32 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 28 Apr 2017 07:02:28 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3SD2SWE4653538; Fri, 28 Apr 2017 06:02:28 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 739E3BE03A; Fri, 28 Apr 2017 07:02:28 -0600 (MDT) Received: from sbct-3.watson.ibm.com (unknown [9.2.141.158]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id CDBD9BE038; Fri, 28 Apr 2017 07:02:27 -0600 (MDT) From: Stefan Berger To: tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, jarkko.sakkinen@linux.intel.com Cc: jgunthorpe@obsidianresearch.com, linux-kernel@vger.kernel.org, Stefan Berger Subject: [PATCH v2 3/3] tpm: vtpm_proxy: Add ioctl to request locality prepended to command Date: Fri, 28 Apr 2017 09:02:18 -0400 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1493384538-27883-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1493384538-27883-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17042813-0028-0000-0000-0000077D2B7B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006989; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00853581; UDB=6.00422109; IPR=6.00632522; BA=6.00005316; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015219; XFM=3.00000014; UTC=2017-04-28 13:02:31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042813-0029-0000-0000-000035738AD3 Message-Id: <1493384538-27883-4-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-28_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704280190 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Add an ioctl to request that the locality be prepended to every TPM command. Signed-off-by: Stefan Berger --- drivers/char/tpm/tpm_vtpm_proxy.c | 18 +++++++++++++----- include/uapi/linux/vtpm_proxy.h | 4 +++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c index 48b9818..6c90e02 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -52,7 +52,8 @@ struct proxy_dev { }; /* all supported flags */ -#define VTPM_PROXY_FLAGS_ALL (VTPM_PROXY_FLAG_TPM2) +#define VTPM_PROXY_FLAGS_ALL (VTPM_PROXY_FLAG_TPM2 | \ + VTPM_PROXY_FLAG_PREPEND_LOCALITY) static struct workqueue_struct *workqueue; @@ -77,8 +78,9 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf, size_t count, loff_t *off) { struct proxy_dev *proxy_dev = filp->private_data; - size_t len; - int sig, rc; + size_t len, offset = 0; + int sig, rc = 0; + uint8_t locality; sig = wait_event_interruptible(proxy_dev->wq, proxy_dev->req_len != 0 || @@ -102,7 +104,13 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf, return -EIO; } - rc = copy_to_user(buf, proxy_dev->buffer, len); + if (proxy_dev->flags & VTPM_PROXY_FLAG_PREPEND_LOCALITY) { + locality = proxy_dev->chip->locality; + offset = sizeof(locality); + rc = copy_to_user(buf, &locality, offset); + } + if (!rc) + rc = copy_to_user(&buf[offset], proxy_dev->buffer, len); memset(proxy_dev->buffer, 0, len); proxy_dev->req_len = 0; @@ -114,7 +122,7 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf, if (rc) return -EFAULT; - return len; + return offset + len; } /** diff --git a/include/uapi/linux/vtpm_proxy.h b/include/uapi/linux/vtpm_proxy.h index 83e64e7..512a29e 100644 --- a/include/uapi/linux/vtpm_proxy.h +++ b/include/uapi/linux/vtpm_proxy.h @@ -22,9 +22,11 @@ /** * enum vtpm_proxy_flags - flags for the proxy TPM * @VTPM_PROXY_FLAG_TPM2: the proxy TPM uses TPM 2.0 protocol + * @VTPM_PROXY_PREPEND_LOCALITY:locality byte prepended on each command */ enum vtpm_proxy_flags { - VTPM_PROXY_FLAG_TPM2 = 1, + VTPM_PROXY_FLAG_TPM2 = 1, + VTPM_PROXY_FLAG_PREPEND_LOCALITY = 2, }; /**