X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=kernel%2Fcapability.c;h=45432b54d5c60ca5b9cde95e480c3fae8cffae4a;hb=602f4f79c8f2a833069cd32cb0cc80984e6febb6;hp=1339806a87312f175a2a19fd99751f949dc9917c;hpb=dae04c1c00f74dd21cce9d85ce90ff50b26d4741;p=firefly-linux-kernel-4.4.55.git diff --git a/kernel/capability.c b/kernel/capability.c index 1339806a8731..45432b54d5c6 100644 --- a/kernel/capability.c +++ b/kernel/capability.c @@ -7,6 +7,8 @@ * 30 May 2002: Cleanup, Robert M. Love */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -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; - - if (!warned) { - char name[sizeof(current->comm)]; + 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); @@ -384,7 +375,7 @@ 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); + pr_crit("capable() called with invalid cap=%u\n", cap); BUG(); } @@ -396,29 +387,6 @@ bool ns_capable(struct user_namespace *ns, int cap) } 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: 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. - * - * This does not set PF_SUPERPRIV because the caller may not - * actually be privileged. - */ -bool file_ns_capable(const struct file *file, 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; -} -EXPORT_SYMBOL(file_ns_capable); /** * capable - Determine if the current task has a superior capability in effect @@ -435,18 +403,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 the current task has the given superior capability - * targeted at its own user namespace. + * Return true if task that opened the file had a capability in effect + * when the file was opened. + * + * 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 +446,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);