lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-23-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:12:42 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 022/437] char/tpm: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/char/tpm/eventlog/common.c |  2 +-
 drivers/char/tpm/tpm-dev-common.c  | 26 +++++++++++++-------------
 drivers/char/tpm/tpm-dev.c         |  4 ++--
 drivers/char/tpm/tpm-dev.h         |  6 ++----
 drivers/char/tpm/tpm_vtpm_proxy.c  | 20 ++++++++++----------
 drivers/char/tpm/tpmrm-dev.c       |  4 ++--
 6 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/drivers/char/tpm/eventlog/common.c b/drivers/char/tpm/eventlog/common.c
index 639c3f395a5a..5df887f7b119 100644
--- a/drivers/char/tpm/eventlog/common.c
+++ b/drivers/char/tpm/eventlog/common.c
@@ -66,7 +66,7 @@ static int tpm_bios_measurements_release(struct inode *inode,
 static const struct file_operations tpm_bios_measurements_ops = {
 	.owner = THIS_MODULE,
 	.open = tpm_bios_measurements_open,
-	.read = seq_read,
+	.read_iter = seq_read_iter,
 	.llseek = seq_lseek,
 	.release = tpm_bios_measurements_release,
 };
diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c
index 30b4c288c1bb..6cb20cb43ac0 100644
--- a/drivers/char/tpm/tpm-dev-common.c
+++ b/drivers/char/tpm/tpm-dev-common.c
@@ -122,10 +122,10 @@ void tpm_common_open(struct file *file, struct tpm_chip *chip,
 	file->private_data = priv;
 }
 
-ssize_t tpm_common_read(struct file *file, char __user *buf,
-			size_t size, loff_t *off)
+ssize_t tpm_common_read_iter(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct file_priv *priv = file->private_data;
+	struct file_priv *priv = iocb->ki_filp->private_data;
+	size_t size = iov_iter_count(to);
 	ssize_t ret_size = 0;
 	int rc;
 
@@ -140,21 +140,21 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,
 			goto out;
 		}
 
-		rc = copy_to_user(buf, priv->data_buffer + *off, ret_size);
+		rc = !copy_to_iter_full(priv->data_buffer + iocb->ki_pos, ret_size, to);
 		if (rc) {
 			memset(priv->data_buffer, 0, TPM_BUFSIZE);
 			priv->response_length = 0;
 			ret_size = -EFAULT;
 		} else {
-			memset(priv->data_buffer + *off, 0, ret_size);
+			memset(priv->data_buffer + iocb->ki_pos, 0, ret_size);
 			priv->response_length -= ret_size;
-			*off += ret_size;
+			iocb->ki_pos += ret_size;
 		}
 	}
 
 out:
 	if (!priv->response_length) {
-		*off = 0;
+		iocb->ki_pos = 0;
 		del_timer_sync(&priv->user_read_timer);
 		flush_work(&priv->timeout_work);
 	}
@@ -162,10 +162,10 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,
 	return ret_size;
 }
 
-ssize_t tpm_common_write(struct file *file, const char __user *buf,
-			 size_t size, loff_t *off)
+ssize_t tpm_common_write_iter(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct file_priv *priv = file->private_data;
+	struct file_priv *priv = iocb->ki_filp->private_data;
+	size_t size = iov_iter_count(from);
 	int ret = 0;
 
 	if (size > TPM_BUFSIZE)
@@ -183,7 +183,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
 		goto out;
 	}
 
-	if (copy_from_user(priv->data_buffer, buf, size)) {
+	if (!copy_from_iter_full(priv->data_buffer, size, from)) {
 		ret = -EFAULT;
 		goto out;
 	}
@@ -196,7 +196,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
 
 	priv->response_length = 0;
 	priv->response_read = false;
-	*off = 0;
+	iocb->ki_pos = 0;
 
 	/*
 	 * If in nonblocking mode schedule an async job to send
@@ -204,7 +204,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
 	 * In case of error the err code will be returned in
 	 * the subsequent read call.
 	 */
-	if (file->f_flags & O_NONBLOCK) {
+	if (iocb->ki_filp->f_flags & O_NONBLOCK) {
 		priv->command_enqueued = true;
 		queue_work(tpm_dev_wq, &priv->async_work);
 		mutex_unlock(&priv->buffer_mutex);
diff --git a/drivers/char/tpm/tpm-dev.c b/drivers/char/tpm/tpm-dev.c
index e2c0baa69fef..2f499c38fef5 100644
--- a/drivers/char/tpm/tpm-dev.c
+++ b/drivers/char/tpm/tpm-dev.c
@@ -61,8 +61,8 @@ const struct file_operations tpm_fops = {
 	.owner = THIS_MODULE,
 	.llseek = no_llseek,
 	.open = tpm_open,
-	.read = tpm_common_read,
-	.write = tpm_common_write,
+	.read_iter = tpm_common_read_iter,
+	.write_iter = tpm_common_write_iter,
 	.poll = tpm_common_poll,
 	.release = tpm_release,
 };
diff --git a/drivers/char/tpm/tpm-dev.h b/drivers/char/tpm/tpm-dev.h
index f3742bcc73e3..bc02b9509724 100644
--- a/drivers/char/tpm/tpm-dev.h
+++ b/drivers/char/tpm/tpm-dev.h
@@ -23,10 +23,8 @@ struct file_priv {
 
 void tpm_common_open(struct file *file, struct tpm_chip *chip,
 		     struct file_priv *priv, struct tpm_space *space);
-ssize_t tpm_common_read(struct file *file, char __user *buf,
-			size_t size, loff_t *off);
-ssize_t tpm_common_write(struct file *file, const char __user *buf,
-			 size_t size, loff_t *off);
+ssize_t tpm_common_read_iter(struct kiocb *iocb, struct iov_iter *to);
+ssize_t tpm_common_write_iter(struct kiocb *iocb, struct iov_iter *from);
 __poll_t tpm_common_poll(struct file *file, poll_table *wait);
 
 void tpm_common_release(struct file *file, struct file_priv *priv);
diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c
index 11c502039faf..70d51ccb9a98 100644
--- a/drivers/char/tpm/tpm_vtpm_proxy.c
+++ b/drivers/char/tpm/tpm_vtpm_proxy.c
@@ -69,10 +69,10 @@ static void vtpm_proxy_delete_device(struct proxy_dev *proxy_dev);
  * Return:
  *	Number of bytes read or negative error code
  */
-static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf,
-				    size_t count, loff_t *off)
+static ssize_t vtpm_proxy_fops_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct proxy_dev *proxy_dev = filp->private_data;
+	struct proxy_dev *proxy_dev = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(to);
 	size_t len;
 	int sig, rc;
 
@@ -98,7 +98,7 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf,
 		return -EIO;
 	}
 
-	rc = copy_to_user(buf, proxy_dev->buffer, len);
+	rc = !copy_to_iter_full(proxy_dev->buffer, len, to);
 	memset(proxy_dev->buffer, 0, len);
 	proxy_dev->req_len = 0;
 
@@ -124,10 +124,10 @@ static ssize_t vtpm_proxy_fops_read(struct file *filp, char __user *buf,
  * Return:
  *	Number of bytes read or negative error value
  */
-static ssize_t vtpm_proxy_fops_write(struct file *filp, const char __user *buf,
-				     size_t count, loff_t *off)
+static ssize_t vtpm_proxy_fops_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct proxy_dev *proxy_dev = filp->private_data;
+	struct proxy_dev *proxy_dev = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 
 	mutex_lock(&proxy_dev->buf_lock);
 
@@ -146,7 +146,7 @@ static ssize_t vtpm_proxy_fops_write(struct file *filp, const char __user *buf,
 
 	proxy_dev->req_len = 0;
 
-	if (copy_from_user(proxy_dev->buffer, buf, count)) {
+	if (!copy_from_iter_full(proxy_dev->buffer, count, from)) {
 		mutex_unlock(&proxy_dev->buf_lock);
 		return -EFAULT;
 	}
@@ -244,8 +244,8 @@ static int vtpm_proxy_fops_release(struct inode *inode, struct file *filp)
 static const struct file_operations vtpm_proxy_fops = {
 	.owner = THIS_MODULE,
 	.llseek = no_llseek,
-	.read = vtpm_proxy_fops_read,
-	.write = vtpm_proxy_fops_write,
+	.read_iter = vtpm_proxy_fops_read,
+	.write_iter = vtpm_proxy_fops_write,
 	.poll = vtpm_proxy_fops_poll,
 	.release = vtpm_proxy_fops_release,
 };
diff --git a/drivers/char/tpm/tpmrm-dev.c b/drivers/char/tpm/tpmrm-dev.c
index eef0fb06ea83..f1f5cc0ba627 100644
--- a/drivers/char/tpm/tpmrm-dev.c
+++ b/drivers/char/tpm/tpmrm-dev.c
@@ -48,8 +48,8 @@ const struct file_operations tpmrm_fops = {
 	.owner = THIS_MODULE,
 	.llseek = no_llseek,
 	.open = tpmrm_open,
-	.read = tpm_common_read,
-	.write = tpm_common_write,
+	.read_iter = tpm_common_read_iter,
+	.write_iter = tpm_common_write_iter,
 	.poll = tpm_common_poll,
 	.release = tpmrm_release,
 };
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ