Skip to content

Commit 2d4ecb0

Browse files
vaverinhtejun
authored andcommitted
cgroup: cgroup_procs_next should increase position index
If seq_file .next fuction does not change position index, read after some lseek can generate unexpected output: 1) dd bs=1 skip output of each 2nd elements $ dd if=/sys/fs/cgroup/cgroup.procs bs=8 count=1 2 3 4 5 1+0 records in 1+0 records out 8 bytes copied, 0,000267297 s, 29,9 kB/s [test@localhost ~]$ dd if=/sys/fs/cgroup/cgroup.procs bs=1 count=8 2 4 <<< NB! 3 was skipped 6 <<< ... and 5 too 8 <<< ... and 7 8+0 records in 8+0 records out 8 bytes copied, 5,2123e-05 s, 153 kB/s This happen because __cgroup_procs_start() makes an extra extra cgroup_procs_next() call 2) read after lseek beyond end of file generates whole last line. 3) read after lseek into middle of last line generates expected rest of last line and unexpected whole line once again. Additionally patch removes an extra position index changes in __cgroup_procs_start() Cc: [email protected] https://bugzilla.kernel.org/show_bug.cgi?id=206283 Signed-off-by: Vasily Averin <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent db8dd96 commit 2d4ecb0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/cgroup/cgroup.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,9 @@ static void *cgroup_procs_next(struct seq_file *s, void *v, loff_t *pos)
45954595
struct kernfs_open_file *of = s->private;
45964596
struct css_task_iter *it = of->priv;
45974597

4598+
if (pos)
4599+
(*pos)++;
4600+
45984601
return css_task_iter_next(it);
45994602
}
46004603

@@ -4610,18 +4613,19 @@ static void *__cgroup_procs_start(struct seq_file *s, loff_t *pos,
46104613
* from position 0, so we can simply keep iterating on !0 *pos.
46114614
*/
46124615
if (!it) {
4613-
if (WARN_ON_ONCE((*pos)++))
4616+
if (WARN_ON_ONCE((*pos)))
46144617
return ERR_PTR(-EINVAL);
46154618

46164619
it = kzalloc(sizeof(*it), GFP_KERNEL);
46174620
if (!it)
46184621
return ERR_PTR(-ENOMEM);
46194622
of->priv = it;
46204623
css_task_iter_start(&cgrp->self, iter_flags, it);
4621-
} else if (!(*pos)++) {
4624+
} else if (!(*pos)) {
46224625
css_task_iter_end(it);
46234626
css_task_iter_start(&cgrp->self, iter_flags, it);
4624-
}
4627+
} else
4628+
return it->cur_task;
46254629

46264630
return cgroup_procs_next(s, NULL, NULL);
46274631
}

0 commit comments

Comments
 (0)