userns: Teach inode_capable to understand inodes whose uids map to other namespaces.
[deliverable/linux.git] / kernel / capability.c
index 3f1adb6c647015d80aa6b5b138f118fde7484d11..493d97259484cfef006c59b934be4fcf9663d1ac 100644 (file)
@@ -419,3 +419,24 @@ 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 we check to see if an inode is owned by the current
+ * user namespace by seeing if the inode's owner maps into the
+ * current user namespace.
+ *
+ */
+bool inode_capable(const struct inode *inode, int cap)
+{
+       struct user_namespace *ns = current_user_ns();
+
+       return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
+}
This page took 0.027376 seconds and 5 git commands to generate.