All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Campos <rodrigo@sdfg.com.ar>
To: fstests@vger.kernel.org
Cc: Christian Brauner <brauner@kernel.org>,
	Giuseppe Scrivano <gscrivan@redhat.com>,
	Rodrigo Campos <rodrigo@sdfg.com.ar>
Subject: [PATCH v3 4/9] vfs: Fix race condition on get_userns_fd()
Date: Mon, 13 Mar 2023 20:03:25 +0100	[thread overview]
Message-ID: <20230313190330.94229-5-rodrigo@sdfg.com.ar> (raw)
In-Reply-To: <20230313190330.94229-1-rodrigo@sdfg.com.ar>

There is a race when we clone: we call a function that just returns
while at the same time we try to get the userns via /proc/pid/ns/user.
The thing is that when the function returns, in the kernel do_exit()
from kernel/exit.c is called, which calls exit_task_namespaces() to destroy
the namespaces.

So, let's wait indefinitely there and add an _exit() call to avoid
warnings. We are already sending a SIGKILL to this pid, so nothing else
remaining to not leak the process.

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>
Reviewed-by: Christian Brauner <brauner@kernel.org>
---
 src/vfs/utils.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git src/vfs/utils.c src/vfs/utils.c
index ea7536c1..2331a3b7 100644
--- src/vfs/utils.c
+++ src/vfs/utils.c
@@ -60,7 +60,9 @@ pid_t do_clone(int (*fn)(void *), void *arg, int flags)
 
 static int get_userns_fd_cb(void *data)
 {
-	return 0;
+	for (;;)
+		pause();
+	_exit(0);
 }
 
 int wait_for_pid(pid_t pid)
-- 
2.39.2


  parent reply	other threads:[~2023-03-13 19:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 19:03 [PATCH v3 0/9] Tests for idmapped tmpfs Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 1/9] vfs: Don't open-code safe_close() Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 2/9] vfs: Fix documentation typo Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 3/9] vfs: Use tabs to indent, not spaces Rodrigo Campos
2023-03-13 19:03 ` Rodrigo Campos [this message]
2023-03-13 19:03 ` [PATCH v3 5/9] vfs: Make switch_userns set PR_SET_DUMPABLE Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 6/9] vfs: Prepare tests in &s_idmapped_mounts to be reused inside a userns Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 7/9] vfs: Make idmapped core tests public Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 8/9] vfs: Export test_setup() and test_cleanup() Rodrigo Campos
2023-03-13 19:03 ` [PATCH v3 9/9] vfs: Add tmpfs tests for idmap mounts Rodrigo Campos
2023-03-14 10:39   ` Zorro Lang
2023-03-14 11:41     ` Rodrigo Campos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230313190330.94229-5-rodrigo@sdfg.com.ar \
    --to=rodrigo@sdfg.com.ar \
    --cc=brauner@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=gscrivan@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.