Commit ce623f89 authored by Aleksa Sarai's avatar Aleksa Sarai Committed by Al Viro

nsfs: clean-up ns_get_path() signature to return int

ns_get_path() and ns_get_path_cb() only ever return either NULL or an
ERR_PTR. It is far more idiomatic to simply return an integer, and it
makes all of the callers of ns_get_path() more straightforward to read.

Fixes: e149ed2b ("take the targets of /proc/*/ns/* symlinks to separate fs")
Signed-off-by: default avatarAleksa Sarai <cyphar@cyphar.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 2b98149c
...@@ -52,7 +52,7 @@ static void nsfs_evict(struct inode *inode) ...@@ -52,7 +52,7 @@ static void nsfs_evict(struct inode *inode)
ns->ops->put(ns); ns->ops->put(ns);
} }
static void *__ns_get_path(struct path *path, struct ns_common *ns) static int __ns_get_path(struct path *path, struct ns_common *ns)
{ {
struct vfsmount *mnt = nsfs_mnt; struct vfsmount *mnt = nsfs_mnt;
struct dentry *dentry; struct dentry *dentry;
...@@ -71,13 +71,13 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns) ...@@ -71,13 +71,13 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
got_it: got_it:
path->mnt = mntget(mnt); path->mnt = mntget(mnt);
path->dentry = dentry; path->dentry = dentry;
return NULL; return 0;
slow: slow:
rcu_read_unlock(); rcu_read_unlock();
inode = new_inode_pseudo(mnt->mnt_sb); inode = new_inode_pseudo(mnt->mnt_sb);
if (!inode) { if (!inode) {
ns->ops->put(ns); ns->ops->put(ns);
return ERR_PTR(-ENOMEM); return -ENOMEM;
} }
inode->i_ino = ns->inum; inode->i_ino = ns->inum;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
...@@ -89,7 +89,7 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns) ...@@ -89,7 +89,7 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
dentry = d_alloc_anon(mnt->mnt_sb); dentry = d_alloc_anon(mnt->mnt_sb);
if (!dentry) { if (!dentry) {
iput(inode); iput(inode);
return ERR_PTR(-ENOMEM); return -ENOMEM;
} }
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dentry->d_fsdata = (void *)ns->ops; dentry->d_fsdata = (void *)ns->ops;
...@@ -98,23 +98,22 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns) ...@@ -98,23 +98,22 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
d_delete(dentry); /* make sure ->d_prune() does nothing */ d_delete(dentry); /* make sure ->d_prune() does nothing */
dput(dentry); dput(dentry);
cpu_relax(); cpu_relax();
return ERR_PTR(-EAGAIN); return -EAGAIN;
} }
goto got_it; goto got_it;
} }
void *ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb, int ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
void *private_data) void *private_data)
{ {
void *ret; int ret;
do { do {
struct ns_common *ns = ns_get_cb(private_data); struct ns_common *ns = ns_get_cb(private_data);
if (!ns) if (!ns)
return ERR_PTR(-ENOENT); return -ENOENT;
ret = __ns_get_path(path, ns); ret = __ns_get_path(path, ns);
} while (ret == ERR_PTR(-EAGAIN)); } while (ret == -EAGAIN);
return ret; return ret;
} }
...@@ -131,7 +130,7 @@ static struct ns_common *ns_get_path_task(void *private_data) ...@@ -131,7 +130,7 @@ static struct ns_common *ns_get_path_task(void *private_data)
return args->ns_ops->get(args->task); return args->ns_ops->get(args->task);
} }
void *ns_get_path(struct path *path, struct task_struct *task, int ns_get_path(struct path *path, struct task_struct *task,
const struct proc_ns_operations *ns_ops) const struct proc_ns_operations *ns_ops)
{ {
struct ns_get_path_task_args args = { struct ns_get_path_task_args args = {
...@@ -147,7 +146,7 @@ int open_related_ns(struct ns_common *ns, ...@@ -147,7 +146,7 @@ int open_related_ns(struct ns_common *ns,
{ {
struct path path = {}; struct path path = {};
struct file *f; struct file *f;
void *err; int err;
int fd; int fd;
fd = get_unused_fd_flags(O_CLOEXEC); fd = get_unused_fd_flags(O_CLOEXEC);
...@@ -164,11 +163,11 @@ int open_related_ns(struct ns_common *ns, ...@@ -164,11 +163,11 @@ int open_related_ns(struct ns_common *ns,
} }
err = __ns_get_path(&path, relative); err = __ns_get_path(&path, relative);
} while (err == ERR_PTR(-EAGAIN)); } while (err == -EAGAIN);
if (IS_ERR(err)) { if (err) {
put_unused_fd(fd); put_unused_fd(fd);
return PTR_ERR(err); return err;
} }
f = dentry_open(&path, O_RDONLY, current_cred()); f = dentry_open(&path, O_RDONLY, current_cred());
......
...@@ -42,14 +42,14 @@ static const char *proc_ns_get_link(struct dentry *dentry, ...@@ -42,14 +42,14 @@ static const char *proc_ns_get_link(struct dentry *dentry,
const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
struct task_struct *task; struct task_struct *task;
struct path ns_path; struct path ns_path;
void *error = ERR_PTR(-EACCES); int error = -EACCES;
if (!dentry) if (!dentry)
return ERR_PTR(-ECHILD); return ERR_PTR(-ECHILD);
task = get_proc_task(inode); task = get_proc_task(inode);
if (!task) if (!task)
return error; return ERR_PTR(-EACCES);
if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) { if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) {
error = ns_get_path(&ns_path, task, ns_ops); error = ns_get_path(&ns_path, task, ns_ops);
...@@ -57,7 +57,7 @@ static const char *proc_ns_get_link(struct dentry *dentry, ...@@ -57,7 +57,7 @@ static const char *proc_ns_get_link(struct dentry *dentry,
nd_jump_link(&ns_path); nd_jump_link(&ns_path);
} }
put_task_struct(task); put_task_struct(task);
return error; return ERR_PTR(error);
} }
static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflen) static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflen)
......
...@@ -76,10 +76,10 @@ static inline int ns_alloc_inum(struct ns_common *ns) ...@@ -76,10 +76,10 @@ static inline int ns_alloc_inum(struct ns_common *ns)
extern struct file *proc_ns_fget(int fd); extern struct file *proc_ns_fget(int fd);
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
extern void *ns_get_path(struct path *path, struct task_struct *task, extern int ns_get_path(struct path *path, struct task_struct *task,
const struct proc_ns_operations *ns_ops); const struct proc_ns_operations *ns_ops);
typedef struct ns_common *ns_get_path_helper_t(void *); typedef struct ns_common *ns_get_path_helper_t(void *);
extern void *ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb, extern int ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
void *private_data); void *private_data);
extern int ns_get_name(char *buf, size_t size, struct task_struct *task, extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
......
...@@ -302,14 +302,14 @@ int bpf_prog_offload_info_fill(struct bpf_prog_info *info, ...@@ -302,14 +302,14 @@ int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
struct inode *ns_inode; struct inode *ns_inode;
struct path ns_path; struct path ns_path;
char __user *uinsns; char __user *uinsns;
void *res; int res;
u32 ulen; u32 ulen;
res = ns_get_path_cb(&ns_path, bpf_prog_offload_info_fill_ns, &args); res = ns_get_path_cb(&ns_path, bpf_prog_offload_info_fill_ns, &args);
if (IS_ERR(res)) { if (res) {
if (!info->ifindex) if (!info->ifindex)
return -ENODEV; return -ENODEV;
return PTR_ERR(res); return res;
} }
down_read(&bpf_devs_lock); down_read(&bpf_devs_lock);
...@@ -526,13 +526,13 @@ int bpf_map_offload_info_fill(struct bpf_map_info *info, struct bpf_map *map) ...@@ -526,13 +526,13 @@ int bpf_map_offload_info_fill(struct bpf_map_info *info, struct bpf_map *map)
}; };
struct inode *ns_inode; struct inode *ns_inode;
struct path ns_path; struct path ns_path;
void *res; int res;
res = ns_get_path_cb(&ns_path, bpf_map_offload_info_fill_ns, &args); res = ns_get_path_cb(&ns_path, bpf_map_offload_info_fill_ns, &args);
if (IS_ERR(res)) { if (res) {
if (!info->ifindex) if (!info->ifindex)
return -ENODEV; return -ENODEV;
return PTR_ERR(res); return res;
} }
ns_inode = ns_path.dentry->d_inode; ns_inode = ns_path.dentry->d_inode;
......
...@@ -7495,7 +7495,7 @@ static void perf_fill_ns_link_info(struct perf_ns_link_info *ns_link_info, ...@@ -7495,7 +7495,7 @@ static void perf_fill_ns_link_info(struct perf_ns_link_info *ns_link_info,
{ {
struct path ns_path; struct path ns_path;
struct inode *ns_inode; struct inode *ns_inode;
void *error; int error;
error = ns_get_path(&ns_path, task, ns_ops); error = ns_get_path(&ns_path, task, ns_ops);
if (!error) { if (!error) {
......
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