Commit 8228e2c3 authored by Dmitry Kadashev's avatar Dmitry Kadashev Committed by Jens Axboe

namei: add getname_uflags()

There are a couple of places where we already open-code the (flags &
AT_EMPTY_PATH) check and io_uring will likely add another one in the
future.  Let's just add a simple helper getname_uflags() that handles
this directly and use it.

Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Acked-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/io-uring/20210415100815.edrn4a7cy26wkowe@wittgenstein/Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: default avatarDmitry Kadashev <dkadashev@gmail.com>
Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20210708063447.3556403-7-dkadashev@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent da2d0ced
...@@ -2070,10 +2070,8 @@ SYSCALL_DEFINE5(execveat, ...@@ -2070,10 +2070,8 @@ SYSCALL_DEFINE5(execveat,
const char __user *const __user *, envp, const char __user *const __user *, envp,
int, flags) int, flags)
{ {
int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
return do_execveat(fd, return do_execveat(fd,
getname_flags(filename, lookup_flags, NULL), getname_uflags(filename, flags),
argv, envp, flags); argv, envp, flags);
} }
...@@ -2091,10 +2089,8 @@ COMPAT_SYSCALL_DEFINE5(execveat, int, fd, ...@@ -2091,10 +2089,8 @@ COMPAT_SYSCALL_DEFINE5(execveat, int, fd,
const compat_uptr_t __user *, envp, const compat_uptr_t __user *, envp,
int, flags) int, flags)
{ {
int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
return compat_do_execveat(fd, return compat_do_execveat(fd,
getname_flags(filename, lookup_flags, NULL), getname_uflags(filename, flags),
argv, envp, flags); argv, envp, flags);
} }
#endif #endif
...@@ -203,6 +203,14 @@ getname_flags(const char __user *filename, int flags, int *empty) ...@@ -203,6 +203,14 @@ getname_flags(const char __user *filename, int flags, int *empty)
return result; return result;
} }
struct filename *
getname_uflags(const char __user *filename, int uflags)
{
int flags = (uflags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
return getname_flags(filename, flags, NULL);
}
struct filename * struct filename *
getname(const char __user * filename) getname(const char __user * filename)
{ {
......
...@@ -2786,6 +2786,7 @@ static inline struct file *file_clone_open(struct file *file) ...@@ -2786,6 +2786,7 @@ static inline struct file *file_clone_open(struct file *file)
extern int filp_close(struct file *, fl_owner_t id); extern int filp_close(struct file *, fl_owner_t id);
extern struct filename *getname_flags(const char __user *, int, int *); extern struct filename *getname_flags(const char __user *, int, int *);
extern struct filename *getname_uflags(const char __user *, int);
extern struct filename *getname(const char __user *); extern struct filename *getname(const char __user *);
extern struct filename *getname_kernel(const char *); extern struct filename *getname_kernel(const char *);
extern void putname(struct filename *name); extern void putname(struct filename *name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment