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>] [day] [month] [year] [list]
Date:   Tue, 8 Oct 2019 19:02:05 -0700
From:   Vito Caputo <vcaputo@...garu.com>
To:     viro@...iv.linux.org.uk
Cc:     linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] seq_file: move seq_read() flushing into a function

Consolidate some duplicated bookkeeping from seq_read() into a
function.

Signed-off-by: Vito Caputo <vcaputo@...garu.com>
---
 fs/seq_file.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1600034a929b..e5d2bccf5ac4 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -141,6 +141,25 @@ static int traverse(struct seq_file *m, loff_t offset)
 	return !m->buf ? -ENOMEM : -EAGAIN;
 }
 
+static int flush(struct seq_file *m, char __user **buf, size_t *size, size_t *copied)
+{
+	int err = 0;
+	size_t n;
+
+	if (!m->count)
+		return err;
+	n = min(m->count, *size);
+	err = copy_to_user(*buf, m->buf + m->from, n);
+	if (err)
+		return err;
+	m->count -= n;
+	m->from += n;
+	*size -= n;
+	*buf += n;
+	*copied += n;
+	return err;
+}
+
 /**
  *	seq_read -	->read() method for sequential files.
  *	@file: the file to read from
@@ -154,7 +173,6 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 {
 	struct seq_file *m = file->private_data;
 	size_t copied = 0;
-	size_t n;
 	void *p;
 	int err = 0;
 
@@ -207,15 +225,9 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 	}
 	/* if not empty - flush it first */
 	if (m->count) {
-		n = min(m->count, size);
-		err = copy_to_user(buf, m->buf + m->from, n);
+		err = flush(m, &buf, &size, &copied);
 		if (err)
 			goto Efault;
-		m->count -= n;
-		m->from += n;
-		size -= n;
-		buf += n;
-		copied += n;
 		if (!size)
 			goto Done;
 	}
@@ -273,13 +285,9 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 		}
 	}
 	m->op->stop(m, p);
-	n = min(m->count, size);
-	err = copy_to_user(buf, m->buf, n);
+	err = flush(m, &buf, &size, &copied);
 	if (err)
 		goto Efault;
-	copied += n;
-	m->count -= n;
-	m->from = n;
 Done:
 	if (!copied)
 		copied = err;
-- 
2.11.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ