/* Calculate the new process capability sets from the capability sets attached to a file.  */
static int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps, struct linux_binprm *bprm, bool *effective)
/* Calculate the new process capability sets from the capability sets attached to a file.  */
static int bprm_caps_from_vfs_caps(struct cpu_vfs_cap_data *caps, struct linux_binprm *bprm, bool *effective)
{
	struct cred *new = bprm->cred;
	unsigned i;
	int ret = 0;
	if (caps->magic_etc & VFS_CAP_FLAGS_EFFECTIVE)
		*effective = true;
	CAP_FOR_EACH_U32(i) {
		__u32 permitted = caps->permitted.cap[i];
		__u32 inheritable = caps->inheritable.cap[i];
		new->cap_permitted.cap[i] =
			(new->cap_bset.cap[i] & permitted) |
			(new->cap_inheritable.cap[i] & inheritable);
		if (permitted & ~new->cap_permitted.cap[i])
			ret = -EPERM;
	}
	return *effective ? ret : 0;
}