From: Vasily Averin <v...@virtuozzo.com>

[ Upstream commit 89163f93c6f969da5811af5377cc10173583123b ]

If seq_file .next function does not change position index, read after
some lseek can generate unexpected output.

https://bugzilla.kernel.org/show_bug.cgi?id=206283
Signed-off-by: Vasily Averin <v...@virtuozzo.com>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Acked-by: Waiman Long <long...@redhat.com>
Cc: Davidlohr Bueso <d...@stgolabs.net>
Cc: Manfred Spraul <manf...@colorfullife.com>
Cc: Al Viro <v...@zeniv.linux.org.uk>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: NeilBrown <ne...@suse.com>
Cc: Peter Oberparleiter <ober...@linux.ibm.com>
Cc: Steven Rostedt <rost...@goodmis.org>
Link: 
http://lkml.kernel.org/r/b7a20945-e315-8bb0-21e6-3875c14a8...@virtuozzo.com
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 ipc/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ipc/util.c b/ipc/util.c
index 798cad18dd878..e65ecf3ccbdab 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -751,13 +751,13 @@ static struct kern_ipc_perm *sysvipc_find_ipc(struct 
ipc_ids *ids, loff_t pos,
                        total++;
        }
 
+       *new_pos = pos + 1;
        if (total >= ids->in_use)
                return NULL;
 
        for (; pos < IPCMNI; pos++) {
                ipc = idr_find(&ids->ipcs_idr, pos);
                if (ipc != NULL) {
-                       *new_pos = pos + 1;
                        rcu_read_lock();
                        ipc_lock_object(ipc);
                        return ipc;
-- 
2.20.1



Reply via email to