@@ -130,7 +130,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
return __proc_ns_get_dentry(sb, ns, ns_ops);
}
-static int open_related_ns(struct vfsmount *mnt, struct proc_ns *ns,
+int open_related_ns(struct vfsmount *mnt, struct proc_ns *ns,
const struct proc_ns_operations *relative_ns_ops,
void *(*get_ns)(void *ns,
const struct proc_ns_operations *ns_ops)) {
@@ -78,4 +78,12 @@ static inline bool proc_ns_inode(struct inode *inode) { return false; }
#endif /* CONFIG_PROC_FS */
+struct vfsmount;
+int open_related_ns(struct vfsmount *mnt, struct proc_ns *ns,
+ const struct proc_ns_operations *relative_ns_ops,
+ void *(*get_ns)(void *ns,
+ const struct proc_ns_operations *ns_ops));
+
+int open_net_ns_fd(struct net *net);
+
#endif /* _LINUX_PROC_NS_H */
@@ -84,6 +84,7 @@
#define SIOCWANDEV 0x894A /* get/set netdev parameters */
#define SIOCOUTQNSD 0x894B /* output queue size (not sent only) */
+#define SIOCGSKNS 0x894C /* get socket network namespace */
/* ARP cache control calls. */
/* 0x8950 - 0x8952 * obsolete calls, don't re-use */
@@ -67,6 +67,7 @@
#include <linux/rcupdate.h>
#include <linux/netdevice.h>
#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
#include <linux/seq_file.h>
#include <linux/mutex.h>
#include <linux/if_bridge.h>
@@ -1026,6 +1027,29 @@ static long sock_do_ioctl(struct net *net, struct socket *sock,
* what to do with it - that's up to the protocol still.
*/
+static void *get_net_ns(void *ns, const struct proc_ns_operations *ns_ops)
+{
+ struct net *net = ns;
+ return get_net(net);
+}
+
+int open_net_ns_fd(struct net *net)
+{
+ struct proc_ns ns = { .ns = net, .ns_ops = &netns_operations, };
+ struct vfsmount *proc_mnt;
+ int ret;
+
+ proc_mnt = mntget(task_active_pid_ns(current)->proc_mnt);
+ if (IS_ERR(proc_mnt))
+ return PTR_ERR(proc_mnt);
+
+ ret = open_related_ns(proc_mnt, &ns, ns.ns_ops, get_net_ns);
+ mntput(proc_mnt);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(open_net_ns_fd);
+
static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
{
struct socket *sock;
@@ -1093,6 +1117,13 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
err = dlci_ioctl_hook(cmd, argp);
mutex_unlock(&dlci_ioctl_mutex);
break;
+ case SIOCGSKNS:
+ err = -EPERM;
+ if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
+ break;
+
+ err = open_net_ns_fd(net);
+ break;
default:
err = sock_do_ioctl(net, sock, cmd, arg);
break;
@@ -3246,6 +3277,7 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
case SIOCSIFVLAN:
case SIOCADDDLCI:
case SIOCDELDLCI:
+ case SIOCGSKNS:
return sock_ioctl(file, cmd, arg);
case SIOCGIFFLAGS: