On Fri 12-09-25 13:52:47, Christian Brauner wrote:
Support the generic ns lookup infrastructure to support file handles for namespaces.
Signed-off-by: Christian Brauner brauner@kernel.org
...
@@ -200,6 +202,7 @@ static void free_user_ns(struct work_struct *work) do { struct ucounts *ucounts = ns->ucounts; parent = ns->parent;
if (ns->gid_map.nr_extents > UID_GID_MAP_MAX_BASE_EXTENTS) { kfree(ns->gid_map.forward); kfree(ns->gid_map.reverse);ns_tree_remove(ns);
@@ -218,7 +221,8 @@ static void free_user_ns(struct work_struct *work) retire_userns_sysctls(ns); key_free_user_ns(ns); ns_free_inum(&ns->ns);
kmem_cache_free(user_ns_cachep, ns);
/* Concurrent nstree traversal depends on a grace period. */
kfree_rcu(ns, ns.ns_rcu);
So this is correct for now but it's a bit of a landmine. A lot of stuff that ns references is kfreed before the RCU expires. Thus if you lookup ns using id, then even if you're under RCU protection you have to be very careful about what you can and cannot dereference. IMHO this deserves a careful documentation at least or, preferably, split free_user_ns() into pre and post-RCU period parts...
Honza