提交 584d3226 编写于 作者: D Dmitry Kadashev 提交者: Jens Axboe

namei: make do_mkdirat() take struct filename

Pass in the struct filename pointers instead of the user string, and
update the three callers to do the same. This is heavily based on
commit dbea8d345177 ("fs: make do_renameat2() take struct filename").

This behaves like do_unlinkat() and do_renameat2().

Cc: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NDmitry Kadashev <dkadashev@gmail.com>
Acked-by: NChristian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20210708063447.3556403-4-dkadashev@gmail.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
上级 0ee50b47
...@@ -76,6 +76,7 @@ long do_unlinkat(int dfd, struct filename *name); ...@@ -76,6 +76,7 @@ long do_unlinkat(int dfd, struct filename *name);
int may_linkat(struct user_namespace *mnt_userns, struct path *link); int may_linkat(struct user_namespace *mnt_userns, struct path *link);
int do_renameat2(int olddfd, struct filename *oldname, int newdfd, int do_renameat2(int olddfd, struct filename *oldname, int newdfd,
struct filename *newname, unsigned int flags); struct filename *newname, unsigned int flags);
long do_mkdirat(int dfd, struct filename *name, umode_t mode);
/* /*
* namespace.c * namespace.c
......
...@@ -3573,7 +3573,7 @@ struct file *do_file_open_root(const struct path *root, ...@@ -3573,7 +3573,7 @@ struct file *do_file_open_root(const struct path *root,
return file; return file;
} }
static struct dentry *filename_create(int dfd, struct filename *name, static struct dentry *__filename_create(int dfd, struct filename *name,
struct path *path, unsigned int lookup_flags) struct path *path, unsigned int lookup_flags)
{ {
struct dentry *dentry = ERR_PTR(-EEXIST); struct dentry *dentry = ERR_PTR(-EEXIST);
...@@ -3589,7 +3589,7 @@ static struct dentry *filename_create(int dfd, struct filename *name, ...@@ -3589,7 +3589,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,
*/ */
lookup_flags &= LOOKUP_REVAL; lookup_flags &= LOOKUP_REVAL;
error = filename_parentat(dfd, name, lookup_flags, path, &last, &type); error = __filename_parentat(dfd, name, lookup_flags, path, &last, &type);
if (error) if (error)
return ERR_PTR(error); return ERR_PTR(error);
...@@ -3642,6 +3642,15 @@ static struct dentry *filename_create(int dfd, struct filename *name, ...@@ -3642,6 +3642,15 @@ static struct dentry *filename_create(int dfd, struct filename *name,
return dentry; return dentry;
} }
static inline struct dentry *filename_create(int dfd, struct filename *name,
struct path *path, unsigned int lookup_flags)
{
struct dentry *res = __filename_create(dfd, name, path, lookup_flags);
putname(name);
return res;
}
struct dentry *kern_path_create(int dfd, const char *pathname, struct dentry *kern_path_create(int dfd, const char *pathname,
struct path *path, unsigned int lookup_flags) struct path *path, unsigned int lookup_flags)
{ {
...@@ -3832,7 +3841,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, ...@@ -3832,7 +3841,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
} }
EXPORT_SYMBOL(vfs_mkdir); EXPORT_SYMBOL(vfs_mkdir);
static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) long do_mkdirat(int dfd, struct filename *name, umode_t mode)
{ {
struct dentry *dentry; struct dentry *dentry;
struct path path; struct path path;
...@@ -3840,9 +3849,10 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) ...@@ -3840,9 +3849,10 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)
unsigned int lookup_flags = LOOKUP_DIRECTORY; unsigned int lookup_flags = LOOKUP_DIRECTORY;
retry: retry:
dentry = user_path_create(dfd, pathname, &path, lookup_flags); dentry = __filename_create(dfd, name, &path, lookup_flags);
error = PTR_ERR(dentry);
if (IS_ERR(dentry)) if (IS_ERR(dentry))
return PTR_ERR(dentry); goto out_putname;
if (!IS_POSIXACL(path.dentry->d_inode)) if (!IS_POSIXACL(path.dentry->d_inode))
mode &= ~current_umask(); mode &= ~current_umask();
...@@ -3858,17 +3868,19 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode) ...@@ -3858,17 +3868,19 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)
lookup_flags |= LOOKUP_REVAL; lookup_flags |= LOOKUP_REVAL;
goto retry; goto retry;
} }
out_putname:
putname(name);
return error; return error;
} }
SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode) SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
{ {
return do_mkdirat(dfd, pathname, mode); return do_mkdirat(dfd, getname(pathname), mode);
} }
SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode)
{ {
return do_mkdirat(AT_FDCWD, pathname, mode); return do_mkdirat(AT_FDCWD, getname(pathname), mode);
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册