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-102-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:14:01 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 101/437] s390/dasd: convert to read/write iterators

Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/s390/block/dasd.c      | 34 +++++++++++++++++++++++++++-------
 drivers/s390/block/dasd_eer.c  | 12 ++++++------
 drivers/s390/block/dasd_int.h  |  1 +
 drivers/s390/block/dasd_proc.c |  2 +-
 4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 0a97cfedd706..789e8c47e6ee 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -897,6 +897,7 @@ void dasd_profile_off(struct dasd_profile *profile)
 	spin_unlock_bh(&profile->lock);
 }
 
+/* this can go away once proc is converted to ->write_iter() */
 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
 {
 	char *buffer;
@@ -916,18 +917,37 @@ char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
 	return buffer;
 }
 
-static ssize_t dasd_stats_write(struct file *file,
-				const char __user *user_buf,
-				size_t user_len, loff_t *pos)
+char *dasd_get_iter_string(struct iov_iter *from)
+{
+	size_t user_len = iov_iter_count(from);
+	char *buffer;
+
+	buffer = vmalloc(user_len + 1);
+	if (buffer == NULL)
+		return ERR_PTR(-ENOMEM);
+	if (!copy_from_iter_full(buffer, user_len, from)) {
+		vfree(buffer);
+		return ERR_PTR(-EFAULT);
+	}
+	/* got the string, now strip linefeed. */
+	if (buffer[user_len - 1] == '\n')
+		buffer[user_len - 1] = 0;
+	else
+		buffer[user_len] = 0;
+	return buffer;
+}
+
+static ssize_t dasd_stats_write(struct kiocb *iocb, struct iov_iter *from)
 {
 	char *buffer, *str;
 	int rc;
-	struct seq_file *m = (struct seq_file *)file->private_data;
+	struct seq_file *m = iocb->ki_filp->private_data;
 	struct dasd_profile *prof = m->private;
+	size_t user_len = iov_iter_count(from);
 
 	if (user_len > 65536)
 		user_len = 65536;
-	buffer = dasd_get_user_string(user_buf, user_len);
+	buffer = dasd_get_iter_string(from);
 	if (IS_ERR(buffer))
 		return PTR_ERR(buffer);
 
@@ -1042,10 +1062,10 @@ static int dasd_stats_open(struct inode *inode, struct file *file)
 static const struct file_operations dasd_stats_raw_fops = {
 	.owner		= THIS_MODULE,
 	.open		= dasd_stats_open,
-	.read		= seq_read,
+	.read_iter	= seq_read_iter,
 	.llseek		= seq_lseek,
 	.release	= single_release,
-	.write		= dasd_stats_write,
+	.write_iter	= dasd_stats_write,
 };
 
 static void dasd_profile_init(struct dasd_profile *profile,
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index 194e9e2d9cb8..476d6cf80089 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -592,15 +592,15 @@ static int dasd_eer_close(struct inode *inp, struct file *filp)
 	return 0;
 }
 
-static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
-			     size_t count, loff_t *ppos)
+static ssize_t dasd_eer_read(struct kiocb *iocb, struct iov_iter *to)
 {
+	size_t count = iov_iter_count(to);
 	int tc,rc;
 	int tailcount,effective_count;
         unsigned long flags;
 	struct eerbuffer *eerb;
 
-	eerb = (struct eerbuffer *) filp->private_data;
+	eerb = (struct eerbuffer *) iocb->ki_filp->private_data;
 	if (mutex_lock_interruptible(&readbuffer_mutex))
 		return -ERESTARTSYS;
 
@@ -625,7 +625,7 @@ static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
 				/* no data available */
 				spin_unlock_irqrestore(&bufferlock, flags);
 				mutex_unlock(&readbuffer_mutex);
-				if (filp->f_flags & O_NONBLOCK)
+				if (iocb->ki_filp->f_flags & O_NONBLOCK)
 					return -EAGAIN;
 				rc = wait_event_interruptible(
 					dasd_eer_read_wait_queue,
@@ -647,7 +647,7 @@ static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
 
 	spin_unlock_irqrestore(&bufferlock, flags);
 
-	if (copy_to_user(buf, readbuffer, effective_count)) {
+	if (!copy_to_iter_full(readbuffer, effective_count, to)) {
 		mutex_unlock(&readbuffer_mutex);
 		return -EFAULT;
 	}
@@ -676,7 +676,7 @@ static __poll_t dasd_eer_poll(struct file *filp, poll_table *ptable)
 static const struct file_operations dasd_eer_fops = {
 	.open		= &dasd_eer_open,
 	.release	= &dasd_eer_close,
-	.read		= &dasd_eer_read,
+	.read_iter	= &dasd_eer_read,
 	.poll		= &dasd_eer_poll,
 	.owner		= THIS_MODULE,
 	.llseek		= noop_llseek,
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index e5f40536b425..be7d6875b054 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -897,6 +897,7 @@ void dasd_profile_reset(struct dasd_profile *);
 int dasd_profile_on(struct dasd_profile *);
 void dasd_profile_off(struct dasd_profile *);
 char *dasd_get_user_string(const char __user *, size_t);
+char *dasd_get_iter_string(struct iov_iter *);
 
 /* externals in dasd_devmap.c */
 extern int dasd_max_devindex;
diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c
index 0faaa437d9be..b97d1227b9b0 100644
--- a/drivers/s390/block/dasd_proc.c
+++ b/drivers/s390/block/dasd_proc.c
@@ -317,7 +317,7 @@ static ssize_t dasd_stats_proc_write(struct file *file,
 
 static const struct proc_ops dasd_stats_proc_ops = {
 	.proc_open	= dasd_stats_proc_open,
-	.proc_read	= seq_read,
+	.proc_read_iter	= seq_read_iter,
 	.proc_lseek	= seq_lseek,
 	.proc_release	= single_release,
 	.proc_write	= dasd_stats_proc_write,
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ