Merge tag 'usb-ci-v4.8-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/peter...
[cascardo/linux.git] / kernel / user_namespace.c
index 9bafc21..68f5942 100644 (file)
@@ -938,6 +938,20 @@ bool userns_may_setgroups(const struct user_namespace *ns)
        return allowed;
 }
 
+/*
+ * Returns true if @ns is the same namespace as or a descendant of
+ * @target_ns.
+ */
+bool current_in_userns(const struct user_namespace *target_ns)
+{
+       struct user_namespace *ns;
+       for (ns = current_user_ns(); ns; ns = ns->parent) {
+               if (ns == target_ns)
+                       return true;
+       }
+       return false;
+}
+
 static inline struct user_namespace *to_user_ns(struct ns_common *ns)
 {
        return container_of(ns, struct user_namespace, ns);