userns: Replace the hard to write inode_userns with inode_capable.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / capability.c
index 3f1adb6c647015d80aa6b5b138f118fde7484d11..cc5f0718215dc418dc116da6ba2e0148445f0158 100644 (file)
@@ -419,3 +419,22 @@ bool nsown_capable(int cap)
 {
        return ns_capable(current_user_ns(), cap);
 }
+
+/**
+ * inode_capable - Check superior capability over inode
+ * @inode: The inode in question
+ * @cap: The capability in question
+ *
+ * Return true if the current task has the given superior capability
+ * targeted at it's own user namespace and that the given inode is owned
+ * by the current user namespace or a child namespace.
+ *
+ * Currently inodes can only be owned by the initial user namespace.
+ *
+ */
+bool inode_capable(const struct inode *inode, int cap)
+{
+       struct user_namespace *ns = current_user_ns();
+
+       return ns_capable(ns, cap) && (ns == &init_user_ns);
+}