Commit ef36b9af authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull vfs fget updates from Al Viro:
 "fget() to fdget() conversions"

* tag 'pull-fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  fuse_dev_ioctl(): switch to fdget()
  cgroup_get_from_fd(): switch to fdget_raw()
  bpf: switch to fdget_raw()
  build_mount_idmapped(): switch to fdget()
  kill the last remaining user of proc_ns_fget()
  SVM-SEV: convert the rest of fget() uses to fdget() in there
  convert sgx_set_attribute() to fdget()/fdput()
  convert setns(2) to fdget()/fdput()
parents 61d325dc 4a892c0f
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -892,20 +892,19 @@ static struct miscdevice sgx_dev_provision = {
int sgx_set_attribute(unsigned long *allowed_attributes,
		      unsigned int attribute_fd)
{
	struct file *file;
	struct fd f = fdget(attribute_fd);

	file = fget(attribute_fd);
	if (!file)
	if (!f.file)
		return -EINVAL;

	if (file->f_op != &sgx_provision_fops) {
		fput(file);
	if (f.file->f_op != &sgx_provision_fops) {
		fdput(f);
		return -EINVAL;
	}

	*allowed_attributes |= SGX_ATTR_PROVISIONKEY;

	fput(file);
	fdput(f);
	return 0;
}
EXPORT_SYMBOL_GPL(sgx_set_attribute);
+14 −12
Original line number Diff line number Diff line
@@ -1767,18 +1767,20 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
{
	struct kvm_sev_info *dst_sev = &to_kvm_svm(kvm)->sev_info;
	struct kvm_sev_info *src_sev, *cg_cleanup_sev;
	struct file *source_kvm_file;
	struct fd f = fdget(source_fd);
	struct kvm *source_kvm;
	bool charged = false;
	int ret;

	source_kvm_file = fget(source_fd);
	if (!file_is_kvm(source_kvm_file)) {
	if (!f.file)
		return -EBADF;

	if (!file_is_kvm(f.file)) {
		ret = -EBADF;
		goto out_fput;
	}

	source_kvm = source_kvm_file->private_data;
	source_kvm = f.file->private_data;
	ret = sev_lock_two_vms(kvm, source_kvm);
	if (ret)
		goto out_fput;
@@ -1828,8 +1830,7 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
out_unlock:
	sev_unlock_two_vms(kvm, source_kvm);
out_fput:
	if (source_kvm_file)
		fput(source_kvm_file);
	fdput(f);
	return ret;
}

@@ -2046,18 +2047,20 @@ int sev_mem_enc_unregister_region(struct kvm *kvm,

int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
{
	struct file *source_kvm_file;
	struct fd f = fdget(source_fd);
	struct kvm *source_kvm;
	struct kvm_sev_info *source_sev, *mirror_sev;
	int ret;

	source_kvm_file = fget(source_fd);
	if (!file_is_kvm(source_kvm_file)) {
	if (!f.file)
		return -EBADF;

	if (!file_is_kvm(f.file)) {
		ret = -EBADF;
		goto e_source_fput;
	}

	source_kvm = source_kvm_file->private_data;
	source_kvm = f.file->private_data;
	ret = sev_lock_two_vms(kvm, source_kvm);
	if (ret)
		goto e_source_fput;
@@ -2103,8 +2106,7 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
e_unlock:
	sev_unlock_two_vms(kvm, source_kvm);
e_source_fput:
	if (source_kvm_file)
		fput(source_kvm_file);
	fdput(f);
	return ret;
}

+21 −20
Original line number Diff line number Diff line
@@ -2257,30 +2257,31 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
	int res;
	int oldfd;
	struct fuse_dev *fud = NULL;
	struct fd f;

	switch (cmd) {
	case FUSE_DEV_IOC_CLONE:
		res = -EFAULT;
		if (!get_user(oldfd, (__u32 __user *)arg)) {
			struct file *old = fget(oldfd);
		if (get_user(oldfd, (__u32 __user *)arg))
			return -EFAULT;

		f = fdget(oldfd);
		if (!f.file)
			return -EINVAL;

			res = -EINVAL;
			if (old) {
		/*
		 * Check against file->f_op because CUSE
		 * uses the same ioctl handler.
		 */
				if (old->f_op == file->f_op)
					fud = fuse_get_dev(old);
		if (f.file->f_op == file->f_op)
			fud = fuse_get_dev(f.file);

		res = -EINVAL;
		if (fud) {
			mutex_lock(&fuse_mutex);
			res = fuse_device_clone(fud->fc, file);
			mutex_unlock(&fuse_mutex);
		}
				fput(old);
			}
		}
		fdput(f);
		break;
	default:
		res = -ENOTTY;
+6 −6
Original line number Diff line number Diff line
@@ -4194,7 +4194,7 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
	int err = 0;
	struct ns_common *ns;
	struct user_namespace *mnt_userns;
	struct file *file;
	struct fd f;

	if (!((attr->attr_set | attr->attr_clr) & MOUNT_ATTR_IDMAP))
		return 0;
@@ -4210,16 +4210,16 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
	if (attr->userns_fd > INT_MAX)
		return -EINVAL;

	file = fget(attr->userns_fd);
	if (!file)
	f = fdget(attr->userns_fd);
	if (!f.file)
		return -EBADF;

	if (!proc_ns_file(file)) {
	if (!proc_ns_file(f.file)) {
		err = -EINVAL;
		goto out_fput;
	}

	ns = get_proc_ns(file_inode(file));
	ns = get_proc_ns(file_inode(f.file));
	if (ns->ops->type != CLONE_NEWUSER) {
		err = -EINVAL;
		goto out_fput;
@@ -4248,7 +4248,7 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
	kattr->mnt_userns = get_user_ns(mnt_userns);

out_fput:
	fput(file);
	fdput(f);
	return err;
}

+0 −18
Original line number Diff line number Diff line
@@ -235,24 +235,6 @@ bool proc_ns_file(const struct file *file)
	return file->f_op == &ns_file_operations;
}

struct file *proc_ns_fget(int fd)
{
	struct file *file;

	file = fget(fd);
	if (!file)
		return ERR_PTR(-EBADF);

	if (file->f_op != &ns_file_operations)
		goto out_invalid;

	return file;

out_invalid:
	fput(file);
	return ERR_PTR(-EINVAL);
}

/**
 * ns_match() - Returns true if current namespace matches dev/ino provided.
 * @ns: current namespace
Loading