fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rodrigo Campos <rodrigo@sdfg.com.ar>
To: Christian Brauner <brauner@kernel.org>
Cc: fstests@vger.kernel.org, Giuseppe Scrivano <gscrivan@redhat.com>
Subject: Re: [PATCH 03/11] vfs: Fix race condition on get_userns_fd()
Date: Tue, 7 Mar 2023 18:32:08 +0100	[thread overview]
Message-ID: <ed07090b-a5a7-513a-aa14-3ef32aaee55e@sdfg.com.ar> (raw)
In-Reply-To: <20230307164604.guofenicecdtlsxl@wittgenstein>

On 3/7/23 17:46, Christian Brauner wrote:
> On Tue, Mar 07, 2023 at 12:44:59PM +0100, Rodrigo Campos wrote:
>> Talking with Christian Brauner about a different problem, he mentioned
>> that technically this race condition exists and we should fix it.
>>
>> The race is that 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, while the pid needs to be reaped, Christian said that
>> the userns file cease to exist as soon as the program finishes.
> 
> See exit_task_namespaces() in kernel/exit.c:do_exit().

Cool, thanks! Added that instead, then :)


>> So, let's make the function never return, so we always can get the
>> userns. 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>
>> ---
>>   src/vfs/utils.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git src/vfs/utils.c src/vfs/utils.c
>> index ea7536c1..67779e83 100644
>> --- src/vfs/utils.c
>> +++ src/vfs/utils.c
>> @@ -58,9 +58,10 @@ pid_t do_clone(int (*fn)(void *), void *arg, int flags)
>>   #endif
>>   }
>>   
>> -static int get_userns_fd_cb(void *data)
>> +__attribute__((noreturn)) static int get_userns_fd_cb(void *data)
>>   {
>> -	return 0;
>> +	for (;;)
>> +		pause();
> 
> Should this add a _exit(0)? It's pretty odd otherwise. And do we need
> noreturn?

Agree, let's do that and remove the attribute.

  reply	other threads:[~2023-03-07 17:36 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 11:44 [PATCH 00/11] Tests for idmapped tmpfs Rodrigo Campos
2023-03-07 11:44 ` [PATCH 01/11] vfs: Don't open-code safe_close() Rodrigo Campos
2023-03-07 16:42   ` Christian Brauner
2023-03-07 11:44 ` [PATCH 02/11] vfs: Fix documentation typo Rodrigo Campos
2023-03-07 16:43   ` Christian Brauner
2023-03-07 11:44 ` [PATCH 03/11] vfs: Fix race condition on get_userns_fd() Rodrigo Campos
2023-03-07 16:46   ` Christian Brauner
2023-03-07 17:32     ` Rodrigo Campos [this message]
2023-03-07 11:45 ` [PATCH 04/11] vfs: Make switch_userns set PR_SET_DUMPABLE Rodrigo Campos
2023-03-07 16:47   ` Christian Brauner
2023-03-07 11:45 ` [PATCH 05/11] vfs: Specify wether a test is run inside a userns or not Rodrigo Campos
2023-03-07 11:45 ` [PATCH 06/11] vfs: Prepare tests in &s_idmapped_mounts to be reused inside a userns Rodrigo Campos
2023-03-07 16:50   ` Christian Brauner
2023-03-07 23:34     ` Rodrigo Campos
2023-03-13 10:37       ` Christian Brauner
2023-03-07 11:45 ` [PATCH 07/11] vfs: Make idmapped core tests public Rodrigo Campos
2023-03-07 16:51   ` Christian Brauner
2023-03-07 11:45 ` [PATCH 08/11] vfs: Export test_setup() and test_cleanup() Rodrigo Campos
2023-03-07 16:51   ` Christian Brauner
2023-03-07 17:11     ` Rodrigo Campos
2023-03-07 11:45 ` [PATCH 09/11] vfs: Add DIR0 constant Rodrigo Campos
2023-03-07 16:53   ` Christian Brauner
2023-03-07 17:33     ` Rodrigo Campos
2023-03-07 11:45 ` [PATCH 10/11] vfs: Add tmpfs tests for idmap mounts Rodrigo Campos
2023-03-07 11:45 ` [PATCH 11/11] vfs: Use tabs to indent, not spaces Rodrigo Campos
2023-03-07 16:55   ` Christian Brauner
2023-03-07 17:10     ` Rodrigo Campos
2023-03-08 17:27     ` Zorro Lang

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=ed07090b-a5a7-513a-aa14-3ef32aaee55e@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).