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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-47-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:13:06 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 046/437] dlm: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 fs/dlm/debug_fs.c | 41 +++++++++++++++++++----------------------
 fs/dlm/plock.c    | 16 ++++++++--------
 fs/dlm/user.c     | 17 +++++++++--------
 3 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index 1236e8d13453..2207cd83ab09 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -700,10 +700,10 @@ static int table_open2(struct inode *inode, struct file *file)
 	return 0;
 }
 
-static ssize_t table_write2(struct file *file, const char __user *user_buf,
-			    size_t count, loff_t *ppos)
+static ssize_t table_write2(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct seq_file *seq = file->private_data;
+	struct seq_file *seq = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	int n, len, lkb_nodeid, lkb_status, error;
 	char name[DLM_RESNAME_MAXLEN + 1] = {};
 	struct dlm_ls *ls = seq->private;
@@ -711,8 +711,7 @@ static ssize_t table_write2(struct file *file, const char __user *user_buf,
 	char buf[256] = {};
 	uint32_t lkb_id;
 
-	if (copy_from_user(buf, user_buf,
-			   min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	n = sscanf(buf, "%x %" __stringify(DLM_RESNAME_MAXLEN) "s %x %d %d",
@@ -783,7 +782,7 @@ static const struct file_operations format2_fops = {
 	.owner   = THIS_MODULE,
 	.open    = table_open2,
 	.read_iter    = seq_read_iter,
-	.write   = table_write2,
+	.write_iter   = table_write2,
 	.llseek  = seq_lseek,
 	.release = seq_release
 };
@@ -815,10 +814,9 @@ static const struct file_operations format5_fops = {
 /*
  * dump lkb's on the ls_waiters list
  */
-static ssize_t waiters_read(struct file *file, char __user *userbuf,
-			    size_t count, loff_t *ppos)
+static ssize_t waiters_read(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct dlm_ls *ls = file->private_data;
+	struct dlm_ls *ls = iocb->ki_filp->private_data;
 	struct dlm_lkb *lkb;
 	size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
 
@@ -836,22 +834,21 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf,
 	}
 	mutex_unlock(&ls->ls_waiters_mutex);
 
-	rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos);
+	rv = simple_copy_to_iter(debug_buf, &iocb->ki_pos, pos, to);
 	mutex_unlock(&debug_buf_lock);
 	return rv;
 }
 
-static ssize_t waiters_write(struct file *file, const char __user *user_buf,
-			     size_t count, loff_t *ppos)
+static ssize_t waiters_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct dlm_ls *ls = file->private_data;
+	struct dlm_ls *ls = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	int mstype, to_nodeid;
 	char buf[128] = {};
 	uint32_t lkb_id;
 	int n, error;
 
-	if (copy_from_user(buf, user_buf,
-			   min_t(size_t, sizeof(buf) - 1, count)))
+	if (!copy_from_iter_full(buf, min_t(size_t, sizeof(buf) - 1, count), from))
 		return -EFAULT;
 
 	n = sscanf(buf, "%x %d %d", &lkb_id, &mstype, &to_nodeid);
@@ -868,8 +865,8 @@ static ssize_t waiters_write(struct file *file, const char __user *user_buf,
 static const struct file_operations waiters_fops = {
 	.owner   = THIS_MODULE,
 	.open    = simple_open,
-	.read    = waiters_read,
-	.write   = waiters_write,
+	.read_iter    = waiters_read,
+	.write_iter   = waiters_write,
 	.llseek  = default_llseek,
 };
 
@@ -911,9 +908,9 @@ static int dlm_version_show(struct seq_file *file, void *offset)
 }
 DEFINE_SHOW_ATTRIBUTE(dlm_version);
 
-static ssize_t dlm_rawmsg_write(struct file *fp, const char __user *user_buf,
-				size_t count, loff_t *ppos)
+static ssize_t dlm_rawmsg_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	void *buf;
 	int ret;
 
@@ -924,12 +921,12 @@ static ssize_t dlm_rawmsg_write(struct file *fp, const char __user *user_buf,
 	if (!buf)
 		return -ENOMEM;
 
-	if (copy_from_user(buf, user_buf, count)) {
+	if (!copy_from_iter_full(buf, count, from)) {
 		ret = -EFAULT;
 		goto out;
 	}
 
-	ret = dlm_midcomms_rawmsg_send(fp->private_data, buf, count);
+	ret = dlm_midcomms_rawmsg_send(iocb->ki_filp->private_data, buf, count);
 	if (ret)
 		goto out;
 
@@ -943,7 +940,7 @@ static ssize_t dlm_rawmsg_write(struct file *fp, const char __user *user_buf,
 
 static const struct file_operations dlm_rawmsg_fops = {
 	.open	= simple_open,
-	.write	= dlm_rawmsg_write,
+	.write_iter	= dlm_rawmsg_write,
 	.llseek	= no_llseek,
 };
 
diff --git a/fs/dlm/plock.c b/fs/dlm/plock.c
index 9ca83ef70ed1..f6d00f39f991 100644
--- a/fs/dlm/plock.c
+++ b/fs/dlm/plock.c
@@ -478,9 +478,9 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,
 EXPORT_SYMBOL_GPL(dlm_posix_get);
 
 /* a read copies out one plock request from the send list */
-static ssize_t dev_read(struct file *file, char __user *u, size_t count,
-			loff_t *ppos)
+static ssize_t dev_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	struct dlm_plock_info info;
 	struct plock_op *op = NULL;
 
@@ -510,16 +510,16 @@ static ssize_t dev_read(struct file *file, char __user *u, size_t count,
 	if (op->info.flags & DLM_PLOCK_FL_CLOSE)
 		dlm_release_plock_op(op);
 
-	if (copy_to_user(u, &info, sizeof(info)))
+	if (!copy_to_iter_full(&info, sizeof(info), to))
 		return -EFAULT;
 	return sizeof(info);
 }
 
 /* a write copies in one plock result that should match a plock_op
    on the recv list */
-static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
-			 loff_t *ppos)
+static ssize_t dev_write(struct kiocb *iocb, struct iov_iter *from)
 {
+	size_t count = iov_iter_count(from);
 	struct plock_op *op = NULL, *iter;
 	struct dlm_plock_info info;
 	int do_callback = 0;
@@ -527,7 +527,7 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
 	if (count != sizeof(info))
 		return -EINVAL;
 
-	if (copy_from_user(&info, u, sizeof(info)))
+	if (!copy_from_iter_full(&info, sizeof(info), from))
 		return -EFAULT;
 
 	trace_dlm_plock_write(&info);
@@ -598,8 +598,8 @@ static __poll_t dev_poll(struct file *file, poll_table *wait)
 }
 
 static const struct file_operations dev_fops = {
-	.read    = dev_read,
-	.write   = dev_write,
+	.read_iter    = dev_read,
+	.write_iter   = dev_write,
 	.poll    = dev_poll,
 	.owner   = THIS_MODULE,
 	.llseek  = noop_llseek,
diff --git a/fs/dlm/user.c b/fs/dlm/user.c
index 9f9b68448830..362c9998929e 100644
--- a/fs/dlm/user.c
+++ b/fs/dlm/user.c
@@ -524,10 +524,10 @@ static int check_version(struct dlm_write_request *req)
 /* a write to a lockspace device is a lock or unlock request, a write
    to the control device is to create/remove a lockspace */
 
-static ssize_t device_write(struct file *file, const char __user *buf,
-			    size_t count, loff_t *ppos)
+static ssize_t device_write(struct kiocb *iocb, struct iov_iter *from)
 {
-	struct dlm_user_proc *proc = file->private_data;
+	struct dlm_user_proc *proc = iocb->ki_filp->private_data;
+	size_t count = iov_iter_count(from);
 	struct dlm_write_request *kbuf;
 	int error;
 
@@ -545,7 +545,7 @@ static ssize_t device_write(struct file *file, const char __user *buf,
 	if (count > sizeof(struct dlm_write_request) + DLM_RESNAME_MAXLEN)
 		return -EINVAL;
 
-	kbuf = memdup_user_nul(buf, count);
+	kbuf = iterdup_nul(from, count);
 	if (IS_ERR(kbuf))
 		return PTR_ERR(kbuf);
 
@@ -918,6 +918,7 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count,
 
 	return ret;
 }
+FOPS_READ_ITER_HELPER(device_read);
 
 static __poll_t device_poll(struct file *file, poll_table *wait)
 {
@@ -982,8 +983,8 @@ static int monitor_device_close(struct inode *inode, struct file *file)
 static const struct file_operations device_fops = {
 	.open    = device_open,
 	.release = device_close,
-	.read    = device_read,
-	.write   = device_write,
+	.read_iter    = device_read_iter,
+	.write_iter   = device_write,
 	.poll    = device_poll,
 	.owner   = THIS_MODULE,
 	.llseek  = noop_llseek,
@@ -992,8 +993,8 @@ static const struct file_operations device_fops = {
 static const struct file_operations ctl_device_fops = {
 	.open    = ctl_device_open,
 	.release = ctl_device_close,
-	.read    = device_read,
-	.write   = device_write,
+	.read_iter    = device_read_iter,
+	.write_iter   = device_write,
 	.owner   = THIS_MODULE,
 	.llseek  = noop_llseek,
 };
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ