]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ipv6_route_seq_next should increase position index
authorVasily Averin <vvs@virtuozzo.com>
Thu, 23 Jan 2020 07:12:06 +0000 (10:12 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 24 Jan 2020 10:42:18 +0000 (11:42 +0100)
if seq_file .next fuction 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 <vvs@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ip6_fib.c

index 7bae6a91b48726173ef285e0449a4bcb29d75993..cfae0a1529a1dc14e1494177f9978451d6d9e5f5 100644 (file)
@@ -2495,14 +2495,13 @@ static void *ipv6_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
        struct net *net = seq_file_net(seq);
        struct ipv6_route_iter *iter = seq->private;
 
+       ++(*pos);
        if (!v)
                goto iter_table;
 
        n = rcu_dereference_bh(((struct fib6_info *)v)->fib6_next);
-       if (n) {
-               ++*pos;
+       if (n)
                return n;
-       }
 
 iter_table:
        ipv6_route_check_sernum(iter);
@@ -2510,8 +2509,6 @@ static void *ipv6_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
        r = fib6_walk_continue(&iter->w);
        spin_unlock_bh(&iter->tbl->tb6_lock);
        if (r > 0) {
-               if (v)
-                       ++*pos;
                return iter->w.leaf;
        } else if (r < 0) {
                fib6_walker_unlink(net, &iter->w);