linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Vagin <avagin@google.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Jan Kara <jack@suse.cz>
Subject: Re: [PATCH] fs/namespace: correctly handle errors returned by grab_requested_mnt_ns
Date: Tue, 11 Nov 2025 08:20:46 -0800	[thread overview]
Message-ID: <CAEWA0a5ZjWuyFM9b6076GT6yEn0jYZu06C=huPxpqyxWQiM7QA@mail.gmail.com> (raw)
In-Reply-To: <20251111-umkleiden-umgegangen-c19ef83823c1@brauner>

)

On Tue, Nov 11, 2025 at 1:13 AM Christian Brauner <brauner@kernel.org> wrote:
>
> On Tue, Nov 11, 2025 at 06:28:15AM +0000, Andrei Vagin wrote:
> > grab_requested_mnt_ns was changed to return error codes on failure, but
> > its callers were not updated to check for error pointers, still checking
> > only for a NULL return value.
> >
> > This commit updates the callers to use IS_ERR() or IS_ERR_OR_NULL() and
> > PTR_ERR() to correctly check for and propagate errors.
> >
> > Fixes: 7b9d14af8777 ("fs: allow mount namespace fd")
> > Cc: Christian Brauner <brauner@kernel.org>
> > Signed-off-by: Andrei Vagin <avagin@google.com>
> > ---
>
> Thanks. I've folded the following diff into the patch to be more in line
> with our usual error handling:

The diff looks good, thanks. I have another question regarding
7b9d14af8777 ("fs: allow mount namespace fd"). My understanding is that
the intention was to allow using mount namespace file descriptors
(req->spare) for the statmount and listmounts syscalls. If this is
correct and I haven't missed anything, we need to make one more change:

diff --git a/fs/namespace.c b/fs/namespace.c
index 9124465dca556..3250cadde6fc4 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5738,7 +5738,7 @@ static int copy_mnt_id_req(const struct
mnt_id_req __user *req,
        ret = copy_struct_from_user(kreq, sizeof(*kreq), req, usize);
        if (ret)
                return ret;
-       if (kreq->spare != 0)
+       if (kreq->spare != 0 && kreq->mnt_ns_id != 0)
                return -EINVAL;
        /* The first valid unique mount id is MNT_UNIQUE_ID_OFFSET + 1. */
        if (kreq->mnt_id <= MNT_UNIQUE_ID_OFFSET)
@@ -5755,9 +5755,6 @@ static struct mnt_namespace
*grab_requested_mnt_ns(const struct mnt_id_req *kreq
 {
        struct mnt_namespace *mnt_ns;

-       if (kreq->mnt_ns_id && kreq->spare)
-               return ERR_PTR(-EINVAL);
-
        if (kreq->mnt_ns_id) {
                mnt_ns = lookup_mnt_ns(kreq->mnt_ns_id);
                return mnt_ns ? : ERR_PTR(-ENOENT);

Thanks,
Andrei

  reply	other threads:[~2025-11-11 16:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11  6:28 [PATCH] fs/namespace: correctly handle errors returned by grab_requested_mnt_ns Andrei Vagin
2025-11-11  8:21 ` Jan Kara
2025-11-11  9:13 ` Christian Brauner
2025-11-11 16:20   ` Andrei Vagin [this message]
2025-11-12  9:42     ` Christian Brauner
2025-11-23 12:51 ` Mark Brown
2025-11-23 15:15   ` Andrei Vagin
2025-11-24 11:23     ` Mark Brown
2025-11-24 19:14       ` Andrei Vagin
2025-11-24 19:28         ` Carlos Llamas

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='CAEWA0a5ZjWuyFM9b6076GT6yEn0jYZu06C=huPxpqyxWQiM7QA@mail.gmail.com' \
    --to=avagin@google.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).