-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tpm: expose spaces via a device link /dev/tpmrm<n>
Currently the tpm spaces are not exposed to userspace. Make this exposure via a separate device, which can now be opened multiple times because each read/write transaction goes separately via the space. Concurrency is protected by the chip->tpm_mutex for each read/write transaction separately. The TPM is cleared of all transient objects by the time the mutex is dropped, so there should be no interference between the kernel and userspace. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
- Loading branch information
James Bottomley
authored and
Jarkko Sakkinen
committed
Apr 3, 2017
1 parent
ecb38e2
commit fdc915f
Showing
5 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2017 James.Bottomley@HansenPartnership.com | ||
* | ||
* GPLv2 | ||
*/ | ||
#include <linux/slab.h> | ||
#include "tpm-dev.h" | ||
|
||
struct tpmrm_priv { | ||
struct file_priv priv; | ||
struct tpm_space space; | ||
}; | ||
|
||
static int tpmrm_open(struct inode *inode, struct file *file) | ||
{ | ||
struct tpm_chip *chip; | ||
struct tpmrm_priv *priv; | ||
int rc; | ||
|
||
chip = container_of(inode->i_cdev, struct tpm_chip, cdevs); | ||
priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
if (priv == NULL) | ||
return -ENOMEM; | ||
|
||
rc = tpm2_init_space(&priv->space); | ||
if (rc) { | ||
kfree(priv); | ||
return -ENOMEM; | ||
} | ||
|
||
tpm_common_open(file, chip, &priv->priv); | ||
|
||
return 0; | ||
} | ||
|
||
static int tpmrm_release(struct inode *inode, struct file *file) | ||
{ | ||
struct file_priv *fpriv = file->private_data; | ||
struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv); | ||
|
||
tpm_common_release(file, fpriv); | ||
tpm2_del_space(&priv->space); | ||
kfree(priv); | ||
|
||
return 0; | ||
} | ||
|
||
ssize_t tpmrm_write(struct file *file, const char __user *buf, | ||
size_t size, loff_t *off) | ||
{ | ||
struct file_priv *fpriv = file->private_data; | ||
struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv); | ||
|
||
return tpm_common_write(file, buf, size, off, &priv->space); | ||
} | ||
|
||
const struct file_operations tpmrm_fops = { | ||
.owner = THIS_MODULE, | ||
.llseek = no_llseek, | ||
.open = tpmrm_open, | ||
.read = tpm_common_read, | ||
.write = tpmrm_write, | ||
.release = tpmrm_release, | ||
}; | ||
|