Merge tag 'for-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux...
[linux-2.6-microblaze.git] / kernel / bpf / task_iter.c
index 99af4ce..5b6af30 100644 (file)
@@ -22,7 +22,8 @@ struct bpf_iter_seq_task_info {
 };
 
 static struct task_struct *task_seq_get_next(struct pid_namespace *ns,
-                                            u32 *tid)
+                                            u32 *tid,
+                                            bool skip_if_dup_files)
 {
        struct task_struct *task = NULL;
        struct pid *pid;
@@ -36,6 +37,12 @@ retry:
                if (!task) {
                        ++*tid;
                        goto retry;
+               } else if (skip_if_dup_files && task->tgid != task->pid &&
+                          task->files == task->group_leader->files) {
+                       put_task_struct(task);
+                       task = NULL;
+                       ++*tid;
+                       goto retry;
                }
        }
        rcu_read_unlock();
@@ -48,7 +55,7 @@ static void *task_seq_start(struct seq_file *seq, loff_t *pos)
        struct bpf_iter_seq_task_info *info = seq->private;
        struct task_struct *task;
 
-       task = task_seq_get_next(info->common.ns, &info->tid);
+       task = task_seq_get_next(info->common.ns, &info->tid, false);
        if (!task)
                return NULL;
 
@@ -65,7 +72,7 @@ static void *task_seq_next(struct seq_file *seq, void *v, loff_t *pos)
        ++*pos;
        ++info->tid;
        put_task_struct((struct task_struct *)v);
-       task = task_seq_get_next(info->common.ns, &info->tid);
+       task = task_seq_get_next(info->common.ns, &info->tid, false);
        if (!task)
                return NULL;
 
@@ -148,7 +155,7 @@ again:
                curr_files = *fstruct;
                curr_fd = info->fd;
        } else {
-               curr_task = task_seq_get_next(ns, &curr_tid);
+               curr_task = task_seq_get_next(ns, &curr_tid, true);
                if (!curr_task)
                        return NULL;