Skip to content

Commit 2a4a828

Browse files
Werkovgregkh
authored andcommitted
cgroup: Remove duplicates in cgroup v1 tasks file
commit 1ca0b60 upstream. One PID may appear multiple times in a preloaded pidlist. (Possibly due to PID recycling but we have reports of the same task_struct appearing with different PIDs, thus possibly involving transfer of PID via de_thread().) Because v1 seq_file iterator uses PIDs as position, it leads to a message: > seq_file: buggy .next function kernfs_seq_next did not update position index Conservative and quick fix consists of removing duplicates from `tasks` file (as opposed to removing pidlists altogether). It doesn't affect correctness (it's sufficient to show a PID once), performance impact would be hidden by unconditional sorting of the pidlist already in place (asymptotically). Link: https://lore.kernel.org/r/[email protected]/ Suggested-by: Firo Yang <[email protected]> Signed-off-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent da7ce52 commit 2a4a828

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernel/cgroup/cgroup-v1.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,9 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
361361
}
362362
css_task_iter_end(&it);
363363
length = n;
364-
/* now sort & (if procs) strip out duplicates */
364+
/* now sort & strip out duplicates (tgids or recycled thread PIDs) */
365365
sort(array, length, sizeof(pid_t), cmppid, NULL);
366-
if (type == CGROUP_FILE_PROCS)
367-
length = pidlist_uniq(array, length);
366+
length = pidlist_uniq(array, length);
368367

369368
l = cgroup_pidlist_find_create(cgrp, type);
370369
if (!l) {

0 commit comments

Comments
 (0)