Lines Matching +full:we +full:- +full:on +full:- +full:ns

1 // SPDX-License-Identifier: GPL-2.0
36 * http://www.kernel.org/pub/linux/libs/security/linux-privs/
41 char name[sizeof(current->comm)]; in warn_legacy_capability_use()
43 pr_info_once("warning: `%s' uses 32-bit capabilities (legacy support in use)\n", in warn_legacy_capability_use()
50 * the necessary user-space source code changes. As such, we have
65 char name[sizeof(current->comm)]; in warn_deprecated_v2()
73 * array, or a negative value on error.
79 if (get_user(version, &header->version)) in cap_validate_magic()
80 return -EFAULT; in cap_validate_magic()
94 if (put_user((u32)_KERNEL_CAPABILITY_VERSION, &header->version)) in cap_validate_magic()
95 return -EFAULT; in cap_validate_magic()
96 return -EINVAL; in cap_validate_magic()
104 * process is the current process. As such, we can't be in this code
105 * at the same time as we are in the process of setting capabilities
106 * in this process. The net result is that we can limit our use of
107 * locks to when we are reading the caps of another process.
121 ret = -ESRCH; in cap_get_target_pid()
133 * sys_capget - get the capabilities of a given process.
139 * Returns 0 on success and < 0 on error.
151 return ((dataptr == NULL) && (ret == -EINVAL)) ? 0 : ret; in SYSCALL_DEFINE2()
153 if (get_user(pid, &header->pid)) in SYSCALL_DEFINE2()
154 return -EFAULT; in SYSCALL_DEFINE2()
157 return -EINVAL; in SYSCALL_DEFINE2()
164 * Annoying legacy format with 64-bit capabilities exposed in SYSCALL_DEFINE2()
165 * as two sets of 32-bit fields, so we need to split the in SYSCALL_DEFINE2()
174 * we silently drop the upper capabilities here. This in SYSCALL_DEFINE2()
180 * This behavior is considered fail-safe in SYSCALL_DEFINE2()
186 * (-ERANGE), but that causes legacy applications to in SYSCALL_DEFINE2()
192 return -EFAULT; in SYSCALL_DEFINE2()
203 * sys_capset - set capabilities for a process or (*) a group of processes
212 * The restrictions on setting capabilities are specified as:
218 * Returns 0 on success and < 0 on error.
233 if (get_user(pid, &header->pid)) in SYSCALL_DEFINE2()
234 return -EFAULT; in SYSCALL_DEFINE2()
238 return -EPERM; in SYSCALL_DEFINE2()
242 return -EFAULT; in SYSCALL_DEFINE2()
245 return -EFAULT; in SYSCALL_DEFINE2()
253 return -ENOMEM; in SYSCALL_DEFINE2()
270 * has_ns_capability - Does a task have a capability in a specific user ns
272 * @ns: target user namespace
278 * Note that this does not set PF_SUPERPRIV on the task.
281 struct user_namespace *ns, int cap) in has_ns_capability() argument
286 ret = security_capable(__task_cred(t), ns, cap, CAP_OPT_NONE); in has_ns_capability()
293 * has_capability - Does a task have a capability in init_user_ns
300 * Note that this does not set PF_SUPERPRIV on the task.
309 * has_ns_capability_noaudit - Does a task have a capability (unaudited)
310 * in a specific user ns.
312 * @ns: target user namespace
319 * Note that this does not set PF_SUPERPRIV on the task.
322 struct user_namespace *ns, int cap) in has_ns_capability_noaudit() argument
327 ret = security_capable(__task_cred(t), ns, cap, CAP_OPT_NOAUDIT); in has_ns_capability_noaudit()
334 * has_capability_noaudit - Does a task have a capability (unaudited) in the
335 * initial user ns
343 * Note that this does not set PF_SUPERPRIV on the task.
351 static bool ns_capable_common(struct user_namespace *ns, in ns_capable_common() argument
362 capable = security_capable(current_cred(), ns, cap, opts); in ns_capable_common()
364 current->flags |= PF_SUPERPRIV; in ns_capable_common()
371 * ns_capable - Determine if the current task has a superior capability in effect
372 * @ns: The usernamespace we want the capability in
378 * This sets PF_SUPERPRIV on the task if the capability is available on the
381 bool ns_capable(struct user_namespace *ns, int cap) in ns_capable() argument
383 return ns_capable_common(ns, cap, CAP_OPT_NONE); in ns_capable()
388 * ns_capable_noaudit - Determine if the current task has a superior capability
390 * @ns: The usernamespace we want the capability in
396 * This sets PF_SUPERPRIV on the task if the capability is available on the
399 bool ns_capable_noaudit(struct user_namespace *ns, int cap) in ns_capable_noaudit() argument
401 return ns_capable_common(ns, cap, CAP_OPT_NOAUDIT); in ns_capable_noaudit()
406 * ns_capable_setid - Determine if the current task has a superior capability
409 * @ns: The usernamespace we want the capability in
415 * This sets PF_SUPERPRIV on the task if the capability is available on the
418 bool ns_capable_setid(struct user_namespace *ns, int cap) in ns_capable_setid() argument
420 return ns_capable_common(ns, cap, CAP_OPT_INSETID); in ns_capable_setid()
425 * capable - Determine if the current task has a superior capability in effect
431 * This sets PF_SUPERPRIV on the task if the capability is available on the
442 * file_ns_capable - Determine if the file's opener had a capability in effect
443 * @file: The file we want to check
444 * @ns: The usernamespace we want the capability in
453 bool file_ns_capable(const struct file *file, struct user_namespace *ns, in file_ns_capable() argument
460 if (security_capable(file->f_cred, ns, cap, CAP_OPT_NONE) == 0) in file_ns_capable()
468 * privileged_wrt_inode_uidgid - Do capabilities in the namespace work over the inode?
469 * @ns: The user namespace in question
475 bool privileged_wrt_inode_uidgid(struct user_namespace *ns, in privileged_wrt_inode_uidgid() argument
479 return vfsuid_has_mapping(ns, i_uid_into_vfsuid(idmap, inode)) && in privileged_wrt_inode_uidgid()
480 vfsgid_has_mapping(ns, i_gid_into_vfsgid(idmap, inode)); in privileged_wrt_inode_uidgid()
484 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
496 struct user_namespace *ns = current_user_ns(); in capable_wrt_inode_uidgid() local
498 return ns_capable(ns, cap) && in capable_wrt_inode_uidgid()
499 privileged_wrt_inode_uidgid(ns, idmap, inode); in capable_wrt_inode_uidgid()
504 * ptracer_capable - Determine if the ptracer holds CAP_SYS_PTRACE in the namespace
506 * @ns: The user namespace to search for CAP_SYS_PTRACE in
511 bool ptracer_capable(struct task_struct *tsk, struct user_namespace *ns) in ptracer_capable() argument
517 cred = rcu_dereference(tsk->ptracer_cred); in ptracer_capable()
519 ret = security_capable(cred, ns, CAP_SYS_PTRACE, in ptracer_capable()