All of lore.kernel.org
 help / color / mirror / Atom feed
* + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree
@ 2021-09-29 23:20 akpm
  2021-10-07 18:27 ` [PATCH] proc: test that /proc/*/task doesn't contain "0" Alexey Dobriyan
  2021-10-07 18:28 ` + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree Alexey Dobriyan
  0 siblings, 2 replies; 5+ messages in thread
From: akpm @ 2021-09-29 23:20 UTC (permalink / raw)
  To: adobriyan, christian.brauner, ebiederm, fweimer, keescook, mm-commits


The patch titled
     Subject: procfs: do not list TID 0 in /proc/<pid>/task
has been added to the -mm tree.  Its filename is
     procfs-do-not-list-tid-0-in-proc-pid-task.patch

This patch should soon appear at
    https://ozlabs.org/~akpm/mmots/broken-out/procfs-do-not-list-tid-0-in-proc-pid-task.patch
and later at
    https://ozlabs.org/~akpm/mmotm/broken-out/procfs-do-not-list-tid-0-in-proc-pid-task.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Florian Weimer <fweimer@redhat.com>
Subject: procfs: do not list TID 0 in /proc/<pid>/task

If a task exits concurrently, task_pid_nr_ns may return 0.

Link: https://lkml.kernel.org/r/8735pn5dx7.fsf@oldenburg.str.redhat.com
Signed-off-by: Florian Weimer <fweimer@redhat.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/proc/base.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/fs/proc/base.c~procfs-do-not-list-tid-0-in-proc-pid-task
+++ a/fs/proc/base.c
@@ -3800,6 +3800,9 @@ static int proc_task_readdir(struct file
 		char name[10 + 1];
 		unsigned int len;
 		tid = task_pid_nr_ns(task, ns);
+		if (!tid)
+			/* The task has just exited. */
+			continue;
 		len = snprintf(name, sizeof(name), "%u", tid);
 		if (!proc_fill_cache(file, ctx, name, len,
 				proc_task_instantiate, task, NULL)) {
_

Patches currently in -mm which might be from fweimer@redhat.com are

procfs-do-not-list-tid-0-in-proc-pid-task.patch


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] proc: test that /proc/*/task doesn't contain "0"
  2021-09-29 23:20 + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree akpm
@ 2021-10-07 18:27 ` Alexey Dobriyan
  2021-10-07 18:52   ` Andrew Morton
  2021-10-07 18:28 ` + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree Alexey Dobriyan
  1 sibling, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2021-10-07 18:27 UTC (permalink / raw)
  To: akpm; +Cc: christian.brauner, ebiederm, fweimer, keescook, linux-kernel

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 tools/testing/selftests/proc/.gitignore  |    1 
 tools/testing/selftests/proc/Makefile    |    2 
 tools/testing/selftests/proc/proc-tid0.c |   81 +++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)

--- a/tools/testing/selftests/proc/.gitignore
+++ b/tools/testing/selftests/proc/.gitignore
@@ -11,6 +11,7 @@
 /proc-self-syscall
 /proc-self-wchan
 /proc-subset-pid
+/proc-tid0
 /proc-uptime-001
 /proc-uptime-002
 /read
--- a/tools/testing/selftests/proc/Makefile
+++ b/tools/testing/selftests/proc/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 CFLAGS += -Wall -O2 -Wno-unused-function
 CFLAGS += -D_GNU_SOURCE
+LDFLAGS += -pthread
 
 TEST_GEN_PROGS :=
 TEST_GEN_PROGS += fd-001-lookup
@@ -13,6 +14,7 @@ TEST_GEN_PROGS += proc-self-map-files-002
 TEST_GEN_PROGS += proc-self-syscall
 TEST_GEN_PROGS += proc-self-wchan
 TEST_GEN_PROGS += proc-subset-pid
+TEST_GEN_PROGS += proc-tid0
 TEST_GEN_PROGS += proc-uptime-001
 TEST_GEN_PROGS += proc-uptime-002
 TEST_GEN_PROGS += read
new file mode 100644
--- /dev/null
+++ b/tools/testing/selftests/proc/proc-tid0.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 Alexey Dobriyan <adobriyan@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+// Test that /proc/*/task never contains "0".
+#include <sys/types.h>
+#include <dirent.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+
+static pid_t pid = -1;
+
+static void atexit_hook(void)
+{
+	if (pid > 0) {
+		kill(pid, SIGKILL);
+	}
+}
+
+static void *f(void *_)
+{
+	return NULL;
+}
+
+static void sigalrm(int _)
+{
+	exit(0);
+}
+
+int main(void)
+{
+	pid = fork();
+	if (pid == 0) {
+		/* child */
+		while (1) {
+			pthread_t pth;
+			pthread_create(&pth, NULL, f, NULL);
+			pthread_join(pth, NULL);
+		}
+	} else if (pid > 0) {
+		/* parent */
+		atexit(atexit_hook);
+
+		char buf[64];
+		snprintf(buf, sizeof(buf), "/proc/%u/task", pid);
+
+		signal(SIGALRM, sigalrm);
+		alarm(1);
+
+		while (1) {
+			DIR *d = opendir(buf);
+			struct dirent *de;
+			while ((de = readdir(d))) {
+				if (strcmp(de->d_name, "0") == 0) {
+					exit(1);
+				}
+			}
+			closedir(d);
+		}
+
+		return 0;
+	} else {
+		perror("fork");
+		return 1;
+	}
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree
  2021-09-29 23:20 + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree akpm
  2021-10-07 18:27 ` [PATCH] proc: test that /proc/*/task doesn't contain "0" Alexey Dobriyan
@ 2021-10-07 18:28 ` Alexey Dobriyan
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2021-10-07 18:28 UTC (permalink / raw)
  To: akpm; +Cc: christian.brauner, ebiederm, fweimer, keescook, mm-commits

On Wed, Sep 29, 2021 at 04:20:38PM -0700, akpm@linux-foundation.org wrote:
> Subject: procfs: do not list TID 0 in /proc/<pid>/task
> 
> If a task exits concurrently, task_pid_nr_ns may return 0.

So easy to reproduce, wonder why didn't anyone report it earlier.

Reviewed-by: Alexey Dobriyan <adobriyan@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] proc: test that /proc/*/task doesn't contain "0"
  2021-10-07 18:27 ` [PATCH] proc: test that /proc/*/task doesn't contain "0" Alexey Dobriyan
@ 2021-10-07 18:52   ` Andrew Morton
  2021-10-07 19:11     ` Alexey Dobriyan
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2021-10-07 18:52 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: christian.brauner, ebiederm, fweimer, keescook, linux-kernel

On Thu, 7 Oct 2021 21:27:14 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:

Could we please have a changelog :(

Why are we doing this?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] proc: test that /proc/*/task doesn't contain "0"
  2021-10-07 18:52   ` Andrew Morton
@ 2021-10-07 19:11     ` Alexey Dobriyan
  0 siblings, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2021-10-07 19:11 UTC (permalink / raw)
  To: Andrew Morton
  Cc: christian.brauner, ebiederm, fweimer, keescook, linux-kernel

On Thu, Oct 07, 2021 at 11:52:37AM -0700, Andrew Morton wrote:
> On Thu, 7 Oct 2021 21:27:14 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> Could we please have a changelog :(
> 
> Why are we doing this?

This can be folded into

	procfs-do-not-list-tid-0-in-proc-pid-task.patch

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-07 19:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 23:20 + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree akpm
2021-10-07 18:27 ` [PATCH] proc: test that /proc/*/task doesn't contain "0" Alexey Dobriyan
2021-10-07 18:52   ` Andrew Morton
2021-10-07 19:11     ` Alexey Dobriyan
2021-10-07 18:28 ` + procfs-do-not-list-tid-0-in-proc-pid-task.patch added to -mm tree Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.