table_seq_next should increase position index
PATCH 1/1 table_seq_next should increase position index
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
--- fs/dlm/debug_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dlm/debug_fs.c +2 -1
@@ -523,7 +523,7 @@ static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos) ri->rsb = r;spin_unlock (&ls->ls_rsbtbl[bucket].lock);dlm_put_rsb (rp); - ++*pos; + ++(*pos);return ri; }spin_unlock (&ls->ls_rsbtbl[bucket].lock);
@@ -542,6 +542,7 @@ static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)if (bucket >= ls->ls_rsbtbl_size) {kfree (ri); + ++(*pos);return NULL ; } tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
Signature · 1 line
1.8.3.1
PATCH 1/1 table_seq_next should increase position index
Could I get any comments?
Unfortunately I do not have enough experience with dlm and cannot verify the patch locally
Usually you can observe following related problems:
- read after lseek beyond end of file, described by NeilBrown in
commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") "dd if=<AFFECTED_FILE> bs=1000 skip=1" will incorrectly generate whole last line
- read after lseek on into middle of last line will output expected rest of last line but then repeat whole last line once again.
- If .show() function generates multi-line output following bash script will never finish.
$ q=;while read -r r;do echo "$((++q)) $r";done < AFFECTED_FILE
Thank you,
Vasily Averin
Quoted 31 lines · Vasily Averin
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 <[email protected]>--- fs/dlm/debug_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/dlm/debug_fs.c +2
-1@@ -523,7 +523,7 @@ static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos) ri->rsb = r;spin_unlock (&ls->ls_rsbtbl[bucket].lock);dlm_put_rsb (rp); - ++*pos; + ++(*pos);return ri; }spin_unlock (&ls->ls_rsbtbl[bucket].lock);@@ -542,6 +542,7 @@ static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)if (bucket >= ls->ls_rsbtbl_size) {kfree (ri); + ++(*pos);return NULL ; } tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;