On Fri, Nov 10, 2017 at 2:14 AM, Rich Felker <[email protected]> wrote:
> On Wed, Nov 08, 2017 at 02:10:05PM +0100, Szabolcs Nagy wrote:
>>
>> this patch broke userspace abi:
>>
>> commit e522751d605d99a81508e58390a8f51ee96fb662
>
> Thanks for reporting this!

Thanks for the report and the reproducer.

Tested fix attached.

Thanks,
Miklos
From: Miklos Szeredi <[email protected]>
Subject: seq_file: fix incomplete reset on read from zero offset

When resetting iterator on a zero offset we need to discard any data
already in the buffer (count), and private state of the iterator (version).

For example this bug results in first line being repeated in /proc/mounts
if doing a zero size read before a non-zero size read.

Reported-by: Rich Felker <[email protected]> 
Signed-off-by: Miklos Szeredi <[email protected]>
Fixes: e522751d605d ("seq_file: reset iterator to first record for zero offset")
Cc: <[email protected]> # v4.10
---
 fs/seq_file.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -181,8 +181,11 @@ ssize_t seq_read(struct file *file, char
 	 * if request is to read from zero offset, reset iterator to first
 	 * record as it might have been already advanced by previous requests
 	 */
-	if (*ppos == 0)
+	if (*ppos == 0) {
 		m->index = 0;
+		m->version = 0;
+		m->count = 0;
+	}
 
 	/* Don't assume *ppos is where we left it */
 	if (unlikely(*ppos != m->read_pos)) {

Reply via email to