Skip to content

Commit 623c8d5

Browse files
committed
Merge branch 'netdev-seq_file-next-functions-should-increase-position-index'
Vasily Averin says: ==================== netdev: seq_file .next functions should increase position index In Aug 2018 NeilBrown noticed commit 1f4aace ("fs/seq_file.c: simplify seq_file iteration code and interface") "Some ->next functions do not increment *pos when they return NULL... Note that such ->next functions are buggy and should be fixed. A simple demonstration is dd if=/proc/swaps bs=1000 skip=1 Choose any block size larger than the size of /proc/swaps. This will always show the whole last line of /proc/swaps" Described problem is still actual. If you make lseek into middle of last output line following read will output end of last line and whole last line once again. $ dd if=/proc/swaps bs=1 # usual output Filename Type Size Used Priority /dev/dm-0 partition 4194812 97536 -2 104+0 records in 104+0 records out 104 bytes copied $ dd if=/proc/swaps bs=40 skip=1 # last line was generated twice dd: /proc/swaps: cannot skip to specified offset v/dm-0 partition 4194812 97536 -2 /dev/dm-0 partition 4194812 97536 -2 3+1 records in 3+1 records out 131 bytes copied There are lot of other affected files, I've found 30+ including /proc/net/ip_tables_matches and /proc/sysvipc/* This patch-set fixes files related to netdev@ https://bugzilla.kernel.org/show_bug.cgi?id=206283 ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 2bec445 + 4fc427e commit 623c8d5

6 files changed

Lines changed: 7 additions & 11 deletions

File tree

‎drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
7070
static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
7171
{
7272
v = seq_tab_get_idx(seq->private, *pos + 1);
73-
if (v)
74-
++*pos;
73+
++(*pos);
7574
return v;
7675
}
7776

‎drivers/net/ethernet/chelsio/cxgb4/l2t.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,7 @@ static void *l2t_seq_start(struct seq_file *seq, loff_t *pos)
678678
static void *l2t_seq_next(struct seq_file *seq, void *v, loff_t *pos)
679679
{
680680
v = l2t_get_idx(seq, *pos);
681-
if (v)
682-
++*pos;
681+
++(*pos);
683682
return v;
684683
}
685684

‎net/atm/proc.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ static void vcc_seq_stop(struct seq_file *seq, void *v)
134134
static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
135135
{
136136
v = vcc_walk(seq, 1);
137-
if (v)
138-
(*pos)++;
137+
(*pos)++;
139138
return v;
140139
}
141140

‎net/core/neighbour.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,6 +3290,7 @@ static void *neigh_stat_seq_next(struct seq_file *seq, void *v, loff_t *pos)
32903290
*pos = cpu+1;
32913291
return per_cpu_ptr(tbl->stats, cpu);
32923292
}
3293+
(*pos)++;
32933294
return NULL;
32943295
}
32953296

‎net/ipv4/route.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ static void *rt_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
271271
*pos = cpu+1;
272272
return &per_cpu(rt_cache_stat, cpu);
273273
}
274+
(*pos)++;
274275
return NULL;
275276

276277
}

‎net/ipv6/ip6_fib.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,23 +2495,20 @@ static void *ipv6_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
24952495
struct net *net = seq_file_net(seq);
24962496
struct ipv6_route_iter *iter = seq->private;
24972497

2498+
++(*pos);
24982499
if (!v)
24992500
goto iter_table;
25002501

25012502
n = rcu_dereference_bh(((struct fib6_info *)v)->fib6_next);
2502-
if (n) {
2503-
++*pos;
2503+
if (n)
25042504
return n;
2505-
}
25062505

25072506
iter_table:
25082507
ipv6_route_check_sernum(iter);
25092508
spin_lock_bh(&iter->tbl->tb6_lock);
25102509
r = fib6_walk_continue(&iter->w);
25112510
spin_unlock_bh(&iter->tbl->tb6_lock);
25122511
if (r > 0) {
2513-
if (v)
2514-
++*pos;
25152512
return iter->w.leaf;
25162513
} else if (r < 0) {
25172514
fib6_walker_unlink(net, &iter->w);

0 commit comments

Comments
 (0)