diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2022-05-16 01:16:54 +0300 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2023-04-21 05:55:35 +0300 |
commit | 38e124086282715e3b9b3d193d9308bb3499b46c (patch) | |
tree | a18f69cb50f1e19c67e20cb591072d225858a1f6 /net/core/net_namespace.c | |
parent | d2084fd84569fb7054c97ae6ffaf2755086fd267 (diff) | |
download | linux-38e124086282715e3b9b3d193d9308bb3499b46c.tar.xz |
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>
Diffstat (limited to 'net/core/net_namespace.c')
-rw-r--r-- | net/core/net_namespace.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 7b69cf882b8e..3e3598cd49f2 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -20,6 +20,7 @@ #include <linux/sched/task.h> #include <linux/uidgid.h> #include <linux/cookie.h> +#include <linux/proc_fs.h> #include <net/sock.h> #include <net/netlink.h> @@ -676,21 +677,19 @@ EXPORT_SYMBOL_GPL(get_net_ns); struct net *get_net_ns_by_fd(int fd) { - struct file *file; - struct ns_common *ns; - struct net *net; + struct fd f = fdget(fd); + struct net *net = ERR_PTR(-EINVAL); - file = proc_ns_fget(fd); - if (IS_ERR(file)) - return ERR_CAST(file); + if (!f.file) + return ERR_PTR(-EBADF); - ns = get_proc_ns(file_inode(file)); - if (ns->ops == &netns_operations) - net = get_net(container_of(ns, struct net, ns)); - else - net = ERR_PTR(-EINVAL); + if (proc_ns_file(f.file)) { + struct ns_common *ns = get_proc_ns(file_inode(f.file)); + if (ns->ops == &netns_operations) + net = get_net(container_of(ns, struct net, ns)); + } + fdput(f); - fput(file); return net; } EXPORT_SYMBOL_GPL(get_net_ns_by_fd); |