Linux filesystem development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, Jeff Layton <jlayton@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>, Jan Kara <jack@suse.cz>,
	Amir Goldstein <amir73il@gmail.com>
Subject: Re: [PATCH] pidfs: protect PIDFD_GET_* ioctls() via ifdef
Date: Sun, 28 Dec 2025 13:01:37 -0800	[thread overview]
Message-ID: <20251228210137.GD2431@quark> (raw)
In-Reply-To: <20251224-ununterbrochen-gagen-ea949b83f8f2@brauner>

On Wed, Dec 24, 2025 at 01:00:24PM +0100, Christian Brauner wrote:
> We originally protected PIDFD_GET_<ns-type>_NAMESPACE ioctls() through
> ifdefs and recent rework made it possible to drop them. There was an
> oversight though. When the relevant namespace is turned off ns->ops will
> be NULL so even though opening a file descriptor is perfectly legitimate
> it would fail during inode eviction when the file was closed.
> 
> The simple fix would be to check ns->ops for NULL and continue allow to
> retrieve namespace fds from pidfds but we don't allow retrieving them
> when the relevant namespace type is turned off. So keep the
> simplification but add the ifdefs back in.
> 
> Reported-by: Eric Biggers <ebiggers@kernel.org>
> Link: https://lore.kernel.org/20251222214907.GA189632@quark
> Fixes: a71e4f103aed ("pidfs: simplify PIDFD_GET_<type>_NAMESPACE ioctls")
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Tested-by: Eric Biggers <ebiggers@kernel.org>

>	case PIDFD_GET_USER_NAMESPACE:
>#ifdef CONFIG_USER_NS
>		scoped_guard(rcu) {
>			struct user_namespace *user_ns;
>
>			user_ns = task_cred_xxx(task, user_ns);
>			if (!ns_ref_get(user_ns))
>				break;
>			ns_common = to_ns_common(user_ns);
>		}
>#endif
>  		break;

Not directly related to this patch, but you know that the 'break;' above
breaks from the scoped_guard() block and not from the switch statement,
right?  (Considering that scoped_guard() is implemented using 'for'.)
There is a break after the scoped_guard(), so it ends up being the same.
But it's confusing.  It would be much easier to understand if it was
rewritten to not use an inner 'break':

            if (ns_ref_get(user_ns))
                    ns_common = to_ns_common(user_ns);

- Eric

  reply	other threads:[~2025-12-28 21:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17 12:36 [PATCH] pidfs: simplify PIDFD_GET_<type>_NAMESPACE ioctls Christian Brauner
2025-12-22 21:49 ` Eric Biggers
2025-12-24 12:00   ` [PATCH] pidfs: protect PIDFD_GET_* ioctls() via ifdef Christian Brauner
2025-12-28 21:01     ` Eric Biggers [this message]
2026-01-06 15:18     ` Brendan Jackman
2026-02-23 15:50 ` [PATCH] pidfs: simplify PIDFD_GET_<type>_NAMESPACE ioctls David Lechner
2026-02-24 11:08   ` Christian Brauner

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=20251228210137.GD2431@quark \
    --to=ebiggers@kernel.org \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /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