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-288-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:17:07 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 287/437] cachefiles: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 fs/cachefiles/daemon.c   | 35 ++++++++++++++++-------------------
 fs/cachefiles/internal.h |  4 ++--
 fs/cachefiles/ondemand.c |  5 +++--
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
index 6465e2574230..4a6a31a76d35 100644
--- a/fs/cachefiles/daemon.c
+++ b/fs/cachefiles/daemon.c
@@ -23,10 +23,8 @@
 
 static int cachefiles_daemon_open(struct inode *, struct file *);
 static int cachefiles_daemon_release(struct inode *, struct file *);
-static ssize_t cachefiles_daemon_read(struct file *, char __user *, size_t,
-				      loff_t *);
-static ssize_t cachefiles_daemon_write(struct file *, const char __user *,
-				       size_t, loff_t *);
+static ssize_t cachefiles_daemon_read(struct kiocb *, struct iov_iter *);
+static ssize_t cachefiles_daemon_write(struct kiocb *, struct iov_iter *);
 static __poll_t cachefiles_daemon_poll(struct file *,
 					   struct poll_table_struct *);
 static int cachefiles_daemon_frun(struct cachefiles_cache *, char *);
@@ -50,8 +48,8 @@ const struct file_operations cachefiles_daemon_fops = {
 	.owner		= THIS_MODULE,
 	.open		= cachefiles_daemon_open,
 	.release	= cachefiles_daemon_release,
-	.read		= cachefiles_daemon_read,
-	.write		= cachefiles_daemon_write,
+	.read_iter	= cachefiles_daemon_read,
+	.write_iter	= cachefiles_daemon_write,
 	.poll		= cachefiles_daemon_poll,
 	.llseek		= noop_llseek,
 };
@@ -207,8 +205,9 @@ static int cachefiles_daemon_release(struct inode *inode, struct file *file)
 }
 
 static ssize_t cachefiles_do_daemon_read(struct cachefiles_cache *cache,
-					 char __user *_buffer, size_t buflen)
+					 struct iov_iter *to)
 {
+	size_t buflen = iov_iter_count(to);
 	unsigned long long b_released;
 	unsigned f_released;
 	char buffer[256];
@@ -245,7 +244,7 @@ static ssize_t cachefiles_do_daemon_read(struct cachefiles_cache *cache,
 	if (n > buflen)
 		return -EMSGSIZE;
 
-	if (copy_to_user(_buffer, buffer, n) != 0)
+	if (!copy_to_iter_full(buffer, n, to) != 0)
 		return -EFAULT;
 
 	return n;
@@ -254,10 +253,9 @@ static ssize_t cachefiles_do_daemon_read(struct cachefiles_cache *cache,
 /*
  * Read the cache state.
  */
-static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
-				      size_t buflen, loff_t *pos)
+static ssize_t cachefiles_daemon_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct cachefiles_cache *cache = file->private_data;
+	struct cachefiles_cache *cache = iocb->ki_filp->private_data;
 
 	//_enter(",,%zu,", buflen);
 
@@ -265,21 +263,20 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
 		return 0;
 
 	if (cachefiles_in_ondemand_mode(cache))
-		return cachefiles_ondemand_daemon_read(cache, _buffer, buflen);
+		return cachefiles_ondemand_daemon_read(cache, to);
 	else
-		return cachefiles_do_daemon_read(cache, _buffer, buflen);
+		return cachefiles_do_daemon_read(cache, to);
 }
 
 /*
  * Take a command from cachefilesd, parse it and act on it.
  */
-static ssize_t cachefiles_daemon_write(struct file *file,
-				       const char __user *_data,
-				       size_t datalen,
-				       loff_t *pos)
+static ssize_t cachefiles_daemon_write(struct kiocb *iocb,
+				       struct iov_iter *from)
 {
 	const struct cachefiles_daemon_cmd *cmd;
-	struct cachefiles_cache *cache = file->private_data;
+	struct cachefiles_cache *cache = iocb->ki_filp->private_data;
+	size_t datalen = iov_iter_count(from);
 	ssize_t ret;
 	char *data, *args, *cp;
 
@@ -294,7 +291,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
 		return -EOPNOTSUPP;
 
 	/* drag the command string into the kernel so we can parse it */
-	data = memdup_user_nul(_data, datalen);
+	data = iterdup_nul(from, datalen);
 	if (IS_ERR(data))
 		return PTR_ERR(data);
 
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index d33169f0018b..2b5565d38cb3 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -298,7 +298,7 @@ extern bool cachefiles_commit_tmpfile(struct cachefiles_cache *cache,
  */
 #ifdef CONFIG_CACHEFILES_ONDEMAND
 extern ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
-					char __user *_buffer, size_t buflen);
+					struct iov_iter *to);
 
 extern int cachefiles_ondemand_copen(struct cachefiles_cache *cache,
 				     char *args);
@@ -341,7 +341,7 @@ static inline bool cachefiles_ondemand_is_reopening_read(struct cachefiles_req *
 
 #else
 static inline ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
-					char __user *_buffer, size_t buflen)
+					struct iov_iter *to)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
index 4ba42f1fa3b4..e27144ff2050 100644
--- a/fs/cachefiles/ondemand.c
+++ b/fs/cachefiles/ondemand.c
@@ -295,8 +295,9 @@ static struct cachefiles_req *cachefiles_ondemand_select_req(struct xa_state *xa
 }
 
 ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
-					char __user *_buffer, size_t buflen)
+					struct iov_iter *to)
 {
+	size_t buflen = iov_iter_count(to);
 	struct cachefiles_req *req;
 	struct cachefiles_msg *msg;
 	unsigned long id = 0;
@@ -345,7 +346,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache,
 	msg->msg_id = id;
 	msg->object_id = req->object->ondemand->ondemand_id;
 
-	if (copy_to_user(_buffer, msg, n) != 0) {
+	if (!copy_to_iter_full(msg, n, to) != 0) {
 		ret = -EFAULT;
 		goto err_put_fd;
 	}
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ