From: Mateusz Guzik <mjguzik@gmail.com>
To: brauner@kernel.org
Cc: viro@zeniv.linux.org.uk, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Mateusz Guzik <mjguzik@gmail.com>
Subject: [PATCH 1/3] vfs: stop using user_path_at_empty in do_readlinkat
Date: Tue, 4 Jun 2024 17:52:55 +0200 [thread overview]
Message-ID: <20240604155257.109500-2-mjguzik@gmail.com> (raw)
In-Reply-To: <20240604155257.109500-1-mjguzik@gmail.com>
It is the only consumer and it saddles getname_flags with an argument set
to NULL by everyone else.
Instead the routine can do the empty check on its own.
Then user_path_at_empty can get retired and getname_flags can lose the
argument.
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
fs/stat.c | 43 ++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/fs/stat.c b/fs/stat.c
index 70bd3e888cfa..7f7861544500 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -488,34 +488,39 @@ static int do_readlinkat(int dfd, const char __user *pathname,
char __user *buf, int bufsiz)
{
struct path path;
+ struct filename *name;
int error;
- int empty = 0;
unsigned int lookup_flags = LOOKUP_EMPTY;
if (bufsiz <= 0)
return -EINVAL;
retry:
- error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty);
- if (!error) {
- struct inode *inode = d_backing_inode(path.dentry);
+ name = getname_flags(pathname, lookup_flags, NULL);
+ error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
+ if (unlikely(error)) {
+ putname(name);
+ return error;
+ }
- error = empty ? -ENOENT : -EINVAL;
- /*
- * AFS mountpoints allow readlink(2) but are not symlinks
- */
- if (d_is_symlink(path.dentry) || inode->i_op->readlink) {
- error = security_inode_readlink(path.dentry);
- if (!error) {
- touch_atime(&path);
- error = vfs_readlink(path.dentry, buf, bufsiz);
- }
- }
- path_put(&path);
- if (retry_estale(error, lookup_flags)) {
- lookup_flags |= LOOKUP_REVAL;
- goto retry;
+ /*
+ * AFS mountpoints allow readlink(2) but are not symlinks
+ */
+ if (d_is_symlink(path.dentry) ||
+ d_backing_inode(path.dentry)->i_op->readlink) {
+ error = security_inode_readlink(path.dentry);
+ if (!error) {
+ touch_atime(&path);
+ error = vfs_readlink(path.dentry, buf, bufsiz);
}
+ } else {
+ error = (name->name[0] == '\0') ? -ENOENT : -EINVAL;
+ }
+ path_put(&path);
+ putname(name);
+ if (retry_estale(error, lookup_flags)) {
+ lookup_flags |= LOOKUP_REVAL;
+ goto retry;
}
return error;
}
--
2.39.2
next prev parent reply other threads:[~2024-06-04 15:53 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 ` Mateusz Guzik [this message]
2024-06-05 15:48 ` [PATCH 1/3] vfs: stop using user_path_at_empty in do_readlinkat 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
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=20240604155257.109500-2-mjguzik@gmail.com \
--to=mjguzik@gmail.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).