Skip to content

Commit 38e1240

Browse files
author
Al Viro
committed
kill the last remaining user of proc_ns_fget()
lookups by descriptor are better off closer to syscall surface... Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d2084fd commit 38e1240

3 files changed

Lines changed: 11 additions & 31 deletions

File tree

fs/nsfs.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,6 @@ bool proc_ns_file(const struct file *file)
235235
return file->f_op == &ns_file_operations;
236236
}
237237

238-
struct file *proc_ns_fget(int fd)
239-
{
240-
struct file *file;
241-
242-
file = fget(fd);
243-
if (!file)
244-
return ERR_PTR(-EBADF);
245-
246-
if (file->f_op != &ns_file_operations)
247-
goto out_invalid;
248-
249-
return file;
250-
251-
out_invalid:
252-
fput(file);
253-
return ERR_PTR(-EINVAL);
254-
}
255-
256238
/**
257239
* ns_match() - Returns true if current namespace matches dev/ino provided.
258240
* @ns: current namespace

include/linux/proc_ns.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ static inline int ns_alloc_inum(struct ns_common *ns)
7272

7373
#define ns_free_inum(ns) proc_free_inum((ns)->inum)
7474

75-
extern struct file *proc_ns_fget(int fd);
7675
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
7776
extern int ns_get_path(struct path *path, struct task_struct *task,
7877
const struct proc_ns_operations *ns_ops);

net/core/net_namespace.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/sched/task.h>
2121
#include <linux/uidgid.h>
2222
#include <linux/cookie.h>
23+
#include <linux/proc_fs.h>
2324

2425
#include <net/sock.h>
2526
#include <net/netlink.h>
@@ -676,21 +677,19 @@ EXPORT_SYMBOL_GPL(get_net_ns);
676677

677678
struct net *get_net_ns_by_fd(int fd)
678679
{
679-
struct file *file;
680-
struct ns_common *ns;
681-
struct net *net;
680+
struct fd f = fdget(fd);
681+
struct net *net = ERR_PTR(-EINVAL);
682682

683-
file = proc_ns_fget(fd);
684-
if (IS_ERR(file))
685-
return ERR_CAST(file);
683+
if (!f.file)
684+
return ERR_PTR(-EBADF);
686685

687-
ns = get_proc_ns(file_inode(file));
688-
if (ns->ops == &netns_operations)
689-
net = get_net(container_of(ns, struct net, ns));
690-
else
691-
net = ERR_PTR(-EINVAL);
686+
if (proc_ns_file(f.file)) {
687+
struct ns_common *ns = get_proc_ns(file_inode(f.file));
688+
if (ns->ops == &netns_operations)
689+
net = get_net(container_of(ns, struct net, ns));
690+
}
691+
fdput(f);
692692

693-
fput(file);
694693
return net;
695694
}
696695
EXPORT_SYMBOL_GPL(get_net_ns_by_fd);

0 commit comments

Comments
 (0)