struct fd layout change (and conversion to accessor helpers)
-----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQQqUNBr3gm4hGXdBJlZ7Krx/gZQ6wUCZvDNmgAKCRBZ7Krx/gZQ 63zrAP9vI0rf55v27twiabe9LnI7aSx5ckoqXxFIFxyT3dOYpQD/bPmoApnWDD3d 592+iDgLsema/H/0/CqfqlaNtDNY8Q0= =HUl5 -----END PGP SIGNATURE----- Merge tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs Pull 'struct fd' updates from Al Viro: "Just the 'struct fd' layout change, with conversion to accessor helpers" * tag 'pull-stable-struct_fd' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: add struct fd constructors, get rid of __to_fd() struct fd: representation change introduce fd_file(), convert all accessors to it.
This commit is contained in:
commit
f8ffbc365f
@ -160,10 +160,10 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
|
|||||||
.count = count
|
.count = count
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!arg.file)
|
if (!fd_file(arg))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(arg.file, &buf.ctx);
|
error = iterate_dir(fd_file(arg), &buf.ctx);
|
||||||
if (error >= 0)
|
if (error >= 0)
|
||||||
error = buf.error;
|
error = buf.error;
|
||||||
if (count != buf.count)
|
if (count != buf.count)
|
||||||
|
@ -239,19 +239,19 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
struct flock64 flock;
|
struct flock64 flock;
|
||||||
long err = -EBADF;
|
long err = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case F_GETLK64:
|
case F_GETLK64:
|
||||||
case F_OFD_GETLK:
|
case F_OFD_GETLK:
|
||||||
err = security_file_fcntl(f.file, cmd, arg);
|
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = get_oabi_flock(&flock, argp);
|
err = get_oabi_flock(&flock, argp);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fcntl_getlk64(f.file, cmd, &flock);
|
err = fcntl_getlk64(fd_file(f), cmd, &flock);
|
||||||
if (!err)
|
if (!err)
|
||||||
err = put_oabi_flock(&flock, argp);
|
err = put_oabi_flock(&flock, argp);
|
||||||
break;
|
break;
|
||||||
@ -259,13 +259,13 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
case F_SETLKW64:
|
case F_SETLKW64:
|
||||||
case F_OFD_SETLK:
|
case F_OFD_SETLK:
|
||||||
case F_OFD_SETLKW:
|
case F_OFD_SETLKW:
|
||||||
err = security_file_fcntl(f.file, cmd, arg);
|
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = get_oabi_flock(&flock, argp);
|
err = get_oabi_flock(&flock, argp);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fcntl_setlk64(fd, f.file, cmd, &flock);
|
err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = sys_fcntl64(fd, cmd, arg);
|
err = sys_fcntl64(fd, cmd, arg);
|
||||||
|
@ -118,12 +118,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
struct fd f;
|
struct fd f;
|
||||||
|
|
||||||
f = fdget(tablefd);
|
f = fdget(tablefd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {
|
list_for_each_entry_rcu(stt, &kvm->arch.spapr_tce_tables, list) {
|
||||||
if (stt == f.file->private_data) {
|
if (stt == fd_file(f)->private_data) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1938,11 +1938,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
|
|
||||||
r = -EBADF;
|
r = -EBADF;
|
||||||
f = fdget(cap->args[0]);
|
f = fdget(cap->args[0]);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
dev = kvm_device_from_filp(f.file);
|
dev = kvm_device_from_filp(fd_file(f));
|
||||||
if (dev)
|
if (dev)
|
||||||
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
|
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
|
||||||
|
|
||||||
@ -1957,11 +1957,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
|
|
||||||
r = -EBADF;
|
r = -EBADF;
|
||||||
f = fdget(cap->args[0]);
|
f = fdget(cap->args[0]);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
dev = kvm_device_from_filp(f.file);
|
dev = kvm_device_from_filp(fd_file(f));
|
||||||
if (dev) {
|
if (dev) {
|
||||||
if (xics_on_xive())
|
if (xics_on_xive())
|
||||||
r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);
|
r = kvmppc_xive_connect_vcpu(dev, vcpu, cap->args[1]);
|
||||||
@ -1980,7 +1980,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
|
|
||||||
r = -EBADF;
|
r = -EBADF;
|
||||||
f = fdget(cap->args[0]);
|
f = fdget(cap->args[0]);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
r = -ENXIO;
|
r = -ENXIO;
|
||||||
@ -1990,7 +1990,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
}
|
}
|
||||||
|
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
dev = kvm_device_from_filp(f.file);
|
dev = kvm_device_from_filp(fd_file(f));
|
||||||
if (dev)
|
if (dev)
|
||||||
r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
|
r = kvmppc_xive_native_connect_vcpu(dev, vcpu,
|
||||||
cap->args[1]);
|
cap->args[1]);
|
||||||
|
@ -66,8 +66,8 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
|
|||||||
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
||||||
struct fd neighbor = fdget(neighbor_fd);
|
struct fd neighbor = fdget(neighbor_fd);
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
if (neighbor.file) {
|
if (fd_file(neighbor)) {
|
||||||
ret = calls->create_thread(name, flags, mode, neighbor.file);
|
ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
|
||||||
fdput(neighbor);
|
fdput(neighbor);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -89,8 +89,8 @@ SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)
|
|||||||
|
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
arg = fdget(fd);
|
arg = fdget(fd);
|
||||||
if (arg.file) {
|
if (fd_file(arg)) {
|
||||||
ret = calls->spu_run(arg.file, unpc, ustatus);
|
ret = calls->spu_run(fd_file(arg), unpc, ustatus);
|
||||||
fdput(arg);
|
fdput(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,10 +903,10 @@ int sgx_set_attribute(unsigned long *allowed_attributes,
|
|||||||
{
|
{
|
||||||
struct fd f = fdget(attribute_fd);
|
struct fd f = fdget(attribute_fd);
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (f.file->f_op != &sgx_provision_fops) {
|
if (fd_file(f)->f_op != &sgx_provision_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -534,10 +534,10 @@ static int __sev_issue_cmd(int fd, int id, void *data, int *error)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = sev_issue_cmd_external_user(f.file, id, data, error);
|
ret = sev_issue_cmd_external_user(fd_file(f), id, data, error);
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret;
|
return ret;
|
||||||
@ -2078,15 +2078,15 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
|||||||
bool charged = false;
|
bool charged = false;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!file_is_kvm(f.file)) {
|
if (!file_is_kvm(fd_file(f))) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
|
|
||||||
source_kvm = f.file->private_data;
|
source_kvm = fd_file(f)->private_data;
|
||||||
ret = sev_lock_two_vms(kvm, source_kvm);
|
ret = sev_lock_two_vms(kvm, source_kvm);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
@ -2803,15 +2803,15 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
|||||||
struct kvm_sev_info *source_sev, *mirror_sev;
|
struct kvm_sev_info *source_sev, *mirror_sev;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!file_is_kvm(f.file)) {
|
if (!file_is_kvm(fd_file(f))) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto e_source_fput;
|
goto e_source_fput;
|
||||||
}
|
}
|
||||||
|
|
||||||
source_kvm = f.file->private_data;
|
source_kvm = fd_file(f)->private_data;
|
||||||
ret = sev_lock_two_vms(kvm, source_kvm);
|
ret = sev_lock_two_vms(kvm, source_kvm);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto e_source_fput;
|
goto e_source_fput;
|
||||||
|
@ -42,10 +42,10 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
|
|||||||
uint32_t id;
|
uint32_t id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
r = amdgpu_file_to_fpriv(f.file, &fpriv);
|
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
||||||
if (r) {
|
if (r) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return r;
|
return r;
|
||||||
@ -71,10 +71,10 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
|
|||||||
struct amdgpu_ctx *ctx;
|
struct amdgpu_ctx *ctx;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
r = amdgpu_file_to_fpriv(f.file, &fpriv);
|
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
||||||
if (r) {
|
if (r) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return r;
|
return r;
|
||||||
|
@ -715,16 +715,16 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (f.file->f_op != &drm_syncobj_file_fops) {
|
if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* take a reference to put in the idr */
|
/* take a reference to put in the idr */
|
||||||
syncobj = f.file->private_data;
|
syncobj = fd_file(f)->private_data;
|
||||||
drm_syncobj_get(syncobj);
|
drm_syncobj_get(syncobj);
|
||||||
|
|
||||||
idr_preload(GFP_KERNEL);
|
idr_preload(GFP_KERNEL);
|
||||||
|
@ -1624,13 +1624,13 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file,
|
|||||||
|
|
||||||
/* Get current fd to protect against it being closed */
|
/* Get current fd to protect against it being closed */
|
||||||
f = fdget(cmd.fd);
|
f = fdget(cmd.fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
if (f.file->f_op != &ucma_fops) {
|
if (fd_file(f)->f_op != &ucma_fops) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto file_put;
|
goto file_put;
|
||||||
}
|
}
|
||||||
cur_file = f.file->private_data;
|
cur_file = fd_file(f)->private_data;
|
||||||
|
|
||||||
/* Validate current fd and prevent destruction of id. */
|
/* Validate current fd and prevent destruction of id. */
|
||||||
ctx = ucma_get_ctx(cur_file, cmd.id);
|
ctx = ucma_get_ctx(cur_file, cmd.id);
|
||||||
|
@ -572,7 +572,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
|
|||||||
struct inode *inode = NULL;
|
struct inode *inode = NULL;
|
||||||
int new_xrcd = 0;
|
int new_xrcd = 0;
|
||||||
struct ib_device *ib_dev;
|
struct ib_device *ib_dev;
|
||||||
struct fd f = {};
|
struct fd f = EMPTY_FD;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = uverbs_request(attrs, &cmd, sizeof(cmd));
|
ret = uverbs_request(attrs, &cmd, sizeof(cmd));
|
||||||
@ -584,12 +584,12 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
|
|||||||
if (cmd.fd != -1) {
|
if (cmd.fd != -1) {
|
||||||
/* search for file descriptor */
|
/* search for file descriptor */
|
||||||
f = fdget(cmd.fd);
|
f = fdget(cmd.fd);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto err_tree_mutex_unlock;
|
goto err_tree_mutex_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = file_inode(f.file);
|
inode = file_inode(fd_file(f));
|
||||||
xrcd = find_xrcd(ibudev, inode);
|
xrcd = find_xrcd(ibudev, inode);
|
||||||
if (!xrcd && !(cmd.oflags & O_CREAT)) {
|
if (!xrcd && !(cmd.oflags & O_CREAT)) {
|
||||||
/* no file descriptor. Need CREATE flag */
|
/* no file descriptor. Need CREATE flag */
|
||||||
@ -632,7 +632,7 @@ static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
|
|||||||
atomic_inc(&xrcd->usecnt);
|
atomic_inc(&xrcd->usecnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.file)
|
if (fd_file(f))
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
mutex_unlock(&ibudev->xrcd_tree_mutex);
|
mutex_unlock(&ibudev->xrcd_tree_mutex);
|
||||||
@ -648,7 +648,7 @@ err:
|
|||||||
uobj_alloc_abort(&obj->uobject, attrs);
|
uobj_alloc_abort(&obj->uobject, attrs);
|
||||||
|
|
||||||
err_tree_mutex_unlock:
|
err_tree_mutex_unlock:
|
||||||
if (f.file)
|
if (fd_file(f))
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
mutex_unlock(&ibudev->xrcd_tree_mutex);
|
mutex_unlock(&ibudev->xrcd_tree_mutex);
|
||||||
|
@ -254,12 +254,12 @@ media_request_get_by_fd(struct media_device *mdev, int request_fd)
|
|||||||
return ERR_PTR(-EBADR);
|
return ERR_PTR(-EBADR);
|
||||||
|
|
||||||
f = fdget(request_fd);
|
f = fdget(request_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto err_no_req_fd;
|
goto err_no_req_fd;
|
||||||
|
|
||||||
if (f.file->f_op != &request_fops)
|
if (fd_file(f)->f_op != &request_fops)
|
||||||
goto err_fput;
|
goto err_fput;
|
||||||
req = f.file->private_data;
|
req = fd_file(f)->private_data;
|
||||||
if (req->mdev != mdev)
|
if (req->mdev != mdev)
|
||||||
goto err_fput;
|
goto err_fput;
|
||||||
|
|
||||||
|
@ -820,20 +820,20 @@ struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
|
|||||||
struct lirc_fh *fh;
|
struct lirc_fh *fh;
|
||||||
struct rc_dev *dev;
|
struct rc_dev *dev;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (f.file->f_op != &lirc_fops) {
|
if (fd_file(f)->f_op != &lirc_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write && !(f.file->f_mode & FMODE_WRITE)) {
|
if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EPERM);
|
return ERR_PTR(-EPERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = f.file->private_data;
|
fh = fd_file(f)->private_data;
|
||||||
dev = fh->rc;
|
dev = fh->rc;
|
||||||
|
|
||||||
get_device(&dev->dev);
|
get_device(&dev->dev);
|
||||||
|
@ -112,7 +112,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
|
|||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
mutex_lock(&group->group_lock);
|
mutex_lock(&group->group_lock);
|
||||||
@ -125,13 +125,13 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
|
|||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
container = vfio_container_from_file(f.file);
|
container = vfio_container_from_file(fd_file(f));
|
||||||
if (container) {
|
if (container) {
|
||||||
ret = vfio_container_attach_group(container, group);
|
ret = vfio_container_attach_group(container, group);
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
iommufd = iommufd_ctx_from_file(f.file);
|
iommufd = iommufd_ctx_from_file(fd_file(f));
|
||||||
if (!IS_ERR(iommufd)) {
|
if (!IS_ERR(iommufd)) {
|
||||||
if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
|
if (IS_ENABLED(CONFIG_VFIO_NOIOMMU) &&
|
||||||
group->type == VFIO_NO_IOMMU)
|
group->type == VFIO_NO_IOMMU)
|
||||||
|
@ -134,12 +134,12 @@ int vfio_virqfd_enable(void *opaque,
|
|||||||
INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);
|
INIT_WORK(&virqfd->flush_inject, virqfd_flush_inject);
|
||||||
|
|
||||||
irqfd = fdget(fd);
|
irqfd = fdget(fd);
|
||||||
if (!irqfd.file) {
|
if (!fd_file(irqfd)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto err_fd;
|
goto err_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = eventfd_ctx_fileget(irqfd.file);
|
ctx = eventfd_ctx_fileget(fd_file(irqfd));
|
||||||
if (IS_ERR(ctx)) {
|
if (IS_ERR(ctx)) {
|
||||||
ret = PTR_ERR(ctx);
|
ret = PTR_ERR(ctx);
|
||||||
goto err_ctx;
|
goto err_ctx;
|
||||||
@ -171,7 +171,7 @@ int vfio_virqfd_enable(void *opaque,
|
|||||||
init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
|
init_waitqueue_func_entry(&virqfd->wait, virqfd_wakeup);
|
||||||
init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
|
init_poll_funcptr(&virqfd->pt, virqfd_ptable_queue_proc);
|
||||||
|
|
||||||
events = vfs_poll(irqfd.file, &virqfd->pt);
|
events = vfs_poll(fd_file(irqfd), &virqfd->pt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if there was an event already pending on the eventfd
|
* Check if there was an event already pending on the eventfd
|
||||||
|
@ -125,12 +125,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
|
|||||||
INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work);
|
INIT_WORK(&irqfd->shutdown, hsm_irqfd_shutdown_work);
|
||||||
|
|
||||||
f = fdget(args->fd);
|
f = fdget(args->fd);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
eventfd = eventfd_ctx_fileget(f.file);
|
eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||||
if (IS_ERR(eventfd)) {
|
if (IS_ERR(eventfd)) {
|
||||||
ret = PTR_ERR(eventfd);
|
ret = PTR_ERR(eventfd);
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -157,7 +157,7 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
|
|||||||
mutex_unlock(&vm->irqfds_lock);
|
mutex_unlock(&vm->irqfds_lock);
|
||||||
|
|
||||||
/* Check the pending event in this stage */
|
/* Check the pending event in this stage */
|
||||||
events = vfs_poll(f.file, &irqfd->pt);
|
events = vfs_poll(fd_file(f), &irqfd->pt);
|
||||||
|
|
||||||
if (events & EPOLLIN)
|
if (events & EPOLLIN)
|
||||||
acrn_irqfd_inject(irqfd);
|
acrn_irqfd_inject(irqfd);
|
||||||
|
@ -959,12 +959,12 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
|
|||||||
INIT_WORK(&kirqfd->shutdown, irqfd_shutdown);
|
INIT_WORK(&kirqfd->shutdown, irqfd_shutdown);
|
||||||
|
|
||||||
f = fdget(irqfd->fd);
|
f = fdget(irqfd->fd);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto error_kfree;
|
goto error_kfree;
|
||||||
}
|
}
|
||||||
|
|
||||||
kirqfd->eventfd = eventfd_ctx_fileget(f.file);
|
kirqfd->eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||||
if (IS_ERR(kirqfd->eventfd)) {
|
if (IS_ERR(kirqfd->eventfd)) {
|
||||||
ret = PTR_ERR(kirqfd->eventfd);
|
ret = PTR_ERR(kirqfd->eventfd);
|
||||||
goto error_fd_put;
|
goto error_fd_put;
|
||||||
@ -995,7 +995,7 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *irqfd)
|
|||||||
* Check if there was an event already pending on the eventfd before we
|
* Check if there was an event already pending on the eventfd before we
|
||||||
* registered, and trigger it as if we didn't miss it.
|
* registered, and trigger it as if we didn't miss it.
|
||||||
*/
|
*/
|
||||||
events = vfs_poll(f.file, &kirqfd->pt);
|
events = vfs_poll(fd_file(f), &kirqfd->pt);
|
||||||
if (events & EPOLLIN)
|
if (events & EPOLLIN)
|
||||||
irqfd_inject(kirqfd);
|
irqfd_inject(kirqfd);
|
||||||
|
|
||||||
@ -1345,12 +1345,12 @@ static int privcmd_ioeventfd_assign(struct privcmd_ioeventfd *ioeventfd)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
f = fdget(ioeventfd->event_fd);
|
f = fdget(ioeventfd->event_fd);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto error_kfree;
|
goto error_kfree;
|
||||||
}
|
}
|
||||||
|
|
||||||
kioeventfd->eventfd = eventfd_ctx_fileget(f.file);
|
kioeventfd->eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
if (IS_ERR(kioeventfd->eventfd)) {
|
if (IS_ERR(kioeventfd->eventfd)) {
|
||||||
|
@ -1310,12 +1310,12 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
|
|||||||
} else {
|
} else {
|
||||||
struct fd src = fdget(fd);
|
struct fd src = fdget(fd);
|
||||||
struct inode *src_inode;
|
struct inode *src_inode;
|
||||||
if (!src.file) {
|
if (!fd_file(src)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out_drop_write;
|
goto out_drop_write;
|
||||||
}
|
}
|
||||||
|
|
||||||
src_inode = file_inode(src.file);
|
src_inode = file_inode(fd_file(src));
|
||||||
if (src_inode->i_sb != file_inode(file)->i_sb) {
|
if (src_inode->i_sb != file_inode(file)->i_sb) {
|
||||||
btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
|
btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
|
||||||
"Snapshot src from another FS");
|
"Snapshot src from another FS");
|
||||||
|
@ -349,9 +349,9 @@ struct eventfd_ctx *eventfd_ctx_fdget(int fd)
|
|||||||
{
|
{
|
||||||
struct eventfd_ctx *ctx;
|
struct eventfd_ctx *ctx;
|
||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
ctx = eventfd_ctx_fileget(f.file);
|
ctx = eventfd_ctx_fileget(fd_file(f));
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
@ -2261,17 +2261,17 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
|
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
f = fdget(epfd);
|
f = fdget(epfd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto error_return;
|
goto error_return;
|
||||||
|
|
||||||
/* Get the "struct file *" for the target file */
|
/* Get the "struct file *" for the target file */
|
||||||
tf = fdget(fd);
|
tf = fdget(fd);
|
||||||
if (!tf.file)
|
if (!fd_file(tf))
|
||||||
goto error_fput;
|
goto error_fput;
|
||||||
|
|
||||||
/* The target file descriptor must support poll */
|
/* The target file descriptor must support poll */
|
||||||
error = -EPERM;
|
error = -EPERM;
|
||||||
if (!file_can_poll(tf.file))
|
if (!file_can_poll(fd_file(tf)))
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
|
|
||||||
/* Check if EPOLLWAKEUP is allowed */
|
/* Check if EPOLLWAKEUP is allowed */
|
||||||
@ -2284,7 +2284,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
* adding an epoll file descriptor inside itself.
|
* adding an epoll file descriptor inside itself.
|
||||||
*/
|
*/
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
if (f.file == tf.file || !is_file_epoll(f.file))
|
if (fd_file(f) == fd_file(tf) || !is_file_epoll(fd_file(f)))
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2295,7 +2295,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) {
|
if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) {
|
||||||
if (op == EPOLL_CTL_MOD)
|
if (op == EPOLL_CTL_MOD)
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
if (op == EPOLL_CTL_ADD && (is_file_epoll(tf.file) ||
|
if (op == EPOLL_CTL_ADD && (is_file_epoll(fd_file(tf)) ||
|
||||||
(epds->events & ~EPOLLEXCLUSIVE_OK_BITS)))
|
(epds->events & ~EPOLLEXCLUSIVE_OK_BITS)))
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
}
|
}
|
||||||
@ -2304,7 +2304,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
* At this point it is safe to assume that the "private_data" contains
|
* At this point it is safe to assume that the "private_data" contains
|
||||||
* our own data structure.
|
* our own data structure.
|
||||||
*/
|
*/
|
||||||
ep = f.file->private_data;
|
ep = fd_file(f)->private_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When we insert an epoll file descriptor inside another epoll file
|
* When we insert an epoll file descriptor inside another epoll file
|
||||||
@ -2325,16 +2325,16 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
if (error)
|
if (error)
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
if (op == EPOLL_CTL_ADD) {
|
if (op == EPOLL_CTL_ADD) {
|
||||||
if (READ_ONCE(f.file->f_ep) || ep->gen == loop_check_gen ||
|
if (READ_ONCE(fd_file(f)->f_ep) || ep->gen == loop_check_gen ||
|
||||||
is_file_epoll(tf.file)) {
|
is_file_epoll(fd_file(tf))) {
|
||||||
mutex_unlock(&ep->mtx);
|
mutex_unlock(&ep->mtx);
|
||||||
error = epoll_mutex_lock(&epnested_mutex, 0, nonblock);
|
error = epoll_mutex_lock(&epnested_mutex, 0, nonblock);
|
||||||
if (error)
|
if (error)
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
loop_check_gen++;
|
loop_check_gen++;
|
||||||
full_check = 1;
|
full_check = 1;
|
||||||
if (is_file_epoll(tf.file)) {
|
if (is_file_epoll(fd_file(tf))) {
|
||||||
tep = tf.file->private_data;
|
tep = fd_file(tf)->private_data;
|
||||||
error = -ELOOP;
|
error = -ELOOP;
|
||||||
if (ep_loop_check(ep, tep) != 0)
|
if (ep_loop_check(ep, tep) != 0)
|
||||||
goto error_tgt_fput;
|
goto error_tgt_fput;
|
||||||
@ -2350,14 +2350,14 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
* above, we can be sure to be able to use the item looked up by
|
* above, we can be sure to be able to use the item looked up by
|
||||||
* ep_find() till we release the mutex.
|
* ep_find() till we release the mutex.
|
||||||
*/
|
*/
|
||||||
epi = ep_find(ep, tf.file, fd);
|
epi = ep_find(ep, fd_file(tf), fd);
|
||||||
|
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case EPOLL_CTL_ADD:
|
case EPOLL_CTL_ADD:
|
||||||
if (!epi) {
|
if (!epi) {
|
||||||
epds->events |= EPOLLERR | EPOLLHUP;
|
epds->events |= EPOLLERR | EPOLLHUP;
|
||||||
error = ep_insert(ep, epds, tf.file, fd, full_check);
|
error = ep_insert(ep, epds, fd_file(tf), fd, full_check);
|
||||||
} else
|
} else
|
||||||
error = -EEXIST;
|
error = -EEXIST;
|
||||||
break;
|
break;
|
||||||
@ -2438,7 +2438,7 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events,
|
|||||||
|
|
||||||
/* Get the "struct file *" for the eventpoll file */
|
/* Get the "struct file *" for the eventpoll file */
|
||||||
f = fdget(epfd);
|
f = fdget(epfd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2446,14 +2446,14 @@ static int do_epoll_wait(int epfd, struct epoll_event __user *events,
|
|||||||
* the user passed to us _is_ an eventpoll file.
|
* the user passed to us _is_ an eventpoll file.
|
||||||
*/
|
*/
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
if (!is_file_epoll(f.file))
|
if (!is_file_epoll(fd_file(f)))
|
||||||
goto error_fput;
|
goto error_fput;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point it is safe to assume that the "private_data" contains
|
* At this point it is safe to assume that the "private_data" contains
|
||||||
* our own data structure.
|
* our own data structure.
|
||||||
*/
|
*/
|
||||||
ep = f.file->private_data;
|
ep = fd_file(f)->private_data;
|
||||||
|
|
||||||
/* Time to fish for events ... */
|
/* Time to fish for events ... */
|
||||||
error = ep_poll(ep, events, maxevents, to);
|
error = ep_poll(ep, events, maxevents, to);
|
||||||
|
@ -1343,10 +1343,10 @@ group_extend_out:
|
|||||||
me.moved_len = 0;
|
me.moved_len = 0;
|
||||||
|
|
||||||
donor = fdget(me.donor_fd);
|
donor = fdget(me.donor_fd);
|
||||||
if (!donor.file)
|
if (!fd_file(donor))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!(donor.file->f_mode & FMODE_WRITE)) {
|
if (!(fd_file(donor)->f_mode & FMODE_WRITE)) {
|
||||||
err = -EBADF;
|
err = -EBADF;
|
||||||
goto mext_out;
|
goto mext_out;
|
||||||
}
|
}
|
||||||
@ -1367,7 +1367,7 @@ group_extend_out:
|
|||||||
if (err)
|
if (err)
|
||||||
goto mext_out;
|
goto mext_out;
|
||||||
|
|
||||||
err = ext4_move_extents(filp, donor.file, me.orig_start,
|
err = ext4_move_extents(filp, fd_file(donor), me.orig_start,
|
||||||
me.donor_start, me.len, &me.moved_len);
|
me.donor_start, me.len, &me.moved_len);
|
||||||
mnt_drop_write_file(filp);
|
mnt_drop_write_file(filp);
|
||||||
|
|
||||||
|
@ -3014,10 +3014,10 @@ static int __f2fs_ioc_move_range(struct file *filp,
|
|||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
dst = fdget(range->dst_fd);
|
dst = fdget(range->dst_fd);
|
||||||
if (!dst.file)
|
if (!fd_file(dst))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!(dst.file->f_mode & FMODE_WRITE)) {
|
if (!(fd_file(dst)->f_mode & FMODE_WRITE)) {
|
||||||
err = -EBADF;
|
err = -EBADF;
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
@ -3026,7 +3026,7 @@ static int __f2fs_ioc_move_range(struct file *filp,
|
|||||||
if (err)
|
if (err)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
|
||||||
err = f2fs_move_file_range(filp, range->pos_in, dst.file,
|
err = f2fs_move_file_range(filp, range->pos_in, fd_file(dst),
|
||||||
range->pos_out, range->len);
|
range->pos_out, range->len);
|
||||||
|
|
||||||
mnt_drop_write_file(filp);
|
mnt_drop_write_file(filp);
|
||||||
|
38
fs/fcntl.c
38
fs/fcntl.c
@ -405,7 +405,7 @@ static long f_dupfd_query(int fd, struct file *filp)
|
|||||||
* overkill, but given our lockless file pointer lookup, the
|
* overkill, but given our lockless file pointer lookup, the
|
||||||
* alternatives are complicated.
|
* alternatives are complicated.
|
||||||
*/
|
*/
|
||||||
return f.file == filp;
|
return fd_file(f) == filp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Let the caller figure out whether a given file was just created. */
|
/* Let the caller figure out whether a given file was just created. */
|
||||||
@ -573,17 +573,17 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
|
|||||||
struct fd f = fdget_raw(fd);
|
struct fd f = fdget_raw(fd);
|
||||||
long err = -EBADF;
|
long err = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (unlikely(f.file->f_mode & FMODE_PATH)) {
|
if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
|
||||||
if (!check_fcntl_cmd(cmd))
|
if (!check_fcntl_cmd(cmd))
|
||||||
goto out1;
|
goto out1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = security_file_fcntl(f.file, cmd, arg);
|
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||||
if (!err)
|
if (!err)
|
||||||
err = do_fcntl(fd, cmd, arg, f.file);
|
err = do_fcntl(fd, cmd, arg, fd_file(f));
|
||||||
|
|
||||||
out1:
|
out1:
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -600,15 +600,15 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
|
|||||||
struct flock64 flock;
|
struct flock64 flock;
|
||||||
long err = -EBADF;
|
long err = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (unlikely(f.file->f_mode & FMODE_PATH)) {
|
if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
|
||||||
if (!check_fcntl_cmd(cmd))
|
if (!check_fcntl_cmd(cmd))
|
||||||
goto out1;
|
goto out1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = security_file_fcntl(f.file, cmd, arg);
|
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||||
if (err)
|
if (err)
|
||||||
goto out1;
|
goto out1;
|
||||||
|
|
||||||
@ -618,7 +618,7 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
|
|||||||
err = -EFAULT;
|
err = -EFAULT;
|
||||||
if (copy_from_user(&flock, argp, sizeof(flock)))
|
if (copy_from_user(&flock, argp, sizeof(flock)))
|
||||||
break;
|
break;
|
||||||
err = fcntl_getlk64(f.file, cmd, &flock);
|
err = fcntl_getlk64(fd_file(f), cmd, &flock);
|
||||||
if (!err && copy_to_user(argp, &flock, sizeof(flock)))
|
if (!err && copy_to_user(argp, &flock, sizeof(flock)))
|
||||||
err = -EFAULT;
|
err = -EFAULT;
|
||||||
break;
|
break;
|
||||||
@ -629,10 +629,10 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
|
|||||||
err = -EFAULT;
|
err = -EFAULT;
|
||||||
if (copy_from_user(&flock, argp, sizeof(flock)))
|
if (copy_from_user(&flock, argp, sizeof(flock)))
|
||||||
break;
|
break;
|
||||||
err = fcntl_setlk64(fd, f.file, cmd, &flock);
|
err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = do_fcntl(fd, cmd, arg, f.file);
|
err = do_fcntl(fd, cmd, arg, fd_file(f));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
out1:
|
out1:
|
||||||
@ -737,15 +737,15 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
struct flock flock;
|
struct flock flock;
|
||||||
long err = -EBADF;
|
long err = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (unlikely(f.file->f_mode & FMODE_PATH)) {
|
if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
|
||||||
if (!check_fcntl_cmd(cmd))
|
if (!check_fcntl_cmd(cmd))
|
||||||
goto out_put;
|
goto out_put;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = security_file_fcntl(f.file, cmd, arg);
|
err = security_file_fcntl(fd_file(f), cmd, arg);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_put;
|
goto out_put;
|
||||||
|
|
||||||
@ -754,7 +754,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
err = get_compat_flock(&flock, compat_ptr(arg));
|
err = get_compat_flock(&flock, compat_ptr(arg));
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);
|
err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fixup_compat_flock(&flock);
|
err = fixup_compat_flock(&flock);
|
||||||
@ -766,7 +766,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
err = get_compat_flock64(&flock, compat_ptr(arg));
|
err = get_compat_flock64(&flock, compat_ptr(arg));
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock);
|
err = fcntl_getlk(fd_file(f), convert_fcntl_cmd(cmd), &flock);
|
||||||
if (!err)
|
if (!err)
|
||||||
err = put_compat_flock64(&flock, compat_ptr(arg));
|
err = put_compat_flock64(&flock, compat_ptr(arg));
|
||||||
break;
|
break;
|
||||||
@ -775,7 +775,7 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
err = get_compat_flock(&flock, compat_ptr(arg));
|
err = get_compat_flock(&flock, compat_ptr(arg));
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock);
|
err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock);
|
||||||
break;
|
break;
|
||||||
case F_SETLK64:
|
case F_SETLK64:
|
||||||
case F_SETLKW64:
|
case F_SETLKW64:
|
||||||
@ -784,10 +784,10 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
|
|||||||
err = get_compat_flock64(&flock, compat_ptr(arg));
|
err = get_compat_flock64(&flock, compat_ptr(arg));
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock);
|
err = fcntl_setlk(fd, fd_file(f), convert_fcntl_cmd(cmd), &flock);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
err = do_fcntl(fd, cmd, arg, f.file);
|
err = do_fcntl(fd, cmd, arg, fd_file(f));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
out_put:
|
out_put:
|
||||||
|
@ -140,9 +140,9 @@ static int get_path_from_fd(int fd, struct path *root)
|
|||||||
spin_unlock(&fs->lock);
|
spin_unlock(&fs->lock);
|
||||||
} else {
|
} else {
|
||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
*root = f.file->f_path;
|
*root = fd_file(f)->f_path;
|
||||||
path_get(root);
|
path_get(root);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
26
fs/file.c
26
fs/file.c
@ -1124,7 +1124,7 @@ EXPORT_SYMBOL(task_lookup_next_fdget_rcu);
|
|||||||
* The fput_needed flag returned by fget_light should be passed to the
|
* The fput_needed flag returned by fget_light should be passed to the
|
||||||
* corresponding fput_light.
|
* corresponding fput_light.
|
||||||
*/
|
*/
|
||||||
static unsigned long __fget_light(unsigned int fd, fmode_t mask)
|
static inline struct fd __fget_light(unsigned int fd, fmode_t mask)
|
||||||
{
|
{
|
||||||
struct files_struct *files = current->files;
|
struct files_struct *files = current->files;
|
||||||
struct file *file;
|
struct file *file;
|
||||||
@ -1141,22 +1141,22 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask)
|
|||||||
if (likely(atomic_read_acquire(&files->count) == 1)) {
|
if (likely(atomic_read_acquire(&files->count) == 1)) {
|
||||||
file = files_lookup_fd_raw(files, fd);
|
file = files_lookup_fd_raw(files, fd);
|
||||||
if (!file || unlikely(file->f_mode & mask))
|
if (!file || unlikely(file->f_mode & mask))
|
||||||
return 0;
|
return EMPTY_FD;
|
||||||
return (unsigned long)file;
|
return BORROWED_FD(file);
|
||||||
} else {
|
} else {
|
||||||
file = __fget_files(files, fd, mask);
|
file = __fget_files(files, fd, mask);
|
||||||
if (!file)
|
if (!file)
|
||||||
return 0;
|
return EMPTY_FD;
|
||||||
return FDPUT_FPUT | (unsigned long)file;
|
return CLONED_FD(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsigned long __fdget(unsigned int fd)
|
struct fd fdget(unsigned int fd)
|
||||||
{
|
{
|
||||||
return __fget_light(fd, FMODE_PATH);
|
return __fget_light(fd, FMODE_PATH);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__fdget);
|
EXPORT_SYMBOL(fdget);
|
||||||
|
|
||||||
unsigned long __fdget_raw(unsigned int fd)
|
struct fd fdget_raw(unsigned int fd)
|
||||||
{
|
{
|
||||||
return __fget_light(fd, 0);
|
return __fget_light(fd, 0);
|
||||||
}
|
}
|
||||||
@ -1177,16 +1177,16 @@ static inline bool file_needs_f_pos_lock(struct file *file)
|
|||||||
(file_count(file) > 1 || file->f_op->iterate_shared);
|
(file_count(file) > 1 || file->f_op->iterate_shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long __fdget_pos(unsigned int fd)
|
struct fd fdget_pos(unsigned int fd)
|
||||||
{
|
{
|
||||||
unsigned long v = __fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
struct file *file = (struct file *)(v & ~3);
|
struct file *file = fd_file(f);
|
||||||
|
|
||||||
if (file && file_needs_f_pos_lock(file)) {
|
if (file && file_needs_f_pos_lock(file)) {
|
||||||
v |= FDPUT_POS_UNLOCK;
|
f.word |= FDPUT_POS_UNLOCK;
|
||||||
mutex_lock(&file->f_pos_lock);
|
mutex_lock(&file->f_pos_lock);
|
||||||
}
|
}
|
||||||
return v;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __f_unlock_pos(struct file *f)
|
void __f_unlock_pos(struct file *f)
|
||||||
|
@ -394,13 +394,13 @@ SYSCALL_DEFINE5(fsconfig,
|
|||||||
}
|
}
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (f.file->f_op != &fscontext_fops)
|
if (fd_file(f)->f_op != &fscontext_fops)
|
||||||
goto out_f;
|
goto out_f;
|
||||||
|
|
||||||
fc = f.file->private_data;
|
fc = fd_file(f)->private_data;
|
||||||
if (fc->ops == &legacy_fs_context_ops) {
|
if (fc->ops == &legacy_fs_context_ops) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case FSCONFIG_SET_BINARY:
|
case FSCONFIG_SET_BINARY:
|
||||||
|
@ -2329,15 +2329,15 @@ static long fuse_dev_ioctl_clone(struct file *file, __u32 __user *argp)
|
|||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
f = fdget(oldfd);
|
f = fdget(oldfd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check against file->f_op because CUSE
|
* Check against file->f_op because CUSE
|
||||||
* uses the same ioctl handler.
|
* uses the same ioctl handler.
|
||||||
*/
|
*/
|
||||||
if (f.file->f_op == file->f_op)
|
if (fd_file(f)->f_op == file->f_op)
|
||||||
fud = fuse_get_dev(f.file);
|
fud = fuse_get_dev(fd_file(f));
|
||||||
|
|
||||||
res = -EINVAL;
|
res = -EINVAL;
|
||||||
if (fud) {
|
if (fud) {
|
||||||
|
30
fs/ioctl.c
30
fs/ioctl.c
@ -235,9 +235,9 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
|
|||||||
loff_t cloned;
|
loff_t cloned;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!src_file.file)
|
if (!fd_file(src_file))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
cloned = vfs_clone_file_range(src_file.file, off, dst_file, destoff,
|
cloned = vfs_clone_file_range(fd_file(src_file), off, dst_file, destoff,
|
||||||
olen, 0);
|
olen, 0);
|
||||||
if (cloned < 0)
|
if (cloned < 0)
|
||||||
ret = cloned;
|
ret = cloned;
|
||||||
@ -895,16 +895,16 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = security_file_ioctl(f.file, cmd, arg);
|
error = security_file_ioctl(fd_file(f), cmd, arg);
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
error = do_vfs_ioctl(f.file, fd, cmd, arg);
|
error = do_vfs_ioctl(fd_file(f), fd, cmd, arg);
|
||||||
if (error == -ENOIOCTLCMD)
|
if (error == -ENOIOCTLCMD)
|
||||||
error = vfs_ioctl(f.file, cmd, arg);
|
error = vfs_ioctl(fd_file(f), cmd, arg);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -953,32 +953,32 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = security_file_ioctl_compat(f.file, cmd, arg);
|
error = security_file_ioctl_compat(fd_file(f), cmd, arg);
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
/* FICLONE takes an int argument, so don't use compat_ptr() */
|
/* FICLONE takes an int argument, so don't use compat_ptr() */
|
||||||
case FICLONE:
|
case FICLONE:
|
||||||
error = ioctl_file_clone(f.file, arg, 0, 0, 0);
|
error = ioctl_file_clone(fd_file(f), arg, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if defined(CONFIG_X86_64)
|
#if defined(CONFIG_X86_64)
|
||||||
/* these get messy on amd64 due to alignment differences */
|
/* these get messy on amd64 due to alignment differences */
|
||||||
case FS_IOC_RESVSP_32:
|
case FS_IOC_RESVSP_32:
|
||||||
case FS_IOC_RESVSP64_32:
|
case FS_IOC_RESVSP64_32:
|
||||||
error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg));
|
error = compat_ioctl_preallocate(fd_file(f), 0, compat_ptr(arg));
|
||||||
break;
|
break;
|
||||||
case FS_IOC_UNRESVSP_32:
|
case FS_IOC_UNRESVSP_32:
|
||||||
case FS_IOC_UNRESVSP64_32:
|
case FS_IOC_UNRESVSP64_32:
|
||||||
error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE,
|
error = compat_ioctl_preallocate(fd_file(f), FALLOC_FL_PUNCH_HOLE,
|
||||||
compat_ptr(arg));
|
compat_ptr(arg));
|
||||||
break;
|
break;
|
||||||
case FS_IOC_ZERO_RANGE_32:
|
case FS_IOC_ZERO_RANGE_32:
|
||||||
error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE,
|
error = compat_ioctl_preallocate(fd_file(f), FALLOC_FL_ZERO_RANGE,
|
||||||
compat_ptr(arg));
|
compat_ptr(arg));
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -998,13 +998,13 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
|
|||||||
* argument.
|
* argument.
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
error = do_vfs_ioctl(f.file, fd, cmd,
|
error = do_vfs_ioctl(fd_file(f), fd, cmd,
|
||||||
(unsigned long)compat_ptr(arg));
|
(unsigned long)compat_ptr(arg));
|
||||||
if (error != -ENOIOCTLCMD)
|
if (error != -ENOIOCTLCMD)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (f.file->f_op->compat_ioctl)
|
if (fd_file(f)->f_op->compat_ioctl)
|
||||||
error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
|
error = fd_file(f)->f_op->compat_ioctl(fd_file(f), cmd, arg);
|
||||||
if (error == -ENOIOCTLCMD)
|
if (error == -ENOIOCTLCMD)
|
||||||
error = -ENOTTY;
|
error = -ENOTTY;
|
||||||
break;
|
break;
|
||||||
|
@ -178,10 +178,10 @@ ssize_t kernel_read_file_from_fd(int fd, loff_t offset, void **buf,
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (!f.file || !(f.file->f_mode & FMODE_READ))
|
if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = kernel_read_file(f.file, offset, buf, buf_size, file_size, id);
|
ret = kernel_read_file(fd_file(f), offset, buf, buf_size, file_size, id);
|
||||||
out:
|
out:
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret;
|
return ret;
|
||||||
|
14
fs/locks.c
14
fs/locks.c
@ -2157,15 +2157,15 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
|
|||||||
|
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (type != F_UNLCK && !(f.file->f_mode & (FMODE_READ | FMODE_WRITE)))
|
if (type != F_UNLCK && !(fd_file(f)->f_mode & (FMODE_READ | FMODE_WRITE)))
|
||||||
goto out_putf;
|
goto out_putf;
|
||||||
|
|
||||||
flock_make_lock(f.file, &fl, type);
|
flock_make_lock(fd_file(f), &fl, type);
|
||||||
|
|
||||||
error = security_file_lock(f.file, fl.c.flc_type);
|
error = security_file_lock(fd_file(f), fl.c.flc_type);
|
||||||
if (error)
|
if (error)
|
||||||
goto out_putf;
|
goto out_putf;
|
||||||
|
|
||||||
@ -2173,12 +2173,12 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
|
|||||||
if (can_sleep)
|
if (can_sleep)
|
||||||
fl.c.flc_flags |= FL_SLEEP;
|
fl.c.flc_flags |= FL_SLEEP;
|
||||||
|
|
||||||
if (f.file->f_op->flock)
|
if (fd_file(f)->f_op->flock)
|
||||||
error = f.file->f_op->flock(f.file,
|
error = fd_file(f)->f_op->flock(fd_file(f),
|
||||||
(can_sleep) ? F_SETLKW : F_SETLK,
|
(can_sleep) ? F_SETLKW : F_SETLK,
|
||||||
&fl);
|
&fl);
|
||||||
else
|
else
|
||||||
error = locks_lock_file_wait(f.file, &fl);
|
error = locks_lock_file_wait(fd_file(f), &fl);
|
||||||
|
|
||||||
locks_release_private(&fl);
|
locks_release_private(&fl);
|
||||||
out_putf:
|
out_putf:
|
||||||
|
10
fs/namei.c
10
fs/namei.c
@ -2506,25 +2506,25 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
|||||||
struct fd f = fdget_raw(nd->dfd);
|
struct fd f = fdget_raw(nd->dfd);
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (flags & LOOKUP_LINKAT_EMPTY) {
|
if (flags & LOOKUP_LINKAT_EMPTY) {
|
||||||
if (f.file->f_cred != current_cred() &&
|
if (fd_file(f)->f_cred != current_cred() &&
|
||||||
!ns_capable(f.file->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {
|
!ns_capable(fd_file(f)->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-ENOENT);
|
return ERR_PTR(-ENOENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dentry = f.file->f_path.dentry;
|
dentry = fd_file(f)->f_path.dentry;
|
||||||
|
|
||||||
if (*s && unlikely(!d_can_lookup(dentry))) {
|
if (*s && unlikely(!d_can_lookup(dentry))) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-ENOTDIR);
|
return ERR_PTR(-ENOTDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
nd->path = f.file->f_path;
|
nd->path = fd_file(f)->f_path;
|
||||||
if (flags & LOOKUP_RCU) {
|
if (flags & LOOKUP_RCU) {
|
||||||
nd->inode = nd->path.dentry->d_inode;
|
nd->inode = nd->path.dentry->d_inode;
|
||||||
nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
|
nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
|
||||||
|
@ -4134,14 +4134,14 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
f = fdget(fs_fd);
|
f = fdget(fs_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (f.file->f_op != &fscontext_fops)
|
if (fd_file(f)->f_op != &fscontext_fops)
|
||||||
goto err_fsfd;
|
goto err_fsfd;
|
||||||
|
|
||||||
fc = f.file->private_data;
|
fc = fd_file(f)->private_data;
|
||||||
|
|
||||||
ret = mutex_lock_interruptible(&fc->uapi_mutex);
|
ret = mutex_lock_interruptible(&fc->uapi_mutex);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -4684,15 +4684,15 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(attr->userns_fd);
|
f = fdget(attr->userns_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!proc_ns_file(f.file)) {
|
if (!proc_ns_file(fd_file(f))) {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
|
|
||||||
ns = get_proc_ns(file_inode(f.file));
|
ns = get_proc_ns(file_inode(fd_file(f)));
|
||||||
if (ns->ops->type != CLONE_NEWUSER) {
|
if (ns->ops->type != CLONE_NEWUSER) {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
@ -5292,13 +5292,13 @@ static struct mnt_namespace *grab_requested_mnt_ns(const struct mnt_id_req *kreq
|
|||||||
struct ns_common *ns;
|
struct ns_common *ns;
|
||||||
|
|
||||||
CLASS(fd, f)(kreq->spare);
|
CLASS(fd, f)(kreq->spare);
|
||||||
if (!f.file)
|
if (fd_empty(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (!proc_ns_file(f.file))
|
if (!proc_ns_file(fd_file(f)))
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
ns = get_proc_ns(file_inode(f.file));
|
ns = get_proc_ns(file_inode(fd_file(f)));
|
||||||
if (ns->ops->type != CLONE_NEWNS)
|
if (ns->ops->type != CLONE_NEWNS)
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
|
@ -1006,17 +1006,17 @@ static int fanotify_find_path(int dfd, const char __user *filename,
|
|||||||
struct fd f = fdget(dfd);
|
struct fd f = fdget(dfd);
|
||||||
|
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = -ENOTDIR;
|
ret = -ENOTDIR;
|
||||||
if ((flags & FAN_MARK_ONLYDIR) &&
|
if ((flags & FAN_MARK_ONLYDIR) &&
|
||||||
!(S_ISDIR(file_inode(f.file)->i_mode))) {
|
!(S_ISDIR(file_inode(fd_file(f))->i_mode))) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
*path = f.file->f_path;
|
*path = fd_file(f)->f_path;
|
||||||
path_get(path);
|
path_get(path);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
} else {
|
} else {
|
||||||
@ -1753,14 +1753,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
|
|||||||
}
|
}
|
||||||
|
|
||||||
f = fdget(fanotify_fd);
|
f = fdget(fanotify_fd);
|
||||||
if (unlikely(!f.file))
|
if (unlikely(!fd_file(f)))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
/* verify that this is indeed an fanotify instance */
|
/* verify that this is indeed an fanotify instance */
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (unlikely(f.file->f_op != &fanotify_fops))
|
if (unlikely(fd_file(f)->f_op != &fanotify_fops))
|
||||||
goto fput_and_out;
|
goto fput_and_out;
|
||||||
group = f.file->private_data;
|
group = fd_file(f)->private_data;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An unprivileged user is not allowed to setup mount nor filesystem
|
* An unprivileged user is not allowed to setup mount nor filesystem
|
||||||
|
@ -753,7 +753,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (unlikely(!f.file))
|
if (unlikely(!fd_file(f)))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
/* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */
|
/* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */
|
||||||
@ -763,7 +763,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* verify that this is indeed an inotify instance */
|
/* verify that this is indeed an inotify instance */
|
||||||
if (unlikely(f.file->f_op != &inotify_fops)) {
|
if (unlikely(fd_file(f)->f_op != &inotify_fops)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fput_and_out;
|
goto fput_and_out;
|
||||||
}
|
}
|
||||||
@ -780,7 +780,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
|
|||||||
|
|
||||||
/* inode held in place by reference to path; group by fget on fd */
|
/* inode held in place by reference to path; group by fget on fd */
|
||||||
inode = path.dentry->d_inode;
|
inode = path.dentry->d_inode;
|
||||||
group = f.file->private_data;
|
group = fd_file(f)->private_data;
|
||||||
|
|
||||||
/* create/update an inode mark */
|
/* create/update an inode mark */
|
||||||
ret = inotify_update_watch(group, inode, mask);
|
ret = inotify_update_watch(group, inode, mask);
|
||||||
@ -798,14 +798,14 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
|
|||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (unlikely(!f.file))
|
if (unlikely(!fd_file(f)))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
/* verify that this is indeed an inotify instance */
|
/* verify that this is indeed an inotify instance */
|
||||||
if (unlikely(f.file->f_op != &inotify_fops))
|
if (unlikely(fd_file(f)->f_op != &inotify_fops))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
group = f.file->private_data;
|
group = fd_file(f)->private_data;
|
||||||
|
|
||||||
i_mark = inotify_idr_find(group, wd);
|
i_mark = inotify_idr_find(group, wd);
|
||||||
if (unlikely(!i_mark))
|
if (unlikely(!i_mark))
|
||||||
|
@ -1785,17 +1785,17 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file == NULL)
|
if (fd_file(f) == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||
|
if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||
|
||||||
reg->hr_block_bytes == 0)
|
reg->hr_block_bytes == 0)
|
||||||
goto out2;
|
goto out2;
|
||||||
|
|
||||||
if (!S_ISBLK(f.file->f_mapping->host->i_mode))
|
if (!S_ISBLK(fd_file(f)->f_mapping->host->i_mode))
|
||||||
goto out2;
|
goto out2;
|
||||||
|
|
||||||
reg->hr_bdev_file = bdev_file_open_by_dev(f.file->f_mapping->host->i_rdev,
|
reg->hr_bdev_file = bdev_file_open_by_dev(fd_file(f)->f_mapping->host->i_rdev,
|
||||||
BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
|
BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL);
|
||||||
if (IS_ERR(reg->hr_bdev_file)) {
|
if (IS_ERR(reg->hr_bdev_file)) {
|
||||||
ret = PTR_ERR(reg->hr_bdev_file);
|
ret = PTR_ERR(reg->hr_bdev_file);
|
||||||
|
24
fs/open.c
24
fs/open.c
@ -193,10 +193,10 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
|
|||||||
if (length < 0)
|
if (length < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = do_ftruncate(f.file, length, small);
|
error = do_ftruncate(fd_file(f), length, small);
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return error;
|
return error;
|
||||||
@ -352,8 +352,8 @@ int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int error = -EBADF;
|
int error = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
error = vfs_fallocate(f.file, mode, offset, len);
|
error = vfs_fallocate(fd_file(f), mode, offset, len);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
@ -584,16 +584,16 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
error = -ENOTDIR;
|
error = -ENOTDIR;
|
||||||
if (!d_can_lookup(f.file->f_path.dentry))
|
if (!d_can_lookup(fd_file(f)->f_path.dentry))
|
||||||
goto out_putf;
|
goto out_putf;
|
||||||
|
|
||||||
error = file_permission(f.file, MAY_EXEC | MAY_CHDIR);
|
error = file_permission(fd_file(f), MAY_EXEC | MAY_CHDIR);
|
||||||
if (!error)
|
if (!error)
|
||||||
set_fs_pwd(current->fs, &f.file->f_path);
|
set_fs_pwd(current->fs, &fd_file(f)->f_path);
|
||||||
out_putf:
|
out_putf:
|
||||||
fdput(f);
|
fdput(f);
|
||||||
out:
|
out:
|
||||||
@ -674,8 +674,8 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int err = -EBADF;
|
int err = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
err = vfs_fchmod(f.file, mode);
|
err = vfs_fchmod(fd_file(f), mode);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
@ -868,8 +868,8 @@ int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int error = -EBADF;
|
int error = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
error = vfs_fchown(f.file, user, group);
|
error = vfs_fchown(fd_file(f), user, group);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
@ -93,11 +93,11 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
|
|||||||
bool allow_meta)
|
bool allow_meta)
|
||||||
{
|
{
|
||||||
struct dentry *dentry = file_dentry(file);
|
struct dentry *dentry = file_dentry(file);
|
||||||
|
struct file *realfile = file->private_data;
|
||||||
struct path realpath;
|
struct path realpath;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
real->flags = 0;
|
real->word = (unsigned long)realfile;
|
||||||
real->file = file->private_data;
|
|
||||||
|
|
||||||
if (allow_meta) {
|
if (allow_meta) {
|
||||||
ovl_path_real(dentry, &realpath);
|
ovl_path_real(dentry, &realpath);
|
||||||
@ -113,16 +113,17 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
/* Has it been copied up since we'd opened it? */
|
/* Has it been copied up since we'd opened it? */
|
||||||
if (unlikely(file_inode(real->file) != d_inode(realpath.dentry))) {
|
if (unlikely(file_inode(realfile) != d_inode(realpath.dentry))) {
|
||||||
real->flags = FDPUT_FPUT;
|
struct file *f = ovl_open_realfile(file, &realpath);
|
||||||
real->file = ovl_open_realfile(file, &realpath);
|
if (IS_ERR(f))
|
||||||
|
return PTR_ERR(f);
|
||||||
return PTR_ERR_OR_ZERO(real->file);
|
real->word = (unsigned long)ovl_open_realfile(file, &realpath) | FDPUT_FPUT;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Did the flags change since open? */
|
/* Did the flags change since open? */
|
||||||
if (unlikely((file->f_flags ^ real->file->f_flags) & ~OVL_OPEN_FLAGS))
|
if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS))
|
||||||
return ovl_change_flags(real->file, file->f_flags);
|
return ovl_change_flags(realfile, file->f_flags);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -130,10 +131,11 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
|
|||||||
static int ovl_real_fdget(const struct file *file, struct fd *real)
|
static int ovl_real_fdget(const struct file *file, struct fd *real)
|
||||||
{
|
{
|
||||||
if (d_is_dir(file_dentry(file))) {
|
if (d_is_dir(file_dentry(file))) {
|
||||||
real->flags = 0;
|
struct file *f = ovl_dir_real_file(file, false);
|
||||||
real->file = ovl_dir_real_file(file, false);
|
if (IS_ERR(f))
|
||||||
|
return PTR_ERR(f);
|
||||||
return PTR_ERR_OR_ZERO(real->file);
|
real->word = (unsigned long)f;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ovl_real_fdget_meta(file, real, false);
|
return ovl_real_fdget_meta(file, real, false);
|
||||||
@ -209,13 +211,13 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
|
|||||||
* files, so we use the real file to perform seeks.
|
* files, so we use the real file to perform seeks.
|
||||||
*/
|
*/
|
||||||
ovl_inode_lock(inode);
|
ovl_inode_lock(inode);
|
||||||
real.file->f_pos = file->f_pos;
|
fd_file(real)->f_pos = file->f_pos;
|
||||||
|
|
||||||
old_cred = ovl_override_creds(inode->i_sb);
|
old_cred = ovl_override_creds(inode->i_sb);
|
||||||
ret = vfs_llseek(real.file, offset, whence);
|
ret = vfs_llseek(fd_file(real), offset, whence);
|
||||||
revert_creds(old_cred);
|
revert_creds(old_cred);
|
||||||
|
|
||||||
file->f_pos = real.file->f_pos;
|
file->f_pos = fd_file(real)->f_pos;
|
||||||
ovl_inode_unlock(inode);
|
ovl_inode_unlock(inode);
|
||||||
|
|
||||||
fdput(real);
|
fdput(real);
|
||||||
@ -275,7 +277,7 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = backing_file_read_iter(real.file, iter, iocb, iocb->ki_flags,
|
ret = backing_file_read_iter(fd_file(real), iter, iocb, iocb->ki_flags,
|
||||||
&ctx);
|
&ctx);
|
||||||
fdput(real);
|
fdput(real);
|
||||||
|
|
||||||
@ -314,7 +316,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
|
|||||||
* this property in case it is set by the issuer.
|
* this property in case it is set by the issuer.
|
||||||
*/
|
*/
|
||||||
ifl &= ~IOCB_DIO_CALLER_COMP;
|
ifl &= ~IOCB_DIO_CALLER_COMP;
|
||||||
ret = backing_file_write_iter(real.file, iter, iocb, ifl, &ctx);
|
ret = backing_file_write_iter(fd_file(real), iter, iocb, ifl, &ctx);
|
||||||
fdput(real);
|
fdput(real);
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
@ -339,7 +341,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos,
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = backing_file_splice_read(real.file, ppos, pipe, len, flags, &ctx);
|
ret = backing_file_splice_read(fd_file(real), ppos, pipe, len, flags, &ctx);
|
||||||
fdput(real);
|
fdput(real);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -348,7 +350,7 @@ static ssize_t ovl_splice_read(struct file *in, loff_t *ppos,
|
|||||||
/*
|
/*
|
||||||
* Calling iter_file_splice_write() directly from overlay's f_op may deadlock
|
* Calling iter_file_splice_write() directly from overlay's f_op may deadlock
|
||||||
* due to lock order inversion between pipe->mutex in iter_file_splice_write()
|
* due to lock order inversion between pipe->mutex in iter_file_splice_write()
|
||||||
* and file_start_write(real.file) in ovl_write_iter().
|
* and file_start_write(fd_file(real)) in ovl_write_iter().
|
||||||
*
|
*
|
||||||
* So do everything ovl_write_iter() does and call iter_file_splice_write() on
|
* So do everything ovl_write_iter() does and call iter_file_splice_write() on
|
||||||
* the real file.
|
* the real file.
|
||||||
@ -373,7 +375,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
ret = backing_file_splice_write(pipe, real.file, ppos, len, flags, &ctx);
|
ret = backing_file_splice_write(pipe, fd_file(real), ppos, len, flags, &ctx);
|
||||||
fdput(real);
|
fdput(real);
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
@ -397,9 +399,9 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Don't sync lower file for fear of receiving EROFS error */
|
/* Don't sync lower file for fear of receiving EROFS error */
|
||||||
if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) {
|
if (file_inode(fd_file(real)) == ovl_inode_upper(file_inode(file))) {
|
||||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||||
ret = vfs_fsync_range(real.file, start, end, datasync);
|
ret = vfs_fsync_range(fd_file(real), start, end, datasync);
|
||||||
revert_creds(old_cred);
|
revert_creds(old_cred);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,7 +441,7 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
|
|||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
|
|
||||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||||
ret = vfs_fallocate(real.file, mode, offset, len);
|
ret = vfs_fallocate(fd_file(real), mode, offset, len);
|
||||||
revert_creds(old_cred);
|
revert_creds(old_cred);
|
||||||
|
|
||||||
/* Update size */
|
/* Update size */
|
||||||
@ -464,7 +466,7 @@ static int ovl_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||||
ret = vfs_fadvise(real.file, offset, len, advice);
|
ret = vfs_fadvise(fd_file(real), offset, len, advice);
|
||||||
revert_creds(old_cred);
|
revert_creds(old_cred);
|
||||||
|
|
||||||
fdput(real);
|
fdput(real);
|
||||||
@ -509,18 +511,18 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
|
|||||||
old_cred = ovl_override_creds(file_inode(file_out)->i_sb);
|
old_cred = ovl_override_creds(file_inode(file_out)->i_sb);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case OVL_COPY:
|
case OVL_COPY:
|
||||||
ret = vfs_copy_file_range(real_in.file, pos_in,
|
ret = vfs_copy_file_range(fd_file(real_in), pos_in,
|
||||||
real_out.file, pos_out, len, flags);
|
fd_file(real_out), pos_out, len, flags);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OVL_CLONE:
|
case OVL_CLONE:
|
||||||
ret = vfs_clone_file_range(real_in.file, pos_in,
|
ret = vfs_clone_file_range(fd_file(real_in), pos_in,
|
||||||
real_out.file, pos_out, len, flags);
|
fd_file(real_out), pos_out, len, flags);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OVL_DEDUPE:
|
case OVL_DEDUPE:
|
||||||
ret = vfs_dedupe_file_range_one(real_in.file, pos_in,
|
ret = vfs_dedupe_file_range_one(fd_file(real_in), pos_in,
|
||||||
real_out.file, pos_out, len,
|
fd_file(real_out), pos_out, len,
|
||||||
flags);
|
flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -583,9 +585,9 @@ static int ovl_flush(struct file *file, fl_owner_t id)
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (real.file->f_op->flush) {
|
if (fd_file(real)->f_op->flush) {
|
||||||
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
old_cred = ovl_override_creds(file_inode(file)->i_sb);
|
||||||
err = real.file->f_op->flush(real.file, id);
|
err = fd_file(real)->f_op->flush(fd_file(real), id);
|
||||||
revert_creds(old_cred);
|
revert_creds(old_cred);
|
||||||
}
|
}
|
||||||
fdput(real);
|
fdput(real);
|
||||||
|
@ -980,7 +980,7 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
f = fdget_raw(fd);
|
f = fdget_raw(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
@ -988,12 +988,12 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (quotactl_cmd_write(cmds)) {
|
if (quotactl_cmd_write(cmds)) {
|
||||||
ret = mnt_want_write(f.file->f_path.mnt);
|
ret = mnt_want_write(fd_file(f)->f_path.mnt);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb = f.file->f_path.mnt->mnt_sb;
|
sb = fd_file(f)->f_path.mnt->mnt_sb;
|
||||||
if (quotactl_cmd_onoff(cmds))
|
if (quotactl_cmd_onoff(cmds))
|
||||||
down_write(&sb->s_umount);
|
down_write(&sb->s_umount);
|
||||||
else
|
else
|
||||||
@ -1007,7 +1007,7 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
|
|||||||
up_read(&sb->s_umount);
|
up_read(&sb->s_umount);
|
||||||
|
|
||||||
if (quotactl_cmd_write(cmds))
|
if (quotactl_cmd_write(cmds))
|
||||||
mnt_drop_write(f.file->f_path.mnt);
|
mnt_drop_write(fd_file(f)->f_path.mnt);
|
||||||
out:
|
out:
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret;
|
return ret;
|
||||||
|
118
fs/read_write.c
118
fs/read_write.c
@ -387,12 +387,12 @@ static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence)
|
|||||||
{
|
{
|
||||||
off_t retval;
|
off_t retval;
|
||||||
struct fd f = fdget_pos(fd);
|
struct fd f = fdget_pos(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
if (whence <= SEEK_MAX) {
|
if (whence <= SEEK_MAX) {
|
||||||
loff_t res = vfs_llseek(f.file, offset, whence);
|
loff_t res = vfs_llseek(fd_file(f), offset, whence);
|
||||||
retval = res;
|
retval = res;
|
||||||
if (res != (loff_t)retval)
|
if (res != (loff_t)retval)
|
||||||
retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
|
retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
|
||||||
@ -423,14 +423,14 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
|
|||||||
struct fd f = fdget_pos(fd);
|
struct fd f = fdget_pos(fd);
|
||||||
loff_t offset;
|
loff_t offset;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
if (whence > SEEK_MAX)
|
if (whence > SEEK_MAX)
|
||||||
goto out_putf;
|
goto out_putf;
|
||||||
|
|
||||||
offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,
|
offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low,
|
||||||
whence);
|
whence);
|
||||||
|
|
||||||
retval = (int)offset;
|
retval = (int)offset;
|
||||||
@ -703,15 +703,15 @@ ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
|
|||||||
struct fd f = fdget_pos(fd);
|
struct fd f = fdget_pos(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(f.file);
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
ppos = &pos;
|
ppos = &pos;
|
||||||
}
|
}
|
||||||
ret = vfs_read(f.file, buf, count, ppos);
|
ret = vfs_read(fd_file(f), buf, count, ppos);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
f.file->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
fdput_pos(f);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -727,15 +727,15 @@ ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
|
|||||||
struct fd f = fdget_pos(fd);
|
struct fd f = fdget_pos(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(f.file);
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
ppos = &pos;
|
ppos = &pos;
|
||||||
}
|
}
|
||||||
ret = vfs_write(f.file, buf, count, ppos);
|
ret = vfs_write(fd_file(f), buf, count, ppos);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
f.file->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
fdput_pos(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,10 +758,10 @@ ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
ret = -ESPIPE;
|
ret = -ESPIPE;
|
||||||
if (f.file->f_mode & FMODE_PREAD)
|
if (fd_file(f)->f_mode & FMODE_PREAD)
|
||||||
ret = vfs_read(f.file, buf, count, &pos);
|
ret = vfs_read(fd_file(f), buf, count, &pos);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,10 +792,10 @@ ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
ret = -ESPIPE;
|
ret = -ESPIPE;
|
||||||
if (f.file->f_mode & FMODE_PWRITE)
|
if (fd_file(f)->f_mode & FMODE_PWRITE)
|
||||||
ret = vfs_write(f.file, buf, count, &pos);
|
ret = vfs_write(fd_file(f), buf, count, &pos);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1078,15 +1078,15 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec,
|
|||||||
struct fd f = fdget_pos(fd);
|
struct fd f = fdget_pos(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(f.file);
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
ppos = &pos;
|
ppos = &pos;
|
||||||
}
|
}
|
||||||
ret = vfs_readv(f.file, vec, vlen, ppos, flags);
|
ret = vfs_readv(fd_file(f), vec, vlen, ppos, flags);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
f.file->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
fdput_pos(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1102,15 +1102,15 @@ static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
|
|||||||
struct fd f = fdget_pos(fd);
|
struct fd f = fdget_pos(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(f.file);
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
ppos = &pos;
|
ppos = &pos;
|
||||||
}
|
}
|
||||||
ret = vfs_writev(f.file, vec, vlen, ppos, flags);
|
ret = vfs_writev(fd_file(f), vec, vlen, ppos, flags);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
f.file->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
fdput_pos(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1136,10 +1136,10 @@ static ssize_t do_preadv(unsigned long fd, const struct iovec __user *vec,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
ret = -ESPIPE;
|
ret = -ESPIPE;
|
||||||
if (f.file->f_mode & FMODE_PREAD)
|
if (fd_file(f)->f_mode & FMODE_PREAD)
|
||||||
ret = vfs_readv(f.file, vec, vlen, &pos, flags);
|
ret = vfs_readv(fd_file(f), vec, vlen, &pos, flags);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,10 +1159,10 @@ static ssize_t do_pwritev(unsigned long fd, const struct iovec __user *vec,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
ret = -ESPIPE;
|
ret = -ESPIPE;
|
||||||
if (f.file->f_mode & FMODE_PWRITE)
|
if (fd_file(f)->f_mode & FMODE_PWRITE)
|
||||||
ret = vfs_writev(f.file, vec, vlen, &pos, flags);
|
ret = vfs_writev(fd_file(f), vec, vlen, &pos, flags);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1328,19 +1328,19 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
|
|||||||
*/
|
*/
|
||||||
retval = -EBADF;
|
retval = -EBADF;
|
||||||
in = fdget(in_fd);
|
in = fdget(in_fd);
|
||||||
if (!in.file)
|
if (!fd_file(in))
|
||||||
goto out;
|
goto out;
|
||||||
if (!(in.file->f_mode & FMODE_READ))
|
if (!(fd_file(in)->f_mode & FMODE_READ))
|
||||||
goto fput_in;
|
goto fput_in;
|
||||||
retval = -ESPIPE;
|
retval = -ESPIPE;
|
||||||
if (!ppos) {
|
if (!ppos) {
|
||||||
pos = in.file->f_pos;
|
pos = fd_file(in)->f_pos;
|
||||||
} else {
|
} else {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
if (!(in.file->f_mode & FMODE_PREAD))
|
if (!(fd_file(in)->f_mode & FMODE_PREAD))
|
||||||
goto fput_in;
|
goto fput_in;
|
||||||
}
|
}
|
||||||
retval = rw_verify_area(READ, in.file, &pos, count);
|
retval = rw_verify_area(READ, fd_file(in), &pos, count);
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
goto fput_in;
|
goto fput_in;
|
||||||
if (count > MAX_RW_COUNT)
|
if (count > MAX_RW_COUNT)
|
||||||
@ -1351,13 +1351,13 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
|
|||||||
*/
|
*/
|
||||||
retval = -EBADF;
|
retval = -EBADF;
|
||||||
out = fdget(out_fd);
|
out = fdget(out_fd);
|
||||||
if (!out.file)
|
if (!fd_file(out))
|
||||||
goto fput_in;
|
goto fput_in;
|
||||||
if (!(out.file->f_mode & FMODE_WRITE))
|
if (!(fd_file(out)->f_mode & FMODE_WRITE))
|
||||||
goto fput_out;
|
goto fput_out;
|
||||||
in_inode = file_inode(in.file);
|
in_inode = file_inode(fd_file(in));
|
||||||
out_inode = file_inode(out.file);
|
out_inode = file_inode(fd_file(out));
|
||||||
out_pos = out.file->f_pos;
|
out_pos = fd_file(out)->f_pos;
|
||||||
|
|
||||||
if (!max)
|
if (!max)
|
||||||
max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
|
max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
|
||||||
@ -1377,33 +1377,33 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
|
|||||||
* and the application is arguably buggy if it doesn't expect
|
* and the application is arguably buggy if it doesn't expect
|
||||||
* EAGAIN on a non-blocking file descriptor.
|
* EAGAIN on a non-blocking file descriptor.
|
||||||
*/
|
*/
|
||||||
if (in.file->f_flags & O_NONBLOCK)
|
if (fd_file(in)->f_flags & O_NONBLOCK)
|
||||||
fl = SPLICE_F_NONBLOCK;
|
fl = SPLICE_F_NONBLOCK;
|
||||||
#endif
|
#endif
|
||||||
opipe = get_pipe_info(out.file, true);
|
opipe = get_pipe_info(fd_file(out), true);
|
||||||
if (!opipe) {
|
if (!opipe) {
|
||||||
retval = rw_verify_area(WRITE, out.file, &out_pos, count);
|
retval = rw_verify_area(WRITE, fd_file(out), &out_pos, count);
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
goto fput_out;
|
goto fput_out;
|
||||||
retval = do_splice_direct(in.file, &pos, out.file, &out_pos,
|
retval = do_splice_direct(fd_file(in), &pos, fd_file(out), &out_pos,
|
||||||
count, fl);
|
count, fl);
|
||||||
} else {
|
} else {
|
||||||
if (out.file->f_flags & O_NONBLOCK)
|
if (fd_file(out)->f_flags & O_NONBLOCK)
|
||||||
fl |= SPLICE_F_NONBLOCK;
|
fl |= SPLICE_F_NONBLOCK;
|
||||||
|
|
||||||
retval = splice_file_to_pipe(in.file, opipe, &pos, count, fl);
|
retval = splice_file_to_pipe(fd_file(in), opipe, &pos, count, fl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval > 0) {
|
if (retval > 0) {
|
||||||
add_rchar(current, retval);
|
add_rchar(current, retval);
|
||||||
add_wchar(current, retval);
|
add_wchar(current, retval);
|
||||||
fsnotify_access(in.file);
|
fsnotify_access(fd_file(in));
|
||||||
fsnotify_modify(out.file);
|
fsnotify_modify(fd_file(out));
|
||||||
out.file->f_pos = out_pos;
|
fd_file(out)->f_pos = out_pos;
|
||||||
if (ppos)
|
if (ppos)
|
||||||
*ppos = pos;
|
*ppos = pos;
|
||||||
else
|
else
|
||||||
in.file->f_pos = pos;
|
fd_file(in)->f_pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
inc_syscr(current);
|
inc_syscr(current);
|
||||||
@ -1676,11 +1676,11 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
|
|||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
f_in = fdget(fd_in);
|
f_in = fdget(fd_in);
|
||||||
if (!f_in.file)
|
if (!fd_file(f_in))
|
||||||
goto out2;
|
goto out2;
|
||||||
|
|
||||||
f_out = fdget(fd_out);
|
f_out = fdget(fd_out);
|
||||||
if (!f_out.file)
|
if (!fd_file(f_out))
|
||||||
goto out1;
|
goto out1;
|
||||||
|
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
@ -1688,21 +1688,21 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
|
|||||||
if (copy_from_user(&pos_in, off_in, sizeof(loff_t)))
|
if (copy_from_user(&pos_in, off_in, sizeof(loff_t)))
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
pos_in = f_in.file->f_pos;
|
pos_in = fd_file(f_in)->f_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (off_out) {
|
if (off_out) {
|
||||||
if (copy_from_user(&pos_out, off_out, sizeof(loff_t)))
|
if (copy_from_user(&pos_out, off_out, sizeof(loff_t)))
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
pos_out = f_out.file->f_pos;
|
pos_out = fd_file(f_out)->f_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (flags != 0)
|
if (flags != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = vfs_copy_file_range(f_in.file, pos_in, f_out.file, pos_out, len,
|
ret = vfs_copy_file_range(fd_file(f_in), pos_in, fd_file(f_out), pos_out, len,
|
||||||
flags);
|
flags);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
pos_in += ret;
|
pos_in += ret;
|
||||||
@ -1712,14 +1712,14 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
|
|||||||
if (copy_to_user(off_in, &pos_in, sizeof(loff_t)))
|
if (copy_to_user(off_in, &pos_in, sizeof(loff_t)))
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
} else {
|
} else {
|
||||||
f_in.file->f_pos = pos_in;
|
fd_file(f_in)->f_pos = pos_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (off_out) {
|
if (off_out) {
|
||||||
if (copy_to_user(off_out, &pos_out, sizeof(loff_t)))
|
if (copy_to_user(off_out, &pos_out, sizeof(loff_t)))
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
} else {
|
} else {
|
||||||
f_out.file->f_pos = pos_out;
|
fd_file(f_out)->f_pos = pos_out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
fs/readdir.c
20
fs/readdir.c
@ -225,10 +225,10 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
|
|||||||
.dirent = dirent
|
.dirent = dirent
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(f.file, &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (buf.result)
|
if (buf.result)
|
||||||
error = buf.result;
|
error = buf.result;
|
||||||
|
|
||||||
@ -318,10 +318,10 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_pos(fd);
|
f = fdget_pos(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(f.file, &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (error >= 0)
|
if (error >= 0)
|
||||||
error = buf.error;
|
error = buf.error;
|
||||||
if (buf.prev_reclen) {
|
if (buf.prev_reclen) {
|
||||||
@ -401,10 +401,10 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_pos(fd);
|
f = fdget_pos(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(f.file, &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (error >= 0)
|
if (error >= 0)
|
||||||
error = buf.error;
|
error = buf.error;
|
||||||
if (buf.prev_reclen) {
|
if (buf.prev_reclen) {
|
||||||
@ -483,10 +483,10 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
|
|||||||
.dirent = dirent
|
.dirent = dirent
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(f.file, &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (buf.result)
|
if (buf.result)
|
||||||
error = buf.result;
|
error = buf.result;
|
||||||
|
|
||||||
@ -569,10 +569,10 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_pos(fd);
|
f = fdget_pos(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(f.file, &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (error >= 0)
|
if (error >= 0)
|
||||||
error = buf.error;
|
error = buf.error;
|
||||||
if (buf.prev_reclen) {
|
if (buf.prev_reclen) {
|
||||||
|
@ -537,7 +537,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
|
|||||||
|
|
||||||
for (i = 0, info = same->info; i < count; i++, info++) {
|
for (i = 0, info = same->info; i < count; i++, info++) {
|
||||||
struct fd dst_fd = fdget(info->dest_fd);
|
struct fd dst_fd = fdget(info->dest_fd);
|
||||||
struct file *dst_file = dst_fd.file;
|
struct file *dst_file = fd_file(dst_fd);
|
||||||
|
|
||||||
if (!dst_file) {
|
if (!dst_file) {
|
||||||
info->status = -EBADF;
|
info->status = -EBADF;
|
||||||
|
@ -529,10 +529,10 @@ static noinline_for_stack int do_select(int n, fd_set_bits *fds, struct timespec
|
|||||||
continue;
|
continue;
|
||||||
mask = EPOLLNVAL;
|
mask = EPOLLNVAL;
|
||||||
f = fdget(i);
|
f = fdget(i);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
wait_key_set(wait, in, out, bit,
|
wait_key_set(wait, in, out, bit,
|
||||||
busy_flag);
|
busy_flag);
|
||||||
mask = vfs_poll(f.file, wait);
|
mask = vfs_poll(fd_file(f), wait);
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
@ -863,13 +863,13 @@ static inline __poll_t do_pollfd(struct pollfd *pollfd, poll_table *pwait,
|
|||||||
goto out;
|
goto out;
|
||||||
mask = EPOLLNVAL;
|
mask = EPOLLNVAL;
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* userland u16 ->events contains POLL... bitmap */
|
/* userland u16 ->events contains POLL... bitmap */
|
||||||
filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP;
|
filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP;
|
||||||
pwait->_key = filter | busy_flag;
|
pwait->_key = filter | busy_flag;
|
||||||
mask = vfs_poll(f.file, pwait);
|
mask = vfs_poll(fd_file(f), pwait);
|
||||||
if (mask & busy_flag)
|
if (mask & busy_flag)
|
||||||
*can_busy_poll = true;
|
*can_busy_poll = true;
|
||||||
mask &= filter; /* Mask out unneeded events. */
|
mask &= filter; /* Mask out unneeded events. */
|
||||||
|
@ -289,10 +289,10 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)
|
|||||||
fd_install(ufd, file);
|
fd_install(ufd, file);
|
||||||
} else {
|
} else {
|
||||||
struct fd f = fdget(ufd);
|
struct fd f = fdget(ufd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
ctx = f.file->private_data;
|
ctx = fd_file(f)->private_data;
|
||||||
if (f.file->f_op != &signalfd_fops) {
|
if (fd_file(f)->f_op != &signalfd_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -90,23 +90,23 @@ static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
src_file = fdget(srcfd);
|
src_file = fdget(srcfd);
|
||||||
if (!src_file.file) {
|
if (!fd_file(src_file)) {
|
||||||
rc = -EBADF;
|
rc = -EBADF;
|
||||||
goto out_drop_write;
|
goto out_drop_write;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) {
|
if (fd_file(src_file)->f_op->unlocked_ioctl != cifs_ioctl) {
|
||||||
rc = -EBADF;
|
rc = -EBADF;
|
||||||
cifs_dbg(VFS, "src file seems to be from a different filesystem type\n");
|
cifs_dbg(VFS, "src file seems to be from a different filesystem type\n");
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
|
|
||||||
src_inode = file_inode(src_file.file);
|
src_inode = file_inode(fd_file(src_file));
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
if (S_ISDIR(src_inode->i_mode))
|
if (S_ISDIR(src_inode->i_mode))
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
|
|
||||||
rc = cifs_file_copychunk_range(xid, src_file.file, 0, dst_file, 0,
|
rc = cifs_file_copychunk_range(xid, fd_file(src_file), 0, dst_file, 0,
|
||||||
src_inode->i_size, 0);
|
src_inode->i_size, 0);
|
||||||
if (rc > 0)
|
if (rc > 0)
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
22
fs/splice.c
22
fs/splice.c
@ -1566,11 +1566,11 @@ static ssize_t vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
|
|||||||
|
|
||||||
static int vmsplice_type(struct fd f, int *type)
|
static int vmsplice_type(struct fd f, int *type)
|
||||||
{
|
{
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (f.file->f_mode & FMODE_WRITE) {
|
if (fd_file(f)->f_mode & FMODE_WRITE) {
|
||||||
*type = ITER_SOURCE;
|
*type = ITER_SOURCE;
|
||||||
} else if (f.file->f_mode & FMODE_READ) {
|
} else if (fd_file(f)->f_mode & FMODE_READ) {
|
||||||
*type = ITER_DEST;
|
*type = ITER_DEST;
|
||||||
} else {
|
} else {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -1621,9 +1621,9 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov,
|
|||||||
if (!iov_iter_count(&iter))
|
if (!iov_iter_count(&iter))
|
||||||
error = 0;
|
error = 0;
|
||||||
else if (type == ITER_SOURCE)
|
else if (type == ITER_SOURCE)
|
||||||
error = vmsplice_to_pipe(f.file, &iter, flags);
|
error = vmsplice_to_pipe(fd_file(f), &iter, flags);
|
||||||
else
|
else
|
||||||
error = vmsplice_to_user(f.file, &iter, flags);
|
error = vmsplice_to_user(fd_file(f), &iter, flags);
|
||||||
|
|
||||||
kfree(iov);
|
kfree(iov);
|
||||||
out_fdput:
|
out_fdput:
|
||||||
@ -1646,10 +1646,10 @@ SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in,
|
|||||||
|
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
in = fdget(fd_in);
|
in = fdget(fd_in);
|
||||||
if (in.file) {
|
if (fd_file(in)) {
|
||||||
out = fdget(fd_out);
|
out = fdget(fd_out);
|
||||||
if (out.file) {
|
if (fd_file(out)) {
|
||||||
error = __do_splice(in.file, off_in, out.file, off_out,
|
error = __do_splice(fd_file(in), off_in, fd_file(out), off_out,
|
||||||
len, flags);
|
len, flags);
|
||||||
fdput(out);
|
fdput(out);
|
||||||
}
|
}
|
||||||
@ -2016,10 +2016,10 @@ SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags)
|
|||||||
|
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
in = fdget(fdin);
|
in = fdget(fdin);
|
||||||
if (in.file) {
|
if (fd_file(in)) {
|
||||||
out = fdget(fdout);
|
out = fdget(fdout);
|
||||||
if (out.file) {
|
if (fd_file(out)) {
|
||||||
error = do_tee(in.file, out.file, len, flags);
|
error = do_tee(fd_file(in), fd_file(out), len, flags);
|
||||||
fdput(out);
|
fdput(out);
|
||||||
}
|
}
|
||||||
fdput(in);
|
fdput(in);
|
||||||
|
@ -224,9 +224,9 @@ int vfs_fstat(int fd, struct kstat *stat)
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_raw(fd);
|
f = fdget_raw(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
error = vfs_getattr(&f.file->f_path, stat, STATX_BASIC_STATS, 0);
|
error = vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -277,9 +277,9 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat,
|
|||||||
u32 request_mask)
|
u32 request_mask)
|
||||||
{
|
{
|
||||||
CLASS(fd_raw, f)(fd);
|
CLASS(fd_raw, f)(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return vfs_statx_path(&f.file->f_path, flags, stat, request_mask);
|
return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,8 +116,8 @@ int fd_statfs(int fd, struct kstatfs *st)
|
|||||||
{
|
{
|
||||||
struct fd f = fdget_raw(fd);
|
struct fd f = fdget_raw(fd);
|
||||||
int error = -EBADF;
|
int error = -EBADF;
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
error = vfs_statfs(&f.file->f_path, st);
|
error = vfs_statfs(&fd_file(f)->f_path, st);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
14
fs/sync.c
14
fs/sync.c
@ -152,15 +152,15 @@ SYSCALL_DEFINE1(syncfs, int, fd)
|
|||||||
struct super_block *sb;
|
struct super_block *sb;
|
||||||
int ret, ret2;
|
int ret, ret2;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
sb = f.file->f_path.dentry->d_sb;
|
sb = fd_file(f)->f_path.dentry->d_sb;
|
||||||
|
|
||||||
down_read(&sb->s_umount);
|
down_read(&sb->s_umount);
|
||||||
ret = sync_filesystem(sb);
|
ret = sync_filesystem(sb);
|
||||||
up_read(&sb->s_umount);
|
up_read(&sb->s_umount);
|
||||||
|
|
||||||
ret2 = errseq_check_and_advance(&sb->s_wb_err, &f.file->f_sb_err);
|
ret2 = errseq_check_and_advance(&sb->s_wb_err, &fd_file(f)->f_sb_err);
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret ? ret : ret2;
|
return ret ? ret : ret2;
|
||||||
@ -208,8 +208,8 @@ static int do_fsync(unsigned int fd, int datasync)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int ret = -EBADF;
|
int ret = -EBADF;
|
||||||
|
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
ret = vfs_fsync(f.file, datasync);
|
ret = vfs_fsync(fd_file(f), datasync);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -360,8 +360,8 @@ int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
|
|||||||
|
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file)
|
if (fd_file(f))
|
||||||
ret = sync_file_range(f.file, offset, nbytes, flags);
|
ret = sync_file_range(fd_file(f), offset, nbytes, flags);
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -397,9 +397,9 @@ static const struct file_operations timerfd_fops = {
|
|||||||
static int timerfd_fget(int fd, struct fd *p)
|
static int timerfd_fget(int fd, struct fd *p)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (f.file->f_op != &timerfd_fops) {
|
if (fd_file(f)->f_op != &timerfd_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -482,7 +482,7 @@ static int do_timerfd_settime(int ufd, int flags,
|
|||||||
ret = timerfd_fget(ufd, &f);
|
ret = timerfd_fget(ufd, &f);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
ctx = f.file->private_data;
|
ctx = fd_file(f)->private_data;
|
||||||
|
|
||||||
if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {
|
if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -546,7 +546,7 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t)
|
|||||||
int ret = timerfd_fget(ufd, &f);
|
int ret = timerfd_fget(ufd, &f);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
ctx = f.file->private_data;
|
ctx = fd_file(f)->private_data;
|
||||||
|
|
||||||
spin_lock_irq(&ctx->wqh.lock);
|
spin_lock_irq(&ctx->wqh.lock);
|
||||||
if (ctx->expired && ctx->tintv) {
|
if (ctx->expired && ctx->tintv) {
|
||||||
|
@ -115,9 +115,9 @@ static int do_utimes_fd(int fd, struct timespec64 *times, int flags)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
error = vfs_utimes(&f.file->f_path, times);
|
error = vfs_utimes(&fd_file(f)->f_path, times);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
36
fs/xattr.c
36
fs/xattr.c
@ -697,19 +697,19 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
CLASS(fd, f)(fd);
|
CLASS(fd, f)(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
audit_file(f.file);
|
audit_file(fd_file(f));
|
||||||
error = setxattr_copy(name, &ctx);
|
error = setxattr_copy(name, &ctx);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
error = mnt_want_write_file(f.file);
|
error = mnt_want_write_file(fd_file(f));
|
||||||
if (!error) {
|
if (!error) {
|
||||||
error = do_setxattr(file_mnt_idmap(f.file),
|
error = do_setxattr(file_mnt_idmap(fd_file(f)),
|
||||||
f.file->f_path.dentry, &ctx);
|
fd_file(f)->f_path.dentry, &ctx);
|
||||||
mnt_drop_write_file(f.file);
|
mnt_drop_write_file(fd_file(f));
|
||||||
}
|
}
|
||||||
kvfree(ctx.kvalue);
|
kvfree(ctx.kvalue);
|
||||||
return error;
|
return error;
|
||||||
@ -812,10 +812,10 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
ssize_t error = -EBADF;
|
ssize_t error = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return error;
|
return error;
|
||||||
audit_file(f.file);
|
audit_file(fd_file(f));
|
||||||
error = getxattr(file_mnt_idmap(f.file), f.file->f_path.dentry,
|
error = getxattr(file_mnt_idmap(fd_file(f)), fd_file(f)->f_path.dentry,
|
||||||
name, value, size);
|
name, value, size);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return error;
|
return error;
|
||||||
@ -888,10 +888,10 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
ssize_t error = -EBADF;
|
ssize_t error = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return error;
|
return error;
|
||||||
audit_file(f.file);
|
audit_file(fd_file(f));
|
||||||
error = listxattr(f.file->f_path.dentry, list, size);
|
error = listxattr(fd_file(f)->f_path.dentry, list, size);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -954,9 +954,9 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
|
|||||||
char kname[XATTR_NAME_MAX + 1];
|
char kname[XATTR_NAME_MAX + 1];
|
||||||
int error = -EBADF;
|
int error = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return error;
|
return error;
|
||||||
audit_file(f.file);
|
audit_file(fd_file(f));
|
||||||
|
|
||||||
error = strncpy_from_user(kname, name, sizeof(kname));
|
error = strncpy_from_user(kname, name, sizeof(kname));
|
||||||
if (error == 0 || error == sizeof(kname))
|
if (error == 0 || error == sizeof(kname))
|
||||||
@ -964,11 +964,11 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
|
|||||||
if (error < 0)
|
if (error < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
error = mnt_want_write_file(f.file);
|
error = mnt_want_write_file(fd_file(f));
|
||||||
if (!error) {
|
if (!error) {
|
||||||
error = removexattr(file_mnt_idmap(f.file),
|
error = removexattr(file_mnt_idmap(fd_file(f)),
|
||||||
f.file->f_path.dentry, kname);
|
fd_file(f)->f_path.dentry, kname);
|
||||||
mnt_drop_write_file(f.file);
|
mnt_drop_write_file(fd_file(f));
|
||||||
}
|
}
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return error;
|
return error;
|
||||||
|
@ -829,9 +829,9 @@ xfs_ioc_exchange_range(
|
|||||||
fxr.flags = args.flags;
|
fxr.flags = args.flags;
|
||||||
|
|
||||||
file1 = fdget(args.file1_fd);
|
file1 = fdget(args.file1_fd);
|
||||||
if (!file1.file)
|
if (!fd_file(file1))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
fxr.file1 = file1.file;
|
fxr.file1 = fd_file(file1);
|
||||||
|
|
||||||
error = xfs_exchange_range(&fxr);
|
error = xfs_exchange_range(&fxr);
|
||||||
fdput(file1);
|
fdput(file1);
|
||||||
@ -935,9 +935,9 @@ xfs_ioc_commit_range(
|
|||||||
fxr.file2_ctime.tv_nsec = kern_f->file2_ctime_nsec;
|
fxr.file2_ctime.tv_nsec = kern_f->file2_ctime_nsec;
|
||||||
|
|
||||||
file1 = fdget(args.file1_fd);
|
file1 = fdget(args.file1_fd);
|
||||||
if (!file1.file)
|
if (fd_empty(file1))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
fxr.file1 = file1.file;
|
fxr.file1 = fd_file(file1);
|
||||||
|
|
||||||
error = xfs_exchange_range(&fxr);
|
error = xfs_exchange_range(&fxr);
|
||||||
fdput(file1);
|
fdput(file1);
|
||||||
|
@ -85,16 +85,16 @@ xfs_find_handle(
|
|||||||
int hsize;
|
int hsize;
|
||||||
xfs_handle_t handle;
|
xfs_handle_t handle;
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct fd f = {NULL};
|
struct fd f = EMPTY_FD;
|
||||||
struct path path;
|
struct path path;
|
||||||
int error;
|
int error;
|
||||||
struct xfs_inode *ip;
|
struct xfs_inode *ip;
|
||||||
|
|
||||||
if (cmd == XFS_IOC_FD_TO_HANDLE) {
|
if (cmd == XFS_IOC_FD_TO_HANDLE) {
|
||||||
f = fdget(hreq->fd);
|
f = fdget(hreq->fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
inode = file_inode(f.file);
|
inode = file_inode(fd_file(f));
|
||||||
} else {
|
} else {
|
||||||
error = user_path_at(AT_FDCWD, hreq->path, 0, &path);
|
error = user_path_at(AT_FDCWD, hreq->path, 0, &path);
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -886,33 +886,33 @@ xfs_ioc_swapext(
|
|||||||
|
|
||||||
/* Pull information for the target fd */
|
/* Pull information for the target fd */
|
||||||
f = fdget((int)sxp->sx_fdtarget);
|
f = fdget((int)sxp->sx_fdtarget);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(f.file->f_mode & FMODE_WRITE) ||
|
if (!(fd_file(f)->f_mode & FMODE_WRITE) ||
|
||||||
!(f.file->f_mode & FMODE_READ) ||
|
!(fd_file(f)->f_mode & FMODE_READ) ||
|
||||||
(f.file->f_flags & O_APPEND)) {
|
(fd_file(f)->f_flags & O_APPEND)) {
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
goto out_put_file;
|
goto out_put_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = fdget((int)sxp->sx_fdtmp);
|
tmp = fdget((int)sxp->sx_fdtmp);
|
||||||
if (!tmp.file) {
|
if (!fd_file(tmp)) {
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
goto out_put_file;
|
goto out_put_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tmp.file->f_mode & FMODE_WRITE) ||
|
if (!(fd_file(tmp)->f_mode & FMODE_WRITE) ||
|
||||||
!(tmp.file->f_mode & FMODE_READ) ||
|
!(fd_file(tmp)->f_mode & FMODE_READ) ||
|
||||||
(tmp.file->f_flags & O_APPEND)) {
|
(fd_file(tmp)->f_flags & O_APPEND)) {
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
goto out_put_tmp_file;
|
goto out_put_tmp_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_SWAPFILE(file_inode(f.file)) ||
|
if (IS_SWAPFILE(file_inode(fd_file(f))) ||
|
||||||
IS_SWAPFILE(file_inode(tmp.file))) {
|
IS_SWAPFILE(file_inode(fd_file(tmp)))) {
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
goto out_put_tmp_file;
|
goto out_put_tmp_file;
|
||||||
}
|
}
|
||||||
@ -922,14 +922,14 @@ xfs_ioc_swapext(
|
|||||||
* before we cast and access them as XFS structures as we have no
|
* before we cast and access them as XFS structures as we have no
|
||||||
* control over what the user passes us here.
|
* control over what the user passes us here.
|
||||||
*/
|
*/
|
||||||
if (f.file->f_op != &xfs_file_operations ||
|
if (fd_file(f)->f_op != &xfs_file_operations ||
|
||||||
tmp.file->f_op != &xfs_file_operations) {
|
fd_file(tmp)->f_op != &xfs_file_operations) {
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
goto out_put_tmp_file;
|
goto out_put_tmp_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = XFS_I(file_inode(f.file));
|
ip = XFS_I(file_inode(fd_file(f)));
|
||||||
tip = XFS_I(file_inode(tmp.file));
|
tip = XFS_I(file_inode(fd_file(tmp)));
|
||||||
|
|
||||||
if (ip->i_mount != tip->i_mount) {
|
if (ip->i_mount != tip->i_mount) {
|
||||||
error = -EINVAL;
|
error = -EINVAL;
|
||||||
|
@ -98,7 +98,7 @@ const volatile void * __must_check_fn(const volatile void *val)
|
|||||||
* DEFINE_CLASS(fdget, struct fd, fdput(_T), fdget(fd), int fd)
|
* DEFINE_CLASS(fdget, struct fd, fdput(_T), fdget(fd), int fd)
|
||||||
*
|
*
|
||||||
* CLASS(fdget, f)(fd);
|
* CLASS(fdget, f)(fd);
|
||||||
* if (!f.file)
|
* if (!fd_file(f))
|
||||||
* return -EBADF;
|
* return -EBADF;
|
||||||
*
|
*
|
||||||
* // use 'f' without concern
|
* // use 'f' without concern
|
||||||
|
@ -36,51 +36,52 @@ static inline void fput_light(struct file *file, int fput_needed)
|
|||||||
fput(file);
|
fput(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* either a reference to struct file + flags
|
||||||
|
* (cloned vs. borrowed, pos locked), with
|
||||||
|
* flags stored in lower bits of value,
|
||||||
|
* or empty (represented by 0).
|
||||||
|
*/
|
||||||
struct fd {
|
struct fd {
|
||||||
struct file *file;
|
unsigned long word;
|
||||||
unsigned int flags;
|
|
||||||
};
|
};
|
||||||
#define FDPUT_FPUT 1
|
#define FDPUT_FPUT 1
|
||||||
#define FDPUT_POS_UNLOCK 2
|
#define FDPUT_POS_UNLOCK 2
|
||||||
|
|
||||||
|
#define fd_file(f) ((struct file *)((f).word & ~(FDPUT_FPUT|FDPUT_POS_UNLOCK)))
|
||||||
|
static inline bool fd_empty(struct fd f)
|
||||||
|
{
|
||||||
|
return unlikely(!f.word);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define EMPTY_FD (struct fd){0}
|
||||||
|
static inline struct fd BORROWED_FD(struct file *f)
|
||||||
|
{
|
||||||
|
return (struct fd){(unsigned long)f};
|
||||||
|
}
|
||||||
|
static inline struct fd CLONED_FD(struct file *f)
|
||||||
|
{
|
||||||
|
return (struct fd){(unsigned long)f | FDPUT_FPUT};
|
||||||
|
}
|
||||||
|
|
||||||
static inline void fdput(struct fd fd)
|
static inline void fdput(struct fd fd)
|
||||||
{
|
{
|
||||||
if (fd.flags & FDPUT_FPUT)
|
if (fd.word & FDPUT_FPUT)
|
||||||
fput(fd.file);
|
fput(fd_file(fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern struct file *fget(unsigned int fd);
|
extern struct file *fget(unsigned int fd);
|
||||||
extern struct file *fget_raw(unsigned int fd);
|
extern struct file *fget_raw(unsigned int fd);
|
||||||
extern struct file *fget_task(struct task_struct *task, unsigned int fd);
|
extern struct file *fget_task(struct task_struct *task, unsigned int fd);
|
||||||
extern unsigned long __fdget(unsigned int fd);
|
|
||||||
extern unsigned long __fdget_raw(unsigned int fd);
|
|
||||||
extern unsigned long __fdget_pos(unsigned int fd);
|
|
||||||
extern void __f_unlock_pos(struct file *);
|
extern void __f_unlock_pos(struct file *);
|
||||||
|
|
||||||
static inline struct fd __to_fd(unsigned long v)
|
struct fd fdget(unsigned int fd);
|
||||||
{
|
struct fd fdget_raw(unsigned int fd);
|
||||||
return (struct fd){(struct file *)(v & ~3),v & 3};
|
struct fd fdget_pos(unsigned int fd);
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct fd fdget(unsigned int fd)
|
|
||||||
{
|
|
||||||
return __to_fd(__fdget(fd));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct fd fdget_raw(unsigned int fd)
|
|
||||||
{
|
|
||||||
return __to_fd(__fdget_raw(fd));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct fd fdget_pos(int fd)
|
|
||||||
{
|
|
||||||
return __to_fd(__fdget_pos(fd));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void fdput_pos(struct fd f)
|
static inline void fdput_pos(struct fd f)
|
||||||
{
|
{
|
||||||
if (f.flags & FDPUT_POS_UNLOCK)
|
if (f.word & FDPUT_POS_UNLOCK)
|
||||||
__f_unlock_pos(f.file);
|
__f_unlock_pos(fd_file(f));
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +109,14 @@ static struct io_sq_data *io_attach_sq_data(struct io_uring_params *p)
|
|||||||
struct fd f;
|
struct fd f;
|
||||||
|
|
||||||
f = fdget(p->wq_fd);
|
f = fdget(p->wq_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-ENXIO);
|
return ERR_PTR(-ENXIO);
|
||||||
if (!io_is_uring_fops(f.file)) {
|
if (!io_is_uring_fops(fd_file(f))) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx_attach = f.file->private_data;
|
ctx_attach = fd_file(f)->private_data;
|
||||||
sqd = ctx_attach->sq_data;
|
sqd = ctx_attach->sq_data;
|
||||||
if (!sqd) {
|
if (!sqd) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -419,9 +419,9 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
|
|||||||
struct fd f;
|
struct fd f;
|
||||||
|
|
||||||
f = fdget(p->wq_fd);
|
f = fdget(p->wq_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
if (!io_is_uring_fops(f.file)) {
|
if (!io_is_uring_fops(fd_file(f))) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
50
ipc/mqueue.c
50
ipc/mqueue.c
@ -1085,20 +1085,20 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
|
|||||||
audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts);
|
audit_mq_sendrecv(mqdes, msg_len, msg_prio, ts);
|
||||||
|
|
||||||
f = fdget(mqdes);
|
f = fdget(mqdes);
|
||||||
if (unlikely(!f.file)) {
|
if (unlikely(!fd_file(f))) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = file_inode(f.file);
|
inode = file_inode(fd_file(f));
|
||||||
if (unlikely(f.file->f_op != &mqueue_file_operations)) {
|
if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
info = MQUEUE_I(inode);
|
info = MQUEUE_I(inode);
|
||||||
audit_file(f.file);
|
audit_file(fd_file(f));
|
||||||
|
|
||||||
if (unlikely(!(f.file->f_mode & FMODE_WRITE))) {
|
if (unlikely(!(fd_file(f)->f_mode & FMODE_WRITE))) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
@ -1138,7 +1138,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
|
if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
|
||||||
if (f.file->f_flags & O_NONBLOCK) {
|
if (fd_file(f)->f_flags & O_NONBLOCK) {
|
||||||
ret = -EAGAIN;
|
ret = -EAGAIN;
|
||||||
} else {
|
} else {
|
||||||
wait.task = current;
|
wait.task = current;
|
||||||
@ -1199,20 +1199,20 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
|
|||||||
audit_mq_sendrecv(mqdes, msg_len, 0, ts);
|
audit_mq_sendrecv(mqdes, msg_len, 0, ts);
|
||||||
|
|
||||||
f = fdget(mqdes);
|
f = fdget(mqdes);
|
||||||
if (unlikely(!f.file)) {
|
if (unlikely(!fd_file(f))) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = file_inode(f.file);
|
inode = file_inode(fd_file(f));
|
||||||
if (unlikely(f.file->f_op != &mqueue_file_operations)) {
|
if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
info = MQUEUE_I(inode);
|
info = MQUEUE_I(inode);
|
||||||
audit_file(f.file);
|
audit_file(fd_file(f));
|
||||||
|
|
||||||
if (unlikely(!(f.file->f_mode & FMODE_READ))) {
|
if (unlikely(!(fd_file(f)->f_mode & FMODE_READ))) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
@ -1242,7 +1242,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (info->attr.mq_curmsgs == 0) {
|
if (info->attr.mq_curmsgs == 0) {
|
||||||
if (f.file->f_flags & O_NONBLOCK) {
|
if (fd_file(f)->f_flags & O_NONBLOCK) {
|
||||||
spin_unlock(&info->lock);
|
spin_unlock(&info->lock);
|
||||||
ret = -EAGAIN;
|
ret = -EAGAIN;
|
||||||
} else {
|
} else {
|
||||||
@ -1356,11 +1356,11 @@ static int do_mq_notify(mqd_t mqdes, const struct sigevent *notification)
|
|||||||
/* and attach it to the socket */
|
/* and attach it to the socket */
|
||||||
retry:
|
retry:
|
||||||
f = fdget(notification->sigev_signo);
|
f = fdget(notification->sigev_signo);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
sock = netlink_getsockbyfilp(f.file);
|
sock = netlink_getsockbyfilp(fd_file(f));
|
||||||
fdput(f);
|
fdput(f);
|
||||||
if (IS_ERR(sock)) {
|
if (IS_ERR(sock)) {
|
||||||
ret = PTR_ERR(sock);
|
ret = PTR_ERR(sock);
|
||||||
@ -1379,13 +1379,13 @@ retry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
f = fdget(mqdes);
|
f = fdget(mqdes);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = file_inode(f.file);
|
inode = file_inode(fd_file(f));
|
||||||
if (unlikely(f.file->f_op != &mqueue_file_operations)) {
|
if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_fput;
|
goto out_fput;
|
||||||
}
|
}
|
||||||
@ -1460,31 +1460,31 @@ static int do_mq_getsetattr(int mqdes, struct mq_attr *new, struct mq_attr *old)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(mqdes);
|
f = fdget(mqdes);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (unlikely(f.file->f_op != &mqueue_file_operations)) {
|
if (unlikely(fd_file(f)->f_op != &mqueue_file_operations)) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = file_inode(f.file);
|
inode = file_inode(fd_file(f));
|
||||||
info = MQUEUE_I(inode);
|
info = MQUEUE_I(inode);
|
||||||
|
|
||||||
spin_lock(&info->lock);
|
spin_lock(&info->lock);
|
||||||
|
|
||||||
if (old) {
|
if (old) {
|
||||||
*old = info->attr;
|
*old = info->attr;
|
||||||
old->mq_flags = f.file->f_flags & O_NONBLOCK;
|
old->mq_flags = fd_file(f)->f_flags & O_NONBLOCK;
|
||||||
}
|
}
|
||||||
if (new) {
|
if (new) {
|
||||||
audit_mq_getsetattr(mqdes, new);
|
audit_mq_getsetattr(mqdes, new);
|
||||||
spin_lock(&f.file->f_lock);
|
spin_lock(&fd_file(f)->f_lock);
|
||||||
if (new->mq_flags & O_NONBLOCK)
|
if (new->mq_flags & O_NONBLOCK)
|
||||||
f.file->f_flags |= O_NONBLOCK;
|
fd_file(f)->f_flags |= O_NONBLOCK;
|
||||||
else
|
else
|
||||||
f.file->f_flags &= ~O_NONBLOCK;
|
fd_file(f)->f_flags &= ~O_NONBLOCK;
|
||||||
spin_unlock(&f.file->f_lock);
|
spin_unlock(&fd_file(f)->f_lock);
|
||||||
|
|
||||||
inode_set_atime_to_ts(inode, inode_set_ctime_current(inode));
|
inode_set_atime_to_ts(inode, inode_set_ctime_current(inode));
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,10 @@ static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)
|
|||||||
struct bpf_local_storage_data *sdata;
|
struct bpf_local_storage_data *sdata;
|
||||||
struct fd f = fdget_raw(*(int *)key);
|
struct fd f = fdget_raw(*(int *)key);
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
sdata = inode_storage_lookup(file_inode(f.file), map, true);
|
sdata = inode_storage_lookup(file_inode(fd_file(f)), map, true);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return sdata ? sdata->data : NULL;
|
return sdata ? sdata->data : NULL;
|
||||||
}
|
}
|
||||||
@ -94,14 +94,14 @@ static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key,
|
|||||||
struct bpf_local_storage_data *sdata;
|
struct bpf_local_storage_data *sdata;
|
||||||
struct fd f = fdget_raw(*(int *)key);
|
struct fd f = fdget_raw(*(int *)key);
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!inode_storage_ptr(file_inode(f.file))) {
|
if (!inode_storage_ptr(file_inode(fd_file(f)))) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdata = bpf_local_storage_update(file_inode(f.file),
|
sdata = bpf_local_storage_update(file_inode(fd_file(f)),
|
||||||
(struct bpf_local_storage_map *)map,
|
(struct bpf_local_storage_map *)map,
|
||||||
value, map_flags, GFP_ATOMIC);
|
value, map_flags, GFP_ATOMIC);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -126,10 +126,10 @@ static long bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key)
|
|||||||
struct fd f = fdget_raw(*(int *)key);
|
struct fd f = fdget_raw(*(int *)key);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
err = inode_storage_delete(file_inode(f.file), map);
|
err = inode_storage_delete(file_inode(fd_file(f)), map);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -7715,15 +7715,15 @@ struct btf *btf_get_by_fd(int fd)
|
|||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (f.file->f_op != &btf_fops) {
|
if (fd_file(f)->f_op != &btf_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
btf = f.file->private_data;
|
btf = fd_file(f)->private_data;
|
||||||
refcount_inc(&btf->refcnt);
|
refcount_inc(&btf->refcnt);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
|
@ -837,7 +837,7 @@ static int bpf_map_release(struct inode *inode, struct file *filp)
|
|||||||
|
|
||||||
static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)
|
static fmode_t map_get_sys_perms(struct bpf_map *map, struct fd f)
|
||||||
{
|
{
|
||||||
fmode_t mode = f.file->f_mode;
|
fmode_t mode = fd_file(f)->f_mode;
|
||||||
|
|
||||||
/* Our file permissions may have been overridden by global
|
/* Our file permissions may have been overridden by global
|
||||||
* map permissions facing syscall side.
|
* map permissions facing syscall side.
|
||||||
@ -1430,14 +1430,14 @@ put_token:
|
|||||||
*/
|
*/
|
||||||
struct bpf_map *__bpf_map_get(struct fd f)
|
struct bpf_map *__bpf_map_get(struct fd f)
|
||||||
{
|
{
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
if (f.file->f_op != &bpf_map_fops) {
|
if (fd_file(f)->f_op != &bpf_map_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.file->private_data;
|
return fd_file(f)->private_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bpf_map_inc(struct bpf_map *map)
|
void bpf_map_inc(struct bpf_map *map)
|
||||||
@ -1658,7 +1658,7 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)
|
|||||||
goto free_key;
|
goto free_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bpf_map_update_value(map, f.file, key, value, attr->flags);
|
err = bpf_map_update_value(map, fd_file(f), key, value, attr->flags);
|
||||||
if (!err)
|
if (!err)
|
||||||
maybe_wait_bpf_programs(map);
|
maybe_wait_bpf_programs(map);
|
||||||
|
|
||||||
@ -2416,14 +2416,14 @@ int bpf_prog_new_fd(struct bpf_prog *prog)
|
|||||||
|
|
||||||
static struct bpf_prog *____bpf_prog_get(struct fd f)
|
static struct bpf_prog *____bpf_prog_get(struct fd f)
|
||||||
{
|
{
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
if (f.file->f_op != &bpf_prog_fops) {
|
if (fd_file(f)->f_op != &bpf_prog_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.file->private_data;
|
return fd_file(f)->private_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bpf_prog_add(struct bpf_prog *prog, int i)
|
void bpf_prog_add(struct bpf_prog *prog, int i)
|
||||||
@ -3266,14 +3266,14 @@ struct bpf_link *bpf_link_get_from_fd(u32 ufd)
|
|||||||
struct fd f = fdget(ufd);
|
struct fd f = fdget(ufd);
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
if (f.file->f_op != &bpf_link_fops && f.file->f_op != &bpf_link_fops_poll) {
|
if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
link = f.file->private_data;
|
link = fd_file(f)->private_data;
|
||||||
bpf_link_inc(link);
|
bpf_link_inc(link);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
@ -4989,19 +4989,19 @@ static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(ufd);
|
f = fdget(ufd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADFD;
|
return -EBADFD;
|
||||||
|
|
||||||
if (f.file->f_op == &bpf_prog_fops)
|
if (fd_file(f)->f_op == &bpf_prog_fops)
|
||||||
err = bpf_prog_get_info_by_fd(f.file, f.file->private_data, attr,
|
err = bpf_prog_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
|
||||||
uattr);
|
uattr);
|
||||||
else if (f.file->f_op == &bpf_map_fops)
|
else if (fd_file(f)->f_op == &bpf_map_fops)
|
||||||
err = bpf_map_get_info_by_fd(f.file, f.file->private_data, attr,
|
err = bpf_map_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
|
||||||
uattr);
|
uattr);
|
||||||
else if (f.file->f_op == &btf_fops)
|
else if (fd_file(f)->f_op == &btf_fops)
|
||||||
err = bpf_btf_get_info_by_fd(f.file, f.file->private_data, attr, uattr);
|
err = bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, uattr);
|
||||||
else if (f.file->f_op == &bpf_link_fops || f.file->f_op == &bpf_link_fops_poll)
|
else if (fd_file(f)->f_op == &bpf_link_fops || fd_file(f)->f_op == &bpf_link_fops_poll)
|
||||||
err = bpf_link_get_info_by_fd(f.file, f.file->private_data,
|
err = bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
|
||||||
attr, uattr);
|
attr, uattr);
|
||||||
else
|
else
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
@ -5222,7 +5222,7 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
|
|||||||
else if (cmd == BPF_MAP_LOOKUP_AND_DELETE_BATCH)
|
else if (cmd == BPF_MAP_LOOKUP_AND_DELETE_BATCH)
|
||||||
BPF_DO_BATCH(map->ops->map_lookup_and_delete_batch, map, attr, uattr);
|
BPF_DO_BATCH(map->ops->map_lookup_and_delete_batch, map, attr, uattr);
|
||||||
else if (cmd == BPF_MAP_UPDATE_BATCH)
|
else if (cmd == BPF_MAP_UPDATE_BATCH)
|
||||||
BPF_DO_BATCH(map->ops->map_update_batch, map, f.file, attr, uattr);
|
BPF_DO_BATCH(map->ops->map_update_batch, map, fd_file(f), attr, uattr);
|
||||||
else
|
else
|
||||||
BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
|
BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
|
||||||
err_put:
|
err_put:
|
||||||
|
@ -122,10 +122,10 @@ int bpf_token_create(union bpf_attr *attr)
|
|||||||
int err, fd;
|
int err, fd;
|
||||||
|
|
||||||
f = fdget(attr->token_create.bpffs_fd);
|
f = fdget(attr->token_create.bpffs_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
path = f.file->f_path;
|
path = fd_file(f)->f_path;
|
||||||
path_get(&path);
|
path_get(&path);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
@ -235,14 +235,14 @@ struct bpf_token *bpf_token_get_from_fd(u32 ufd)
|
|||||||
struct fd f = fdget(ufd);
|
struct fd f = fdget(ufd);
|
||||||
struct bpf_token *token;
|
struct bpf_token *token;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
if (f.file->f_op != &bpf_token_fops) {
|
if (fd_file(f)->f_op != &bpf_token_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
token = f.file->private_data;
|
token = fd_file(f)->private_data;
|
||||||
bpf_token_inc(token);
|
bpf_token_inc(token);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
|
@ -6968,10 +6968,10 @@ struct cgroup *cgroup_v1v2_get_from_fd(int fd)
|
|||||||
{
|
{
|
||||||
struct cgroup *cgrp;
|
struct cgroup *cgrp;
|
||||||
struct fd f = fdget_raw(fd);
|
struct fd f = fdget_raw(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
cgrp = cgroup_v1v2_get_from_file(f.file);
|
cgrp = cgroup_v1v2_get_from_file(fd_file(f));
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return cgrp;
|
return cgrp;
|
||||||
}
|
}
|
||||||
|
@ -969,10 +969,10 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
css = css_tryget_online_from_dir(f.file->f_path.dentry,
|
css = css_tryget_online_from_dir(fd_file(f)->f_path.dentry,
|
||||||
&perf_event_cgrp_subsys);
|
&perf_event_cgrp_subsys);
|
||||||
if (IS_ERR(css)) {
|
if (IS_ERR(css)) {
|
||||||
ret = PTR_ERR(css);
|
ret = PTR_ERR(css);
|
||||||
@ -6001,10 +6001,10 @@ static const struct file_operations perf_fops;
|
|||||||
static inline int perf_fget_light(int fd, struct fd *p)
|
static inline int perf_fget_light(int fd, struct fd *p)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (f.file->f_op != &perf_fops) {
|
if (fd_file(f)->f_op != &perf_fops) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
@ -6064,7 +6064,7 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon
|
|||||||
ret = perf_fget_light(arg, &output);
|
ret = perf_fget_light(arg, &output);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
output_event = output.file->private_data;
|
output_event = fd_file(output)->private_data;
|
||||||
ret = perf_event_set_output(event, output_event);
|
ret = perf_event_set_output(event, output_event);
|
||||||
fdput(output);
|
fdput(output);
|
||||||
} else {
|
} else {
|
||||||
@ -12665,7 +12665,7 @@ SYSCALL_DEFINE5(perf_event_open,
|
|||||||
struct perf_event_attr attr;
|
struct perf_event_attr attr;
|
||||||
struct perf_event_context *ctx;
|
struct perf_event_context *ctx;
|
||||||
struct file *event_file = NULL;
|
struct file *event_file = NULL;
|
||||||
struct fd group = {NULL, 0};
|
struct fd group = EMPTY_FD;
|
||||||
struct task_struct *task = NULL;
|
struct task_struct *task = NULL;
|
||||||
struct pmu *pmu;
|
struct pmu *pmu;
|
||||||
int event_fd;
|
int event_fd;
|
||||||
@ -12740,7 +12740,7 @@ SYSCALL_DEFINE5(perf_event_open,
|
|||||||
err = perf_fget_light(group_fd, &group);
|
err = perf_fget_light(group_fd, &group);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_fd;
|
goto err_fd;
|
||||||
group_leader = group.file->private_data;
|
group_leader = fd_file(group)->private_data;
|
||||||
if (flags & PERF_FLAG_FD_OUTPUT)
|
if (flags & PERF_FLAG_FD_OUTPUT)
|
||||||
output_event = group_leader;
|
output_event = group_leader;
|
||||||
if (flags & PERF_FLAG_FD_NO_GROUP)
|
if (flags & PERF_FLAG_FD_NO_GROUP)
|
||||||
|
@ -3234,7 +3234,7 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
err = idempotent_init_module(f.file, uargs, flags);
|
err = idempotent_init_module(fd_file(f), uargs, flags);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -550,15 +550,15 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags)
|
|||||||
struct nsset nsset = {};
|
struct nsset nsset = {};
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (proc_ns_file(f.file)) {
|
if (proc_ns_file(fd_file(f))) {
|
||||||
ns = get_proc_ns(file_inode(f.file));
|
ns = get_proc_ns(file_inode(fd_file(f)));
|
||||||
if (flags && (ns->ops->type != flags))
|
if (flags && (ns->ops->type != flags))
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
flags = ns->ops->type;
|
flags = ns->ops->type;
|
||||||
} else if (!IS_ERR(pidfd_pid(f.file))) {
|
} else if (!IS_ERR(pidfd_pid(fd_file(f)))) {
|
||||||
err = check_setns_flags(flags);
|
err = check_setns_flags(flags);
|
||||||
} else {
|
} else {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
@ -570,10 +570,10 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags)
|
|||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (proc_ns_file(f.file))
|
if (proc_ns_file(fd_file(f)))
|
||||||
err = validate_ns(&nsset, ns);
|
err = validate_ns(&nsset, ns);
|
||||||
else
|
else
|
||||||
err = validate_nsset(&nsset, pidfd_pid(f.file));
|
err = validate_nsset(&nsset, pidfd_pid(fd_file(f)));
|
||||||
if (!err) {
|
if (!err) {
|
||||||
commit_nsset(&nsset);
|
commit_nsset(&nsset);
|
||||||
perf_event_namespaces(current);
|
perf_event_namespaces(current);
|
||||||
|
10
kernel/pid.c
10
kernel/pid.c
@ -540,13 +540,13 @@ struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
|
|||||||
struct pid *pid;
|
struct pid *pid;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
pid = pidfd_pid(f.file);
|
pid = pidfd_pid(fd_file(f));
|
||||||
if (!IS_ERR(pid)) {
|
if (!IS_ERR(pid)) {
|
||||||
get_pid(pid);
|
get_pid(pid);
|
||||||
*flags = f.file->f_flags;
|
*flags = fd_file(f)->f_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
@ -755,10 +755,10 @@ SYSCALL_DEFINE3(pidfd_getfd, int, pidfd, int, fd,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(pidfd);
|
f = fdget(pidfd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
pid = pidfd_pid(f.file);
|
pid = pidfd_pid(fd_file(f));
|
||||||
if (IS_ERR(pid))
|
if (IS_ERR(pid))
|
||||||
ret = PTR_ERR(pid);
|
ret = PTR_ERR(pid);
|
||||||
else
|
else
|
||||||
|
@ -3941,11 +3941,11 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
f = fdget(pidfd);
|
f = fdget(pidfd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
/* Is this a pidfd? */
|
/* Is this a pidfd? */
|
||||||
pid = pidfd_to_pid(f.file);
|
pid = pidfd_to_pid(fd_file(f));
|
||||||
if (IS_ERR(pid)) {
|
if (IS_ERR(pid)) {
|
||||||
ret = PTR_ERR(pid);
|
ret = PTR_ERR(pid);
|
||||||
goto err;
|
goto err;
|
||||||
@ -3958,7 +3958,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
|
|||||||
switch (flags) {
|
switch (flags) {
|
||||||
case 0:
|
case 0:
|
||||||
/* Infer scope from the type of pidfd. */
|
/* Infer scope from the type of pidfd. */
|
||||||
if (f.file->f_flags & PIDFD_THREAD)
|
if (fd_file(f)->f_flags & PIDFD_THREAD)
|
||||||
type = PIDTYPE_PID;
|
type = PIDTYPE_PID;
|
||||||
else
|
else
|
||||||
type = PIDTYPE_TGID;
|
type = PIDTYPE_TGID;
|
||||||
|
10
kernel/sys.c
10
kernel/sys.c
@ -1916,10 +1916,10 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
exe = fdget(fd);
|
exe = fdget(fd);
|
||||||
if (!exe.file)
|
if (!fd_file(exe))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
inode = file_inode(exe.file);
|
inode = file_inode(fd_file(exe));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Because the original mm->exe_file points to executable file, make
|
* Because the original mm->exe_file points to executable file, make
|
||||||
@ -1927,14 +1927,14 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
|
|||||||
* overall picture.
|
* overall picture.
|
||||||
*/
|
*/
|
||||||
err = -EACCES;
|
err = -EACCES;
|
||||||
if (!S_ISREG(inode->i_mode) || path_noexec(&exe.file->f_path))
|
if (!S_ISREG(inode->i_mode) || path_noexec(&fd_file(exe)->f_path))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
err = file_permission(exe.file, MAY_EXEC);
|
err = file_permission(fd_file(exe), MAY_EXEC);
|
||||||
if (err)
|
if (err)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
err = replace_mm_exe_file(mm, exe.file);
|
err = replace_mm_exe_file(mm, fd_file(exe));
|
||||||
exit:
|
exit:
|
||||||
fdput(exe);
|
fdput(exe);
|
||||||
return err;
|
return err;
|
||||||
|
@ -419,7 +419,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
|
|||||||
|
|
||||||
fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
|
fd = nla_get_u32(info->attrs[CGROUPSTATS_CMD_ATTR_FD]);
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size = nla_total_size(sizeof(struct cgroupstats));
|
size = nla_total_size(sizeof(struct cgroupstats));
|
||||||
@ -440,7 +440,7 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
|
|||||||
stats = nla_data(na);
|
stats = nla_data(na);
|
||||||
memset(stats, 0, sizeof(*stats));
|
memset(stats, 0, sizeof(*stats));
|
||||||
|
|
||||||
rc = cgroupstats_build(stats, f.file->f_path.dentry);
|
rc = cgroupstats_build(stats, fd_file(f)->f_path.dentry);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
nlmsg_free(rep_skb);
|
nlmsg_free(rep_skb);
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -666,8 +666,8 @@ struct watch_queue *get_watch_queue(int fd)
|
|||||||
struct fd f;
|
struct fd f;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
pipe = get_pipe_info(f.file, false);
|
pipe = get_pipe_info(fd_file(f), false);
|
||||||
if (pipe && pipe->watch_queue) {
|
if (pipe && pipe->watch_queue) {
|
||||||
wqueue = pipe->watch_queue;
|
wqueue = pipe->watch_queue;
|
||||||
kref_get(&wqueue->usage);
|
kref_get(&wqueue->usage);
|
||||||
|
@ -193,10 +193,10 @@ int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = vfs_fadvise(f.file, offset, len, advice);
|
ret = vfs_fadvise(fd_file(f), offset, len, advice);
|
||||||
|
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -4423,7 +4423,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
|
|||||||
struct cachestat cs;
|
struct cachestat cs;
|
||||||
pgoff_t first_index, last_index;
|
pgoff_t first_index, last_index;
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (copy_from_user(&csr, cstat_range,
|
if (copy_from_user(&csr, cstat_range,
|
||||||
@ -4433,7 +4433,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* hugetlbfs is not supported */
|
/* hugetlbfs is not supported */
|
||||||
if (is_file_hugepages(f.file)) {
|
if (is_file_hugepages(fd_file(f))) {
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
@ -4447,7 +4447,7 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
|
|||||||
last_index =
|
last_index =
|
||||||
csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
|
csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
|
||||||
memset(&cs, 0, sizeof(struct cachestat));
|
memset(&cs, 0, sizeof(struct cachestat));
|
||||||
mapping = f.file->f_mapping;
|
mapping = fd_file(f)->f_mapping;
|
||||||
filemap_cachestat(mapping, first_index, last_index, &cs);
|
filemap_cachestat(mapping, first_index, last_index, &cs);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
|
||||||
|
@ -1947,26 +1947,26 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
INIT_WORK(&event->remove, memcg_event_remove);
|
INIT_WORK(&event->remove, memcg_event_remove);
|
||||||
|
|
||||||
efile = fdget(efd);
|
efile = fdget(efd);
|
||||||
if (!efile.file) {
|
if (!fd_file(efile)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_kfree;
|
goto out_kfree;
|
||||||
}
|
}
|
||||||
|
|
||||||
event->eventfd = eventfd_ctx_fileget(efile.file);
|
event->eventfd = eventfd_ctx_fileget(fd_file(efile));
|
||||||
if (IS_ERR(event->eventfd)) {
|
if (IS_ERR(event->eventfd)) {
|
||||||
ret = PTR_ERR(event->eventfd);
|
ret = PTR_ERR(event->eventfd);
|
||||||
goto out_put_efile;
|
goto out_put_efile;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfile = fdget(cfd);
|
cfile = fdget(cfd);
|
||||||
if (!cfile.file) {
|
if (!fd_file(cfile)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_put_eventfd;
|
goto out_put_eventfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the process need read permission on control file */
|
/* the process need read permission on control file */
|
||||||
/* AV: shouldn't we check that it's been opened for read instead? */
|
/* AV: shouldn't we check that it's been opened for read instead? */
|
||||||
ret = file_permission(cfile.file, MAY_READ);
|
ret = file_permission(fd_file(cfile), MAY_READ);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_put_cfile;
|
goto out_put_cfile;
|
||||||
|
|
||||||
@ -1974,7 +1974,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
* The control file must be a regular cgroup1 file. As a regular cgroup
|
* The control file must be a regular cgroup1 file. As a regular cgroup
|
||||||
* file can't be renamed, it's safe to access its name afterwards.
|
* file can't be renamed, it's safe to access its name afterwards.
|
||||||
*/
|
*/
|
||||||
cdentry = cfile.file->f_path.dentry;
|
cdentry = fd_file(cfile)->f_path.dentry;
|
||||||
if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {
|
if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out_put_cfile;
|
goto out_put_cfile;
|
||||||
@ -2032,7 +2032,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out_put_css;
|
goto out_put_css;
|
||||||
|
|
||||||
vfs_poll(efile.file, &event->pt);
|
vfs_poll(fd_file(efile), &event->pt);
|
||||||
|
|
||||||
spin_lock_irq(&memcg->event_list_lock);
|
spin_lock_irq(&memcg->event_list_lock);
|
||||||
list_add(&event->list, &memcg->event_list);
|
list_add(&event->list, &memcg->event_list);
|
||||||
|
@ -678,7 +678,7 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count)
|
|||||||
|
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file || !(f.file->f_mode & FMODE_READ))
|
if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -687,12 +687,12 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count)
|
|||||||
* on this file, then we must return -EINVAL.
|
* on this file, then we must return -EINVAL.
|
||||||
*/
|
*/
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (!f.file->f_mapping || !f.file->f_mapping->a_ops ||
|
if (!fd_file(f)->f_mapping || !fd_file(f)->f_mapping->a_ops ||
|
||||||
(!S_ISREG(file_inode(f.file)->i_mode) &&
|
(!S_ISREG(file_inode(fd_file(f))->i_mode) &&
|
||||||
!S_ISBLK(file_inode(f.file)->i_mode)))
|
!S_ISBLK(file_inode(fd_file(f))->i_mode)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = vfs_fadvise(f.file, offset, count, POSIX_FADV_WILLNEED);
|
ret = vfs_fadvise(fd_file(f), offset, count, POSIX_FADV_WILLNEED);
|
||||||
out:
|
out:
|
||||||
fdput(f);
|
fdput(f);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -697,11 +697,11 @@ struct net *get_net_ns_by_fd(int fd)
|
|||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
struct net *net = ERR_PTR(-EINVAL);
|
struct net *net = ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (proc_ns_file(f.file)) {
|
if (proc_ns_file(fd_file(f))) {
|
||||||
struct ns_common *ns = get_proc_ns(file_inode(f.file));
|
struct ns_common *ns = get_proc_ns(file_inode(fd_file(f)));
|
||||||
if (ns->ops == &netns_operations)
|
if (ns->ops == &netns_operations)
|
||||||
net = get_net(container_of(ns, struct net, ns));
|
net = get_net(container_of(ns, struct net, ns));
|
||||||
}
|
}
|
||||||
|
14
net/socket.c
14
net/socket.c
@ -556,10 +556,10 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
|
|||||||
struct socket *sock;
|
struct socket *sock;
|
||||||
|
|
||||||
*err = -EBADF;
|
*err = -EBADF;
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
sock = sock_from_file(f.file);
|
sock = sock_from_file(fd_file(f));
|
||||||
if (likely(sock)) {
|
if (likely(sock)) {
|
||||||
*fput_needed = f.flags & FDPUT_FPUT;
|
*fput_needed = f.word & FDPUT_FPUT;
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
*err = -ENOTSOCK;
|
*err = -ENOTSOCK;
|
||||||
@ -2014,8 +2014,8 @@ int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
|
|||||||
struct fd f;
|
struct fd f;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
ret = __sys_accept4_file(f.file, upeer_sockaddr,
|
ret = __sys_accept4_file(fd_file(f), upeer_sockaddr,
|
||||||
upeer_addrlen, flags);
|
upeer_addrlen, flags);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
@ -2076,12 +2076,12 @@ int __sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen)
|
|||||||
struct fd f;
|
struct fd f;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (f.file) {
|
if (fd_file(f)) {
|
||||||
struct sockaddr_storage address;
|
struct sockaddr_storage address;
|
||||||
|
|
||||||
ret = move_addr_to_kernel(uservaddr, addrlen, &address);
|
ret = move_addr_to_kernel(uservaddr, addrlen, &address);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = __sys_connect_file(f.file, &address, addrlen, 0);
|
ret = __sys_connect_file(fd_file(f), &address, addrlen, 0);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1068,10 +1068,10 @@ void ima_kexec_cmdline(int kernel_fd, const void *buf, int size)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
f = fdget(kernel_fd);
|
f = fdget(kernel_fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
process_buffer_measurement(file_mnt_idmap(f.file), file_inode(f.file),
|
process_buffer_measurement(file_mnt_idmap(fd_file(f)), file_inode(fd_file(f)),
|
||||||
buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
|
buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
|
||||||
NULL, false, NULL, 0);
|
NULL, false, NULL, 0);
|
||||||
fdput(f);
|
fdput(f);
|
||||||
|
@ -238,19 +238,19 @@ static struct landlock_ruleset *get_ruleset_from_fd(const int fd,
|
|||||||
struct landlock_ruleset *ruleset;
|
struct landlock_ruleset *ruleset;
|
||||||
|
|
||||||
ruleset_f = fdget(fd);
|
ruleset_f = fdget(fd);
|
||||||
if (!ruleset_f.file)
|
if (!fd_file(ruleset_f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
/* Checks FD type and access right. */
|
/* Checks FD type and access right. */
|
||||||
if (ruleset_f.file->f_op != &ruleset_fops) {
|
if (fd_file(ruleset_f)->f_op != &ruleset_fops) {
|
||||||
ruleset = ERR_PTR(-EBADFD);
|
ruleset = ERR_PTR(-EBADFD);
|
||||||
goto out_fdput;
|
goto out_fdput;
|
||||||
}
|
}
|
||||||
if (!(ruleset_f.file->f_mode & mode)) {
|
if (!(fd_file(ruleset_f)->f_mode & mode)) {
|
||||||
ruleset = ERR_PTR(-EPERM);
|
ruleset = ERR_PTR(-EPERM);
|
||||||
goto out_fdput;
|
goto out_fdput;
|
||||||
}
|
}
|
||||||
ruleset = ruleset_f.file->private_data;
|
ruleset = fd_file(ruleset_f)->private_data;
|
||||||
if (WARN_ON_ONCE(ruleset->num_layers != 1)) {
|
if (WARN_ON_ONCE(ruleset->num_layers != 1)) {
|
||||||
ruleset = ERR_PTR(-EINVAL);
|
ruleset = ERR_PTR(-EINVAL);
|
||||||
goto out_fdput;
|
goto out_fdput;
|
||||||
@ -277,22 +277,22 @@ static int get_path_from_fd(const s32 fd, struct path *const path)
|
|||||||
|
|
||||||
/* Handles O_PATH. */
|
/* Handles O_PATH. */
|
||||||
f = fdget_raw(fd);
|
f = fdget_raw(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
/*
|
/*
|
||||||
* Forbids ruleset FDs, internal filesystems (e.g. nsfs), including
|
* Forbids ruleset FDs, internal filesystems (e.g. nsfs), including
|
||||||
* pseudo filesystems that will never be mountable (e.g. sockfs,
|
* pseudo filesystems that will never be mountable (e.g. sockfs,
|
||||||
* pipefs).
|
* pipefs).
|
||||||
*/
|
*/
|
||||||
if ((f.file->f_op == &ruleset_fops) ||
|
if ((fd_file(f)->f_op == &ruleset_fops) ||
|
||||||
(f.file->f_path.mnt->mnt_flags & MNT_INTERNAL) ||
|
(fd_file(f)->f_path.mnt->mnt_flags & MNT_INTERNAL) ||
|
||||||
(f.file->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||
|
(fd_file(f)->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||
|
||||||
d_is_negative(f.file->f_path.dentry) ||
|
d_is_negative(fd_file(f)->f_path.dentry) ||
|
||||||
IS_PRIVATE(d_backing_inode(f.file->f_path.dentry))) {
|
IS_PRIVATE(d_backing_inode(fd_file(f)->f_path.dentry))) {
|
||||||
err = -EBADFD;
|
err = -EBADFD;
|
||||||
goto out_fdput;
|
goto out_fdput;
|
||||||
}
|
}
|
||||||
*path = f.file->f_path;
|
*path = fd_file(f)->f_path;
|
||||||
path_get(path);
|
path_get(path);
|
||||||
|
|
||||||
out_fdput:
|
out_fdput:
|
||||||
|
@ -296,7 +296,7 @@ static int read_trusted_verity_root_digests(unsigned int fd)
|
|||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
data = kzalloc(SZ_4K, GFP_KERNEL);
|
data = kzalloc(SZ_4K, GFP_KERNEL);
|
||||||
@ -305,7 +305,7 @@ static int read_trusted_verity_root_digests(unsigned int fd)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = kernel_read_file(f.file, 0, (void **)&data, SZ_4K - 1, NULL, READING_POLICY);
|
rc = kernel_read_file(fd_file(f), 0, (void **)&data, SZ_4K - 1, NULL, READING_POLICY);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -2250,12 +2250,12 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
|
|||||||
bool nonatomic = substream->pcm->nonatomic;
|
bool nonatomic = substream->pcm->nonatomic;
|
||||||
CLASS(fd, f)(fd);
|
CLASS(fd, f)(fd);
|
||||||
|
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADFD;
|
return -EBADFD;
|
||||||
if (!is_pcm_file(f.file))
|
if (!is_pcm_file(fd_file(f)))
|
||||||
return -EBADFD;
|
return -EBADFD;
|
||||||
|
|
||||||
pcm_file = f.file->private_data;
|
pcm_file = fd_file(f)->private_data;
|
||||||
substream1 = pcm_file->substream;
|
substream1 = pcm_file->substream;
|
||||||
|
|
||||||
if (substream == substream1)
|
if (substream == substream1)
|
||||||
|
@ -328,12 +328,12 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
|
|||||||
seqcount_spinlock_init(&irqfd->irq_entry_sc, &kvm->irqfds.lock);
|
seqcount_spinlock_init(&irqfd->irq_entry_sc, &kvm->irqfds.lock);
|
||||||
|
|
||||||
f = fdget(args->fd);
|
f = fdget(args->fd);
|
||||||
if (!f.file) {
|
if (!fd_file(f)) {
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
eventfd = eventfd_ctx_fileget(f.file);
|
eventfd = eventfd_ctx_fileget(fd_file(f));
|
||||||
if (IS_ERR(eventfd)) {
|
if (IS_ERR(eventfd)) {
|
||||||
ret = PTR_ERR(eventfd);
|
ret = PTR_ERR(eventfd);
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -420,7 +420,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
|
|||||||
* Check if there was an event already pending on the eventfd
|
* Check if there was an event already pending on the eventfd
|
||||||
* before we registered, and trigger it as if we didn't miss it.
|
* before we registered, and trigger it as if we didn't miss it.
|
||||||
*/
|
*/
|
||||||
events = vfs_poll(f.file, &irqfd->pt);
|
events = vfs_poll(fd_file(f), &irqfd->pt);
|
||||||
|
|
||||||
if (events & EPOLLIN)
|
if (events & EPOLLIN)
|
||||||
schedule_work(&irqfd->inject);
|
schedule_work(&irqfd->inject);
|
||||||
|
@ -194,7 +194,7 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
f = fdget(fd);
|
f = fdget(fd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
@ -202,7 +202,7 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
|
|||||||
mutex_lock(&kv->lock);
|
mutex_lock(&kv->lock);
|
||||||
|
|
||||||
list_for_each_entry(kvf, &kv->file_list, node) {
|
list_for_each_entry(kvf, &kv->file_list, node) {
|
||||||
if (kvf->file != f.file)
|
if (kvf->file != fd_file(f))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
list_del(&kvf->node);
|
list_del(&kvf->node);
|
||||||
@ -240,7 +240,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
|
|||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
f = fdget(param.groupfd);
|
f = fdget(param.groupfd);
|
||||||
if (!f.file)
|
if (!fd_file(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
@ -248,7 +248,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
|
|||||||
mutex_lock(&kv->lock);
|
mutex_lock(&kv->lock);
|
||||||
|
|
||||||
list_for_each_entry(kvf, &kv->file_list, node) {
|
list_for_each_entry(kvf, &kv->file_list, node) {
|
||||||
if (kvf->file != f.file)
|
if (kvf->file != fd_file(f))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!kvf->iommu_group) {
|
if (!kvf->iommu_group) {
|
||||||
|
Loading…
Reference in New Issue
Block a user