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 v4 5/9] vfs: Make switch_userns set PR_SET_DUMPABLE
Date: Tue, 14 Mar 2023 12:45:07 +0100	[thread overview]
Message-ID: <20230314114511.128207-6-rodrigo@sdfg.com.ar> (raw)
In-Reply-To: <20230314114511.128207-1-rodrigo@sdfg.com.ar>

We need PR_SET_DUMPABLE in order to write the mapping files when
creating a userns. From prctl(2) PR_SET_DUMPABLE is reset when the
process's effective user or group ID is changed.

As we are changing the EUID here, we also reset it to allow creating
nested userns with subsequent switch_users() calls.

This was not causing any issues because we weren't using switch_users()
to create nested userns. Nested userns were created with
userns_fd_cb()/create_userns_hierarchy() that set PR_SET_DUMPABLE.

Future patches will rely on switch_users() to create nested userns. So
this patch fixes that.

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

diff --git src/vfs/utils.c src/vfs/utils.c
index 2331a3b7..9e67ac37 100644
--- src/vfs/utils.c
+++ src/vfs/utils.c
@@ -286,6 +286,10 @@ bool switch_ids(uid_t uid, gid_t gid)
 	if (setresuid(uid, uid, uid))
 		return syserror("failure: setresuid");
 
+	/* Ensure we can access proc files from processes we can ptrace. */
+	if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0))
+		return syserror("failure: make dumpable");
+
 	return true;
 }
 
@@ -303,11 +307,6 @@ static int userns_fd_cb(void *data)
 	if (c == '1') {
 		if (!switch_ids(0, 0))
 			return syserror("failure: switch ids to 0");
-
-		/* Ensure we can access proc files from processes we can ptrace. */
-		ret = prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
-		if (ret < 0)
-			return syserror("failure: make dumpable");
 	}
 
 	ret = write_nointr(h->fd_event, "1", 1);
-- 
2.39.2


  parent reply	other threads:[~2023-03-14 11:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 11:45 [PATCH v4 0/9] Tests for idmapped tmpfs Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 1/9] vfs: Don't open-code safe_close() Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 2/9] vfs: Fix documentation typo Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 3/9] vfs: Use tabs to indent, not spaces Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 4/9] vfs: Fix race condition on get_userns_fd() Rodrigo Campos
2023-03-14 11:45 ` Rodrigo Campos [this message]
2023-03-14 11:45 ` [PATCH v4 6/9] vfs: Prepare tests in &s_idmapped_mounts to be reused inside a userns Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 7/9] vfs: Make idmapped core tests public Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 8/9] vfs: Export test_setup() and test_cleanup() Rodrigo Campos
2023-03-14 11:45 ` [PATCH v4 9/9] vfs: Add tmpfs tests for idmap mounts Rodrigo Campos
2023-03-14 13:13   ` Christian Brauner
2023-03-14 14:47   ` Zorro Lang
2023-03-14 15:08     ` 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=20230314114511.128207-6-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.