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: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dmitry Kadashev <dkadashev@gmail.com> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Link: https://lore.kernel.org/r/20210708063447.3556403-4-dkadashev@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Родитель
0ee50b4753
Коммит
584d3226d6
|
@ -76,6 +76,7 @@ long do_unlinkat(int dfd, struct filename *name);
|
|||
int may_linkat(struct user_namespace *mnt_userns, struct path *link);
|
||||
int do_renameat2(int olddfd, struct filename *oldname, int newdfd,
|
||||
struct filename *newname, unsigned int flags);
|
||||
long do_mkdirat(int dfd, struct filename *name, umode_t mode);
|
||||
|
||||
/*
|
||||
* namespace.c
|
||||
|
|
26
fs/namei.c
26
fs/namei.c
|
@ -3573,7 +3573,7 @@ struct file *do_file_open_root(const struct path *root,
|
|||
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 dentry *dentry = ERR_PTR(-EEXIST);
|
||||
|
@ -3589,7 +3589,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,
|
|||
*/
|
||||
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)
|
||||
return ERR_PTR(error);
|
||||
|
||||
|
@ -3642,6 +3642,15 @@ out:
|
|||
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 path *path, unsigned int lookup_flags)
|
||||
{
|
||||
|
@ -3832,7 +3841,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
|
|||
}
|
||||
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 path path;
|
||||
|
@ -3840,9 +3849,10 @@ static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)
|
|||
unsigned int lookup_flags = LOOKUP_DIRECTORY;
|
||||
|
||||
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))
|
||||
return PTR_ERR(dentry);
|
||||
goto out_putname;
|
||||
|
||||
if (!IS_POSIXACL(path.dentry->d_inode))
|
||||
mode &= ~current_umask();
|
||||
|
@ -3858,17 +3868,19 @@ retry:
|
|||
lookup_flags |= LOOKUP_REVAL;
|
||||
goto retry;
|
||||
}
|
||||
out_putname:
|
||||
putname(name);
|
||||
return error;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return do_mkdirat(AT_FDCWD, pathname, mode);
|
||||
return do_mkdirat(AT_FDCWD, getname(pathname), mode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче