arm64: dts: rockchip: add allocator type inside vpu & rkvdec for rk3399-android
[firefly-linux-kernel-4.4.55.git] / kernel / capability.c
index 1339806a87312f175a2a19fd99751f949dc9917c..00411c82dac57c4cac0254c823f9adcb2a951549 100644 (file)
@@ -7,6 +7,8 @@
  * 30 May 2002:        Cleanup, Robert M. Love <rml@tech9.net>
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/audit.h>
 #include <linux/capability.h>
 #include <linux/mm.h>
@@ -22,7 +24,6 @@
  */
 
 const kernel_cap_t __cap_empty_set = CAP_EMPTY_SET;
-
 EXPORT_SYMBOL(__cap_empty_set);
 
 int file_caps_enabled = 1;
@@ -34,6 +35,7 @@ static int __init file_caps_disable(char *str)
 }
 __setup("no_file_caps", file_caps_disable);
 
+#ifdef CONFIG_MULTIUSER
 /*
  * More recent versions of libcap are available from:
  *
@@ -42,15 +44,10 @@ __setup("no_file_caps", file_caps_disable);
 
 static void warn_legacy_capability_use(void)
 {
-       static int warned;
-       if (!warned) {
-               char name[sizeof(current->comm)];
-
-               printk(KERN_INFO "warning: `%s' uses 32-bit capabilities"
-                      " (legacy support in use)\n",
-                      get_task_comm(name, current));
-               warned = 1;
-       }
+       char name[sizeof(current->comm)];
+
+       pr_info_once("warning: `%s' uses 32-bit capabilities (legacy support in use)\n",
+                    get_task_comm(name, current));
 }
 
 /*
@@ -71,16 +68,10 @@ static void warn_legacy_capability_use(void)
 
 static void warn_deprecated_v2(void)
 {
-       static int warned;
+       char name[sizeof(current->comm)];
 
-       if (!warned) {
-               char name[sizeof(current->comm)];
-
-               printk(KERN_INFO "warning: `%s' uses deprecated v2"
-                      " capabilities in a way that may be insecure.\n",
-                      get_task_comm(name, current));
-               warned = 1;
-       }
+       pr_info_once("warning: `%s' uses deprecated v2 capabilities in a way that may be insecure\n",
+                    get_task_comm(name, current));
 }
 
 /*
@@ -198,7 +189,7 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
                 *
                 * An alternative would be to return an error here
                 * (-ERANGE), but that causes legacy applications to
-                * unexpectidly fail; the capget/modify/capset aborts
+                * unexpectedly fail; the capget/modify/capset aborts
                 * before modification is attempted and the application
                 * fails.
                 */
@@ -281,7 +272,7 @@ SYSCALL_DEFINE2(capset, cap_user_header_t, header, const cap_user_data_t, data)
        if (ret < 0)
                goto error;
 
-       audit_log_capset(pid, new, current_cred());
+       audit_log_capset(new, current_cred());
 
        return commit_creds(new);
 
@@ -370,6 +361,24 @@ bool has_capability_noaudit(struct task_struct *t, int cap)
        return has_ns_capability_noaudit(t, &init_user_ns, cap);
 }
 
+static bool ns_capable_common(struct user_namespace *ns, int cap, bool audit)
+{
+       int capable;
+
+       if (unlikely(!cap_valid(cap))) {
+               pr_crit("capable() called with invalid cap=%u\n", cap);
+               BUG();
+       }
+
+       capable = audit ? security_capable(current_cred(), ns, cap) :
+                         security_capable_noaudit(current_cred(), ns, cap);
+       if (capable == 0) {
+               current->flags |= PF_SUPERPRIV;
+               return true;
+       }
+       return false;
+}
+
 /**
  * ns_capable - Determine if the current task has a superior capability in effect
  * @ns:  The usernamespace we want the capability in
@@ -383,42 +392,27 @@ bool has_capability_noaudit(struct task_struct *t, int cap)
  */
 bool ns_capable(struct user_namespace *ns, int cap)
 {
-       if (unlikely(!cap_valid(cap))) {
-               printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
-               BUG();
-       }
-
-       if (security_capable(current_cred(), ns, cap) == 0) {
-               current->flags |= PF_SUPERPRIV;
-               return true;
-       }
-       return false;
+       return ns_capable_common(ns, cap, true);
 }
 EXPORT_SYMBOL(ns_capable);
 
 /**
- * file_ns_capable - Determine if the file's opener had a capability in effect
- * @file:  The file we want to check
+ * ns_capable_noaudit - Determine if the current task has a superior capability
+ * (unaudited) in effect
  * @ns:  The usernamespace we want the capability in
  * @cap: The capability to be tested for
  *
- * Return true if task that opened the file had a capability in effect
- * when the file was opened.
+ * Return true if the current task has the given superior capability currently
+ * available for use, false if not.
  *
- * This does not set PF_SUPERPRIV because the caller may not
- * actually be privileged.
+ * This sets PF_SUPERPRIV on the task if the capability is available on the
+ * assumption that it's about to be used.
  */
-bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap)
+bool ns_capable_noaudit(struct user_namespace *ns, int cap)
 {
-       if (WARN_ON_ONCE(!cap_valid(cap)))
-               return false;
-
-       if (security_capable(file->f_cred, ns, cap) == 0)
-               return true;
-
-       return false;
+       return ns_capable_common(ns, cap, false);
 }
-EXPORT_SYMBOL(file_ns_capable);
+EXPORT_SYMBOL(ns_capable_noaudit);
 
 /**
  * capable - Determine if the current task has a superior capability in effect
@@ -435,18 +429,32 @@ bool capable(int cap)
        return ns_capable(&init_user_ns, cap);
 }
 EXPORT_SYMBOL(capable);
+#endif /* CONFIG_MULTIUSER */
 
 /**
- * nsown_capable - Check superior capability to one's own user_ns
- * @cap: The capability in question
+ * file_ns_capable - Determine if the file's opener had a capability in effect
+ * @file:  The file we want to check
+ * @ns:  The usernamespace we want the capability in
+ * @cap: The capability to be tested for
+ *
+ * Return true if task that opened the file had a capability in effect
+ * when the file was opened.
  *
- * Return true if the current task has the given superior capability
- * targeted at its own user namespace.
+ * This does not set PF_SUPERPRIV because the caller may not
+ * actually be privileged.
  */
-bool nsown_capable(int cap)
+bool file_ns_capable(const struct file *file, struct user_namespace *ns,
+                    int cap)
 {
-       return ns_capable(current_user_ns(), cap);
+       if (WARN_ON_ONCE(!cap_valid(cap)))
+               return false;
+
+       if (security_capable(file->f_cred, ns, cap) == 0)
+               return true;
+
+       return false;
 }
+EXPORT_SYMBOL(file_ns_capable);
 
 /**
  * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
@@ -464,3 +472,4 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
        return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
                kgid_has_mapping(ns, inode->i_gid);
 }
+EXPORT_SYMBOL(capable_wrt_inode_uidgid);