From: Jan Kara <jack@suse.cz>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: brauner@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 3/3] vfs: shave a branch in getname_flags
Date: Wed, 5 Jun 2024 17:49:23 +0200 [thread overview]
Message-ID: <20240605154923.sec53hhjnzgowvws@quack3> (raw)
In-Reply-To: <20240604155257.109500-4-mjguzik@gmail.com>
On Tue 04-06-24 17:52:57, Mateusz Guzik wrote:
> Check for an error while copying and no path in one branch.
>
> Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Looks good to me modulo the need for rechecking Christian already pointed
out. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/namei.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index 950ad6bdd9fe..f25dcb9077dd 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -148,9 +148,20 @@ getname_flags(const char __user *filename, int flags)
> result->name = kname;
>
> len = strncpy_from_user(kname, filename, EMBEDDED_NAME_MAX);
> - if (unlikely(len < 0)) {
> - __putname(result);
> - return ERR_PTR(len);
> + /*
> + * Handle both empty path and copy failure in one go.
> + */
> + if (unlikely(len <= 0)) {
> + if (unlikely(len < 0)) {
> + __putname(result);
> + return ERR_PTR(len);
> + }
> +
> + /* The empty path is special. */
> + if (!(flags & LOOKUP_EMPTY)) {
> + __putname(result);
> + return ERR_PTR(-ENOENT);
> + }
> }
>
> /*
> @@ -188,14 +199,6 @@ getname_flags(const char __user *filename, int flags)
> }
>
> atomic_set(&result->refcnt, 1);
> - /* The empty path is special. */
> - if (unlikely(!len)) {
> - if (!(flags & LOOKUP_EMPTY)) {
> - putname(result);
> - return ERR_PTR(-ENOENT);
> - }
> - }
> -
> result->uptr = filename;
> result->aname = NULL;
> audit_getname(result);
> --
> 2.39.2
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-06-05 15:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 15:52 [PATCH 0/3] whack user_path_at_empty, cleanup getname_flags Mateusz Guzik
2024-06-04 15:52 ` [PATCH 1/3] vfs: stop using user_path_at_empty in do_readlinkat Mateusz Guzik
2024-06-05 15:48 ` Jan Kara
2024-06-04 15:52 ` [PATCH 2/3] vfs: retire user_path_at_empty and drop empty arg from getname_flags Mateusz Guzik
2024-06-05 15:48 ` Jan Kara
2024-06-04 15:52 ` [PATCH 3/3] vfs: shave a branch in getname_flags Mateusz Guzik
2024-06-05 15:03 ` Christian Brauner
2024-06-05 15:10 ` Mateusz Guzik
2024-06-05 15:49 ` Jan Kara [this message]
2024-06-05 15:10 ` [PATCH 0/3] whack user_path_at_empty, cleanup getname_flags 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=20240605154923.sec53hhjnzgowvws@quack3 \
--to=jack@suse.cz \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--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