--- l/include/linux/ns_common.h +++ n/include/linux/ns_common.h @@ -38,7 +38,7 @@ extern const struct proc_ns_operations t extern const struct proc_ns_operations timens_for_children_operations; struct ns_common { - u32 ns_type; + u32 ns_type, gi; struct dentry *stashed; const struct proc_ns_operations *ops; unsigned int inum; --- l/kernel/nscommon.c +++ n/kernel/nscommon.c @@ -57,6 +57,7 @@ int __ns_common_init(struct ns_common *n ns->ops = ops; ns->ns_id = 0; ns->ns_type = ns_type; + ns->gi = 0; RB_CLEAR_NODE(&ns->ns_tree_node); INIT_LIST_HEAD(&ns->ns_list_node); @@ -66,6 +67,7 @@ int __ns_common_init(struct ns_common *n if (inum) { ns->inum = inum; + ns->gi++; return 0; } return proc_alloc_inum(&ns->inum); @@ -73,5 +75,7 @@ int __ns_common_init(struct ns_common *n void __ns_common_free(struct ns_common *ns) { + if (ns->gi) + return; proc_free_inum(ns->inum); } --- l/fs/namespace.c +++ n/fs/namespace.c @@ -3026,7 +3026,7 @@ static struct file *open_detached_copy(s mnt = __do_loopback(path, recursive); if (IS_ERR(mnt)) { namespace_unlock(); - free_mnt_ns(ns); + put_mnt_ns(ns); return ERR_CAST(mnt); }