mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 20:51:44 +00:00
fdget(), trivial conversions
fdget() is the first thing done in scope, all matching fdput() are immediately followed by leaving the scope. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
46b5e18ae8
commit
6348be02ee
@ -115,10 +115,9 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
struct iommu_table_group *table_group;
|
struct iommu_table_group *table_group;
|
||||||
long i;
|
long i;
|
||||||
struct kvmppc_spapr_tce_iommu_table *stit;
|
struct kvmppc_spapr_tce_iommu_table *stit;
|
||||||
struct fd f;
|
CLASS(fd, f)(tablefd);
|
||||||
|
|
||||||
f = fdget(tablefd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
@ -130,16 +129,12 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
}
|
}
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
|
||||||
if (!found) {
|
if (!found)
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
table_group = iommu_group_get_iommudata(grp);
|
table_group = iommu_group_get_iommudata(grp);
|
||||||
if (WARN_ON(!table_group)) {
|
if (WARN_ON(!table_group))
|
||||||
fdput(f);
|
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
|
for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
|
||||||
struct iommu_table *tbltmp = table_group->tables[i];
|
struct iommu_table *tbltmp = table_group->tables[i];
|
||||||
@ -160,10 +155,8 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tbl) {
|
if (!tbl)
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
list_for_each_entry_rcu(stit, &stt->iommu_tables, next) {
|
list_for_each_entry_rcu(stit, &stt->iommu_tables, next) {
|
||||||
@ -174,7 +167,6 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
/* stit is being destroyed */
|
/* stit is being destroyed */
|
||||||
iommu_tce_table_put(tbl);
|
iommu_tce_table_put(tbl);
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
fdput(f);
|
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -182,7 +174,6 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
* its KVM reference counter and can return.
|
* its KVM reference counter and can return.
|
||||||
*/
|
*/
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
fdput(f);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
@ -190,7 +181,6 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
stit = kzalloc(sizeof(*stit), GFP_KERNEL);
|
stit = kzalloc(sizeof(*stit), GFP_KERNEL);
|
||||||
if (!stit) {
|
if (!stit) {
|
||||||
iommu_tce_table_put(tbl);
|
iommu_tce_table_put(tbl);
|
||||||
fdput(f);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +189,6 @@ long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
|
|||||||
|
|
||||||
list_add_rcu(&stit->next, &stt->iommu_tables);
|
list_add_rcu(&stit->next, &stt->iommu_tables);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1933,12 +1933,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_KVM_MPIC
|
#ifdef CONFIG_KVM_MPIC
|
||||||
case KVM_CAP_IRQ_MPIC: {
|
case KVM_CAP_IRQ_MPIC: {
|
||||||
struct fd f;
|
CLASS(fd, f)(cap->args[0]);
|
||||||
struct kvm_device *dev;
|
struct kvm_device *dev;
|
||||||
|
|
||||||
r = -EBADF;
|
r = -EBADF;
|
||||||
f = fdget(cap->args[0]);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
@ -1946,18 +1945,16 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
if (dev)
|
if (dev)
|
||||||
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
|
r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_KVM_XICS
|
#ifdef CONFIG_KVM_XICS
|
||||||
case KVM_CAP_IRQ_XICS: {
|
case KVM_CAP_IRQ_XICS: {
|
||||||
struct fd f;
|
CLASS(fd, f)(cap->args[0]);
|
||||||
struct kvm_device *dev;
|
struct kvm_device *dev;
|
||||||
|
|
||||||
r = -EBADF;
|
r = -EBADF;
|
||||||
f = fdget(cap->args[0]);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
@ -1968,34 +1965,27 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
|
|||||||
else
|
else
|
||||||
r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]);
|
r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_KVM_XICS */
|
#endif /* CONFIG_KVM_XICS */
|
||||||
#ifdef CONFIG_KVM_XIVE
|
#ifdef CONFIG_KVM_XIVE
|
||||||
case KVM_CAP_PPC_IRQ_XIVE: {
|
case KVM_CAP_PPC_IRQ_XIVE: {
|
||||||
struct fd f;
|
CLASS(fd, f)(cap->args[0]);
|
||||||
struct kvm_device *dev;
|
struct kvm_device *dev;
|
||||||
|
|
||||||
r = -EBADF;
|
r = -EBADF;
|
||||||
f = fdget(cap->args[0]);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
r = -ENXIO;
|
r = -ENXIO;
|
||||||
if (!xive_enabled()) {
|
if (!xive_enabled())
|
||||||
fdput(f);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
dev = kvm_device_from_filp(fd_file(f));
|
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]);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_KVM_XIVE */
|
#endif /* CONFIG_KVM_XIVE */
|
||||||
|
@ -64,12 +64,10 @@ SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
|
|||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
if (flags & SPU_CREATE_AFFINITY_SPU) {
|
||||||
struct fd neighbor = fdget(neighbor_fd);
|
CLASS(fd, neighbor)(neighbor_fd);
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
if (fd_file(neighbor)) {
|
if (!fd_empty(neighbor))
|
||||||
ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
|
ret = calls->create_thread(name, flags, mode, fd_file(neighbor));
|
||||||
fdput(neighbor);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
ret = calls->create_thread(name, flags, mode, NULL);
|
ret = calls->create_thread(name, flags, mode, NULL);
|
||||||
|
|
||||||
|
@ -901,19 +901,15 @@ static struct miscdevice sgx_dev_provision = {
|
|||||||
int sgx_set_attribute(unsigned long *allowed_attributes,
|
int sgx_set_attribute(unsigned long *allowed_attributes,
|
||||||
unsigned int attribute_fd)
|
unsigned int attribute_fd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(attribute_fd);
|
CLASS(fd, f)(attribute_fd);
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (fd_file(f)->f_op != &sgx_provision_fops) {
|
if (fd_file(f)->f_op != &sgx_provision_fops)
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
*allowed_attributes |= SGX_ATTR_PROVISIONKEY;
|
*allowed_attributes |= SGX_ATTR_PROVISIONKEY;
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(sgx_set_attribute);
|
EXPORT_SYMBOL_GPL(sgx_set_attribute);
|
||||||
|
@ -530,17 +530,12 @@ static int sev_bind_asid(struct kvm *kvm, unsigned int handle, int *error)
|
|||||||
|
|
||||||
static int __sev_issue_cmd(int fd, int id, void *data, int *error)
|
static int __sev_issue_cmd(int fd, int id, void *data, int *error)
|
||||||
{
|
{
|
||||||
struct fd f;
|
CLASS(fd, f)(fd);
|
||||||
int ret;
|
|
||||||
|
|
||||||
f = fdget(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = sev_issue_cmd_external_user(fd_file(f), id, data, error);
|
return sev_issue_cmd_external_user(fd_file(f), id, data, error);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sev_issue_cmd(struct kvm *kvm, int id, void *data, int *error)
|
static int sev_issue_cmd(struct kvm *kvm, int id, void *data, int *error)
|
||||||
@ -2073,23 +2068,21 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
|||||||
{
|
{
|
||||||
struct kvm_sev_info *dst_sev = &to_kvm_svm(kvm)->sev_info;
|
struct kvm_sev_info *dst_sev = &to_kvm_svm(kvm)->sev_info;
|
||||||
struct kvm_sev_info *src_sev, *cg_cleanup_sev;
|
struct kvm_sev_info *src_sev, *cg_cleanup_sev;
|
||||||
struct fd f = fdget(source_fd);
|
CLASS(fd, f)(source_fd);
|
||||||
struct kvm *source_kvm;
|
struct kvm *source_kvm;
|
||||||
bool charged = false;
|
bool charged = false;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!file_is_kvm(fd_file(f))) {
|
if (!file_is_kvm(fd_file(f)))
|
||||||
ret = -EBADF;
|
return -EBADF;
|
||||||
goto out_fput;
|
|
||||||
}
|
|
||||||
|
|
||||||
source_kvm = fd_file(f)->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;
|
return ret;
|
||||||
|
|
||||||
if (kvm->arch.vm_type != source_kvm->arch.vm_type ||
|
if (kvm->arch.vm_type != source_kvm->arch.vm_type ||
|
||||||
sev_guest(kvm) || !sev_guest(source_kvm)) {
|
sev_guest(kvm) || !sev_guest(source_kvm)) {
|
||||||
@ -2136,8 +2129,6 @@ out_dst_cgroup:
|
|||||||
cg_cleanup_sev->misc_cg = NULL;
|
cg_cleanup_sev->misc_cg = NULL;
|
||||||
out_unlock:
|
out_unlock:
|
||||||
sev_unlock_two_vms(kvm, source_kvm);
|
sev_unlock_two_vms(kvm, source_kvm);
|
||||||
out_fput:
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2798,23 +2789,21 @@ failed:
|
|||||||
|
|
||||||
int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(source_fd);
|
CLASS(fd, f)(source_fd);
|
||||||
struct kvm *source_kvm;
|
struct kvm *source_kvm;
|
||||||
struct kvm_sev_info *source_sev, *mirror_sev;
|
struct kvm_sev_info *source_sev, *mirror_sev;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!file_is_kvm(fd_file(f))) {
|
if (!file_is_kvm(fd_file(f)))
|
||||||
ret = -EBADF;
|
return -EBADF;
|
||||||
goto e_source_fput;
|
|
||||||
}
|
|
||||||
|
|
||||||
source_kvm = fd_file(f)->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;
|
return ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mirrors of mirrors should work, but let's not get silly. Also
|
* Mirrors of mirrors should work, but let's not get silly. Also
|
||||||
@ -2857,8 +2846,6 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd)
|
|||||||
|
|
||||||
e_unlock:
|
e_unlock:
|
||||||
sev_unlock_two_vms(kvm, source_kvm);
|
sev_unlock_two_vms(kvm, source_kvm);
|
||||||
e_source_fput:
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,21 +35,19 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
|
|||||||
int fd,
|
int fd,
|
||||||
int32_t priority)
|
int32_t priority)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
struct amdgpu_fpriv *fpriv;
|
struct amdgpu_fpriv *fpriv;
|
||||||
struct amdgpu_ctx_mgr *mgr;
|
struct amdgpu_ctx_mgr *mgr;
|
||||||
struct amdgpu_ctx *ctx;
|
struct amdgpu_ctx *ctx;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
||||||
if (r) {
|
if (r)
|
||||||
fdput(f);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
mgr = &fpriv->ctx_mgr;
|
mgr = &fpriv->ctx_mgr;
|
||||||
mutex_lock(&mgr->lock);
|
mutex_lock(&mgr->lock);
|
||||||
@ -57,7 +55,6 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
|
|||||||
amdgpu_ctx_priority_override(ctx, priority);
|
amdgpu_ctx_priority_override(ctx, priority);
|
||||||
mutex_unlock(&mgr->lock);
|
mutex_unlock(&mgr->lock);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,31 +63,25 @@ static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
|
|||||||
unsigned ctx_id,
|
unsigned ctx_id,
|
||||||
int32_t priority)
|
int32_t priority)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
struct amdgpu_fpriv *fpriv;
|
struct amdgpu_fpriv *fpriv;
|
||||||
struct amdgpu_ctx *ctx;
|
struct amdgpu_ctx *ctx;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
r = amdgpu_file_to_fpriv(fd_file(f), &fpriv);
|
||||||
if (r) {
|
if (r)
|
||||||
fdput(f);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
ctx = amdgpu_ctx_get(fpriv, ctx_id);
|
ctx = amdgpu_ctx_get(fpriv, ctx_id);
|
||||||
|
|
||||||
if (!ctx) {
|
if (!ctx)
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
amdgpu_ctx_priority_override(ctx, priority);
|
amdgpu_ctx_priority_override(ctx, priority);
|
||||||
amdgpu_ctx_put(ctx);
|
amdgpu_ctx_put(ctx);
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,16 +712,14 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
|
|||||||
int fd, u32 *handle)
|
int fd, u32 *handle)
|
||||||
{
|
{
|
||||||
struct drm_syncobj *syncobj;
|
struct drm_syncobj *syncobj;
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (fd_file(f)->f_op != &drm_syncobj_file_fops) {
|
if (fd_file(f)->f_op != &drm_syncobj_file_fops)
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
/* take a reference to put in the idr */
|
/* take a reference to put in the idr */
|
||||||
syncobj = fd_file(f)->private_data;
|
syncobj = fd_file(f)->private_data;
|
||||||
@ -739,7 +737,6 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
|
|||||||
} else
|
} else
|
||||||
drm_syncobj_put(syncobj);
|
drm_syncobj_put(syncobj);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,28 +815,23 @@ void __exit lirc_dev_exit(void)
|
|||||||
|
|
||||||
struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
|
struct rc_dev *rc_dev_get_from_fd(int fd, bool write)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
struct lirc_fh *fh;
|
struct lirc_fh *fh;
|
||||||
struct rc_dev *dev;
|
struct rc_dev *dev;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (fd_file(f)->f_op != &lirc_fops) {
|
if (fd_file(f)->f_op != &lirc_fops)
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
|
||||||
|
|
||||||
if (write && !(fd_file(f)->f_mode & FMODE_WRITE)) {
|
if (write && !(fd_file(f)->f_mode & FMODE_WRITE))
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EPERM);
|
return ERR_PTR(-EPERM);
|
||||||
}
|
|
||||||
|
|
||||||
fh = fd_file(f)->private_data;
|
fh = fd_file(f)->private_data;
|
||||||
dev = fh->rc;
|
dev = fh->rc;
|
||||||
|
|
||||||
get_device(&dev->dev);
|
get_device(&dev->dev);
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
@ -1308,9 +1308,9 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
|
|||||||
ret = btrfs_mksubvol(&file->f_path, idmap, name,
|
ret = btrfs_mksubvol(&file->f_path, idmap, name,
|
||||||
namelen, NULL, readonly, inherit);
|
namelen, NULL, readonly, inherit);
|
||||||
} else {
|
} else {
|
||||||
struct fd src = fdget(fd);
|
CLASS(fd, src)(fd);
|
||||||
struct inode *src_inode;
|
struct inode *src_inode;
|
||||||
if (!fd_file(src)) {
|
if (fd_empty(src)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out_drop_write;
|
goto out_drop_write;
|
||||||
}
|
}
|
||||||
@ -1341,7 +1341,6 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
|
|||||||
BTRFS_I(src_inode)->root,
|
BTRFS_I(src_inode)->root,
|
||||||
readonly, inherit);
|
readonly, inherit);
|
||||||
}
|
}
|
||||||
fdput(src);
|
|
||||||
}
|
}
|
||||||
out_drop_write:
|
out_drop_write:
|
||||||
mnt_drop_write_file(file);
|
mnt_drop_write_file(file);
|
||||||
|
@ -347,13 +347,10 @@ EXPORT_SYMBOL_GPL(eventfd_fget);
|
|||||||
*/
|
*/
|
||||||
struct eventfd_ctx *eventfd_ctx_fdget(int fd)
|
struct eventfd_ctx *eventfd_ctx_fdget(int fd)
|
||||||
{
|
{
|
||||||
struct eventfd_ctx *ctx;
|
CLASS(fd, f)(fd);
|
||||||
struct fd f = fdget(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
ctx = eventfd_ctx_fileget(fd_file(f));
|
return eventfd_ctx_fileget(fd_file(f));
|
||||||
fdput(f);
|
|
||||||
return ctx;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(eventfd_ctx_fdget);
|
EXPORT_SYMBOL_GPL(eventfd_ctx_fdget);
|
||||||
|
|
||||||
|
@ -2254,25 +2254,22 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
int full_check = 0;
|
int full_check = 0;
|
||||||
struct fd f, tf;
|
|
||||||
struct eventpoll *ep;
|
struct eventpoll *ep;
|
||||||
struct epitem *epi;
|
struct epitem *epi;
|
||||||
struct eventpoll *tep = NULL;
|
struct eventpoll *tep = NULL;
|
||||||
|
|
||||||
error = -EBADF;
|
CLASS(fd, f)(epfd);
|
||||||
f = fdget(epfd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
return -EBADF;
|
||||||
goto error_return;
|
|
||||||
|
|
||||||
/* Get the "struct file *" for the target file */
|
/* Get the "struct file *" for the target file */
|
||||||
tf = fdget(fd);
|
CLASS(fd, tf)(fd);
|
||||||
if (!fd_file(tf))
|
if (fd_empty(tf))
|
||||||
goto error_fput;
|
return -EBADF;
|
||||||
|
|
||||||
/* The target file descriptor must support poll */
|
/* The target file descriptor must support poll */
|
||||||
error = -EPERM;
|
|
||||||
if (!file_can_poll(fd_file(tf)))
|
if (!file_can_poll(fd_file(tf)))
|
||||||
goto error_tgt_fput;
|
return -EPERM;
|
||||||
|
|
||||||
/* Check if EPOLLWAKEUP is allowed */
|
/* Check if EPOLLWAKEUP is allowed */
|
||||||
if (ep_op_has_event(op))
|
if (ep_op_has_event(op))
|
||||||
@ -2391,12 +2388,6 @@ error_tgt_fput:
|
|||||||
loop_check_gen++;
|
loop_check_gen++;
|
||||||
mutex_unlock(&epnested_mutex);
|
mutex_unlock(&epnested_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
fdput(tf);
|
|
||||||
error_fput:
|
|
||||||
fdput(f);
|
|
||||||
error_return:
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,12 +139,11 @@ static int get_path_from_fd(int fd, struct path *root)
|
|||||||
path_get(root);
|
path_get(root);
|
||||||
spin_unlock(&fs->lock);
|
spin_unlock(&fs->lock);
|
||||||
} else {
|
} else {
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
*root = fd_file(f)->f_path;
|
*root = fd_file(f)->f_path;
|
||||||
path_get(root);
|
path_get(root);
|
||||||
fdput(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
23
fs/ioctl.c
23
fs/ioctl.c
@ -231,11 +231,11 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap)
|
|||||||
static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
|
static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
|
||||||
u64 off, u64 olen, u64 destoff)
|
u64 off, u64 olen, u64 destoff)
|
||||||
{
|
{
|
||||||
struct fd src_file = fdget(srcfd);
|
CLASS(fd, src_file)(srcfd);
|
||||||
loff_t cloned;
|
loff_t cloned;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!fd_file(src_file))
|
if (fd_empty(src_file))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
cloned = vfs_clone_file_range(fd_file(src_file), off, dst_file, destoff,
|
cloned = vfs_clone_file_range(fd_file(src_file), off, dst_file, destoff,
|
||||||
olen, 0);
|
olen, 0);
|
||||||
@ -245,7 +245,6 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
|
|||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
else
|
else
|
||||||
ret = 0;
|
ret = 0;
|
||||||
fdput(src_file);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -892,22 +891,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
|
|||||||
|
|
||||||
SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
|
SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = security_file_ioctl(fd_file(f), cmd, arg);
|
error = security_file_ioctl(fd_file(f), cmd, arg);
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
return error;
|
||||||
|
|
||||||
error = do_vfs_ioctl(fd_file(f), fd, cmd, arg);
|
error = do_vfs_ioctl(fd_file(f), fd, cmd, arg);
|
||||||
if (error == -ENOIOCTLCMD)
|
if (error == -ENOIOCTLCMD)
|
||||||
error = vfs_ioctl(fd_file(f), cmd, arg);
|
error = vfs_ioctl(fd_file(f), cmd, arg);
|
||||||
|
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,15 +947,15 @@ EXPORT_SYMBOL(compat_ptr_ioctl);
|
|||||||
COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
|
COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
|
||||||
compat_ulong_t, arg)
|
compat_ulong_t, arg)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = security_file_ioctl_compat(fd_file(f), cmd, arg);
|
error = security_file_ioctl_compat(fd_file(f), cmd, arg);
|
||||||
if (error)
|
if (error)
|
||||||
goto out;
|
return error;
|
||||||
|
|
||||||
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() */
|
||||||
@ -1009,10 +1006,6 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
|
|||||||
error = -ENOTTY;
|
error = -ENOTTY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -175,15 +175,11 @@ ssize_t kernel_read_file_from_fd(int fd, loff_t offset, void **buf,
|
|||||||
size_t buf_size, size_t *file_size,
|
size_t buf_size, size_t *file_size,
|
||||||
enum kernel_read_file_id id)
|
enum kernel_read_file_id id)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
ssize_t ret = -EBADF;
|
|
||||||
|
|
||||||
if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
|
if (fd_empty(f) || !(fd_file(f)->f_mode & FMODE_READ))
|
||||||
goto out;
|
return -EBADF;
|
||||||
|
|
||||||
ret = kernel_read_file(fd_file(f), offset, buf, buf_size, file_size, id);
|
return kernel_read_file(fd_file(f), offset, buf, buf_size, file_size, id);
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(kernel_read_file_from_fd);
|
EXPORT_SYMBOL_GPL(kernel_read_file_from_fd);
|
||||||
|
@ -1003,22 +1003,17 @@ static int fanotify_find_path(int dfd, const char __user *filename,
|
|||||||
dfd, filename, flags);
|
dfd, filename, flags);
|
||||||
|
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
struct fd f = fdget(dfd);
|
CLASS(fd, f)(dfd);
|
||||||
|
|
||||||
ret = -EBADF;
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
return -EBADF;
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = -ENOTDIR;
|
|
||||||
if ((flags & FAN_MARK_ONLYDIR) &&
|
if ((flags & FAN_MARK_ONLYDIR) &&
|
||||||
!(S_ISDIR(file_inode(fd_file(f))->i_mode))) {
|
!(S_ISDIR(file_inode(fd_file(f))->i_mode)))
|
||||||
fdput(f);
|
return -ENOTDIR;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
*path = fd_file(f)->f_path;
|
*path = fd_file(f)->f_path;
|
||||||
path_get(path);
|
path_get(path);
|
||||||
fdput(f);
|
|
||||||
} else {
|
} else {
|
||||||
unsigned int lookup_flags = 0;
|
unsigned int lookup_flags = 0;
|
||||||
|
|
||||||
|
@ -794,33 +794,26 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
|
|||||||
{
|
{
|
||||||
struct fsnotify_group *group;
|
struct fsnotify_group *group;
|
||||||
struct inotify_inode_mark *i_mark;
|
struct inotify_inode_mark *i_mark;
|
||||||
struct fd f;
|
CLASS(fd, f)(fd);
|
||||||
int ret = -EINVAL;
|
|
||||||
|
|
||||||
f = fdget(fd);
|
if (fd_empty(f))
|
||||||
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(fd_file(f)->f_op != &inotify_fops))
|
if (unlikely(fd_file(f)->f_op != &inotify_fops))
|
||||||
goto out;
|
return -EINVAL;
|
||||||
|
|
||||||
group = fd_file(f)->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))
|
||||||
goto out;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
fsnotify_destroy_mark(&i_mark->fsn_mark, group);
|
fsnotify_destroy_mark(&i_mark->fsn_mark, group);
|
||||||
|
|
||||||
/* match ref taken by inotify_idr_find */
|
/* match ref taken by inotify_idr_find */
|
||||||
fsnotify_put_mark(&i_mark->fsn_mark);
|
fsnotify_put_mark(&i_mark->fsn_mark);
|
||||||
|
return 0;
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
36
fs/open.c
36
fs/open.c
@ -349,14 +349,12 @@ EXPORT_SYMBOL_GPL(vfs_fallocate);
|
|||||||
|
|
||||||
int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)
|
int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int error = -EBADF;
|
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (fd_empty(f))
|
||||||
error = vfs_fallocate(fd_file(f), mode, offset, len);
|
return -EBADF;
|
||||||
fdput(f);
|
|
||||||
}
|
return vfs_fallocate(fd_file(f), mode, offset, len);
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
|
SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
|
||||||
@ -666,14 +664,12 @@ int vfs_fchmod(struct file *file, umode_t mode)
|
|||||||
|
|
||||||
SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
|
SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int err = -EBADF;
|
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (fd_empty(f))
|
||||||
err = vfs_fchmod(fd_file(f), mode);
|
return -EBADF;
|
||||||
fdput(f);
|
|
||||||
}
|
return vfs_fchmod(fd_file(f), mode);
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_fchmodat(int dfd, const char __user *filename, umode_t mode,
|
static int do_fchmodat(int dfd, const char __user *filename, umode_t mode,
|
||||||
@ -860,14 +856,12 @@ int vfs_fchown(struct file *file, uid_t user, gid_t group)
|
|||||||
|
|
||||||
int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
|
int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int error = -EBADF;
|
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (fd_empty(f))
|
||||||
error = vfs_fchown(fd_file(f), user, group);
|
return -EBADF;
|
||||||
fdput(f);
|
|
||||||
}
|
return vfs_fchown(fd_file(f), user, group);
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
|
SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
|
||||||
|
@ -1663,36 +1663,32 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
|
|||||||
{
|
{
|
||||||
loff_t pos_in;
|
loff_t pos_in;
|
||||||
loff_t pos_out;
|
loff_t pos_out;
|
||||||
struct fd f_in;
|
|
||||||
struct fd f_out;
|
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
f_in = fdget(fd_in);
|
CLASS(fd, f_in)(fd_in);
|
||||||
if (!fd_file(f_in))
|
if (fd_empty(f_in))
|
||||||
goto out2;
|
return -EBADF;
|
||||||
|
|
||||||
f_out = fdget(fd_out);
|
CLASS(fd, f_out)(fd_out);
|
||||||
if (!fd_file(f_out))
|
if (fd_empty(f_out))
|
||||||
goto out1;
|
return -EBADF;
|
||||||
|
|
||||||
ret = -EFAULT;
|
|
||||||
if (off_in) {
|
if (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;
|
return -EFAULT;
|
||||||
} else {
|
} else {
|
||||||
pos_in = fd_file(f_in)->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;
|
return -EFAULT;
|
||||||
} else {
|
} else {
|
||||||
pos_out = fd_file(f_out)->f_pos;
|
pos_out = fd_file(f_out)->f_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = -EINVAL;
|
|
||||||
if (flags != 0)
|
if (flags != 0)
|
||||||
goto out;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = vfs_copy_file_range(fd_file(f_in), pos_in, fd_file(f_out), pos_out, len,
|
ret = vfs_copy_file_range(fd_file(f_in), pos_in, fd_file(f_out), pos_out, len,
|
||||||
flags);
|
flags);
|
||||||
@ -1714,12 +1710,6 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
|
|||||||
fd_file(f_out)->f_pos = pos_out;
|
fd_file(f_out)->f_pos = pos_out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
fdput(f_out);
|
|
||||||
out1:
|
|
||||||
fdput(f_in);
|
|
||||||
out2:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,20 +288,17 @@ 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);
|
CLASS(fd, f)(ufd);
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
ctx = fd_file(f)->private_data;
|
ctx = fd_file(f)->private_data;
|
||||||
if (fd_file(f)->f_op != &signalfd_fops) {
|
if (fd_file(f)->f_op != &signalfd_fops)
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
ctx->sigmask = *mask;
|
ctx->sigmask = *mask;
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
|
|
||||||
wake_up(¤t->sighand->signalfd_wqh);
|
wake_up(¤t->sighand->signalfd_wqh);
|
||||||
fdput(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ufd;
|
return ufd;
|
||||||
|
29
fs/sync.c
29
fs/sync.c
@ -148,11 +148,11 @@ void emergency_sync(void)
|
|||||||
*/
|
*/
|
||||||
SYSCALL_DEFINE1(syncfs, int, fd)
|
SYSCALL_DEFINE1(syncfs, int, fd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
struct super_block *sb;
|
struct super_block *sb;
|
||||||
int ret, ret2;
|
int ret, ret2;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
sb = fd_file(f)->f_path.dentry->d_sb;
|
sb = fd_file(f)->f_path.dentry->d_sb;
|
||||||
|
|
||||||
@ -162,7 +162,6 @@ SYSCALL_DEFINE1(syncfs, int, fd)
|
|||||||
|
|
||||||
ret2 = errseq_check_and_advance(&sb->s_wb_err, &fd_file(f)->f_sb_err);
|
ret2 = errseq_check_and_advance(&sb->s_wb_err, &fd_file(f)->f_sb_err);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return ret ? ret : ret2;
|
return ret ? ret : ret2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,14 +204,12 @@ EXPORT_SYMBOL(vfs_fsync);
|
|||||||
|
|
||||||
static int do_fsync(unsigned int fd, int datasync)
|
static int do_fsync(unsigned int fd, int datasync)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int ret = -EBADF;
|
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (fd_empty(f))
|
||||||
ret = vfs_fsync(fd_file(f), datasync);
|
return -EBADF;
|
||||||
fdput(f);
|
|
||||||
}
|
return vfs_fsync(fd_file(f), datasync);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE1(fsync, unsigned int, fd)
|
SYSCALL_DEFINE1(fsync, unsigned int, fd)
|
||||||
@ -355,16 +352,12 @@ out:
|
|||||||
int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
|
int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret;
|
CLASS(fd, f)(fd);
|
||||||
struct fd f;
|
|
||||||
|
|
||||||
ret = -EBADF;
|
if (fd_empty(f))
|
||||||
f = fdget(fd);
|
return -EBADF;
|
||||||
if (fd_file(f))
|
|
||||||
ret = sync_file_range(fd_file(f), offset, nbytes, flags);
|
|
||||||
|
|
||||||
fdput(f);
|
return sync_file_range(fd_file(f), offset, nbytes, flags);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE4(sync_file_range, int, fd, loff_t, offset, loff_t, nbytes,
|
SYSCALL_DEFINE4(sync_file_range, int, fd, loff_t, offset, loff_t, nbytes,
|
||||||
|
@ -106,29 +106,21 @@ static struct io_sq_data *io_attach_sq_data(struct io_uring_params *p)
|
|||||||
{
|
{
|
||||||
struct io_ring_ctx *ctx_attach;
|
struct io_ring_ctx *ctx_attach;
|
||||||
struct io_sq_data *sqd;
|
struct io_sq_data *sqd;
|
||||||
struct fd f;
|
CLASS(fd, f)(p->wq_fd);
|
||||||
|
|
||||||
f = fdget(p->wq_fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return ERR_PTR(-ENXIO);
|
return ERR_PTR(-ENXIO);
|
||||||
if (!io_is_uring_fops(fd_file(f))) {
|
if (!io_is_uring_fops(fd_file(f)))
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
|
||||||
|
|
||||||
ctx_attach = fd_file(f)->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);
|
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
if (sqd->task_tgid != current->tgid)
|
||||||
if (sqd->task_tgid != current->tgid) {
|
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EPERM);
|
return ERR_PTR(-EPERM);
|
||||||
}
|
|
||||||
|
|
||||||
refcount_inc(&sqd->refs);
|
refcount_inc(&sqd->refs);
|
||||||
fdput(f);
|
|
||||||
return sqd;
|
return sqd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,16 +409,11 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx,
|
|||||||
/* Retain compatibility with failing for an invalid attach attempt */
|
/* Retain compatibility with failing for an invalid attach attempt */
|
||||||
if ((ctx->flags & (IORING_SETUP_ATTACH_WQ | IORING_SETUP_SQPOLL)) ==
|
if ((ctx->flags & (IORING_SETUP_ATTACH_WQ | IORING_SETUP_SQPOLL)) ==
|
||||||
IORING_SETUP_ATTACH_WQ) {
|
IORING_SETUP_ATTACH_WQ) {
|
||||||
struct fd f;
|
CLASS(fd, f)(p->wq_fd);
|
||||||
|
if (fd_empty(f))
|
||||||
f = fdget(p->wq_fd);
|
|
||||||
if (!fd_file(f))
|
|
||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
if (!io_is_uring_fops(fd_file(f))) {
|
if (!io_is_uring_fops(fd_file(f)))
|
||||||
fdput(f);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
fdput(f);
|
|
||||||
}
|
}
|
||||||
if (ctx->flags & IORING_SETUP_SQPOLL) {
|
if (ctx->flags & IORING_SETUP_SQPOLL) {
|
||||||
struct task_struct *tsk;
|
struct task_struct *tsk;
|
||||||
|
@ -966,22 +966,20 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
|
|||||||
{
|
{
|
||||||
struct perf_cgroup *cgrp;
|
struct perf_cgroup *cgrp;
|
||||||
struct cgroup_subsys_state *css;
|
struct cgroup_subsys_state *css;
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
css = css_tryget_online_from_dir(fd_file(f)->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);
|
return PTR_ERR(css);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = perf_cgroup_ensure_storage(event, css);
|
ret = perf_cgroup_ensure_storage(event, css);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
cgrp = container_of(css, struct perf_cgroup, css);
|
cgrp = container_of(css, struct perf_cgroup, css);
|
||||||
event->cgrp = cgrp;
|
event->cgrp = cgrp;
|
||||||
@ -995,8 +993,6 @@ static inline int perf_cgroup_connect(int fd, struct perf_event *event,
|
|||||||
perf_detach_cgroup(event);
|
perf_detach_cgroup(event);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,12 +545,12 @@ static void commit_nsset(struct nsset *nsset)
|
|||||||
|
|
||||||
SYSCALL_DEFINE2(setns, int, fd, int, flags)
|
SYSCALL_DEFINE2(setns, int, fd, int, flags)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
struct ns_common *ns = NULL;
|
struct ns_common *ns = NULL;
|
||||||
struct nsset nsset = {};
|
struct nsset nsset = {};
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (proc_ns_file(fd_file(f))) {
|
if (proc_ns_file(fd_file(f))) {
|
||||||
@ -580,7 +580,6 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags)
|
|||||||
}
|
}
|
||||||
put_nsset(&nsset);
|
put_nsset(&nsset);
|
||||||
out:
|
out:
|
||||||
fdput(f);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,11 +536,10 @@ EXPORT_SYMBOL_GPL(find_ge_pid);
|
|||||||
|
|
||||||
struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
|
struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
|
||||||
{
|
{
|
||||||
struct fd f;
|
CLASS(fd, f)(fd);
|
||||||
struct pid *pid;
|
struct pid *pid;
|
||||||
|
|
||||||
f = fdget(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
pid = pidfd_pid(fd_file(f));
|
pid = pidfd_pid(fd_file(f));
|
||||||
@ -548,8 +547,6 @@ struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags)
|
|||||||
get_pid(pid);
|
get_pid(pid);
|
||||||
*flags = fd_file(f)->f_flags;
|
*flags = fd_file(f)->f_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
kernel/sys.c
15
kernel/sys.c
@ -1911,12 +1911,11 @@ SYSCALL_DEFINE1(umask, int, mask)
|
|||||||
|
|
||||||
static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
|
static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
|
||||||
{
|
{
|
||||||
struct fd exe;
|
CLASS(fd, exe)(fd);
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
exe = fdget(fd);
|
if (fd_empty(exe))
|
||||||
if (!fd_file(exe))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
inode = file_inode(fd_file(exe));
|
inode = file_inode(fd_file(exe));
|
||||||
@ -1926,18 +1925,14 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
|
|||||||
* sure that this one is executable as well, to avoid breaking an
|
* sure that this one is executable as well, to avoid breaking an
|
||||||
* overall picture.
|
* overall picture.
|
||||||
*/
|
*/
|
||||||
err = -EACCES;
|
|
||||||
if (!S_ISREG(inode->i_mode) || path_noexec(&fd_file(exe)->f_path))
|
if (!S_ISREG(inode->i_mode) || path_noexec(&fd_file(exe)->f_path))
|
||||||
goto exit;
|
return -EACCES;
|
||||||
|
|
||||||
err = file_permission(fd_file(exe), MAY_EXEC);
|
err = file_permission(fd_file(exe), MAY_EXEC);
|
||||||
if (err)
|
if (err)
|
||||||
goto exit;
|
return err;
|
||||||
|
|
||||||
err = replace_mm_exe_file(mm, fd_file(exe));
|
return replace_mm_exe_file(mm, fd_file(exe));
|
||||||
exit:
|
|
||||||
fdput(exe);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -663,16 +663,14 @@ struct watch_queue *get_watch_queue(int fd)
|
|||||||
{
|
{
|
||||||
struct pipe_inode_info *pipe;
|
struct pipe_inode_info *pipe;
|
||||||
struct watch_queue *wqueue = ERR_PTR(-EINVAL);
|
struct watch_queue *wqueue = ERR_PTR(-EINVAL);
|
||||||
struct fd f;
|
CLASS(fd, f)(fd);
|
||||||
|
|
||||||
f = fdget(fd);
|
if (!fd_empty(f)) {
|
||||||
if (fd_file(f)) {
|
|
||||||
pipe = get_pipe_info(fd_file(f), 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);
|
||||||
}
|
}
|
||||||
fdput(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return wqueue;
|
return wqueue;
|
||||||
|
10
mm/fadvise.c
10
mm/fadvise.c
@ -190,16 +190,12 @@ EXPORT_SYMBOL(vfs_fadvise);
|
|||||||
|
|
||||||
int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
|
int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = vfs_fadvise(fd_file(f), offset, len, advice);
|
return vfs_fadvise(fd_file(f), offset, len, advice);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice)
|
SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice)
|
||||||
|
@ -673,29 +673,22 @@ EXPORT_SYMBOL_GPL(page_cache_async_ra);
|
|||||||
|
|
||||||
ssize_t ksys_readahead(int fd, loff_t offset, size_t count)
|
ssize_t ksys_readahead(int fd, loff_t offset, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
CLASS(fd, f)(fd);
|
||||||
struct fd f;
|
|
||||||
|
|
||||||
ret = -EBADF;
|
if (fd_empty(f) || !(fd_file(f)->f_mode & FMODE_READ))
|
||||||
f = fdget(fd);
|
return -EBADF;
|
||||||
if (!fd_file(f) || !(fd_file(f)->f_mode & FMODE_READ))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The readahead() syscall is intended to run only on files
|
* The readahead() syscall is intended to run only on files
|
||||||
* that can execute readahead. If readahead is not possible
|
* that can execute readahead. If readahead is not possible
|
||||||
* on this file, then we must return -EINVAL.
|
* on this file, then we must return -EINVAL.
|
||||||
*/
|
*/
|
||||||
ret = -EINVAL;
|
|
||||||
if (!fd_file(f)->f_mapping || !fd_file(f)->f_mapping->a_ops ||
|
if (!fd_file(f)->f_mapping || !fd_file(f)->f_mapping->a_ops ||
|
||||||
(!S_ISREG(file_inode(fd_file(f))->i_mode) &&
|
(!S_ISREG(file_inode(fd_file(f))->i_mode) &&
|
||||||
!S_ISBLK(file_inode(fd_file(f))->i_mode)))
|
!S_ISBLK(file_inode(fd_file(f))->i_mode)))
|
||||||
goto out;
|
return -EINVAL;
|
||||||
|
|
||||||
ret = vfs_fadvise(fd_file(f), offset, count, POSIX_FADV_WILLNEED);
|
return vfs_fadvise(fd_file(f), offset, count, POSIX_FADV_WILLNEED);
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count)
|
SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count)
|
||||||
|
@ -694,20 +694,18 @@ EXPORT_SYMBOL_GPL(get_net_ns);
|
|||||||
|
|
||||||
struct net *get_net_ns_by_fd(int fd)
|
struct net *get_net_ns_by_fd(int fd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
CLASS(fd, f)(fd);
|
||||||
struct net *net = ERR_PTR(-EINVAL);
|
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (proc_ns_file(fd_file(f))) {
|
if (proc_ns_file(fd_file(f))) {
|
||||||
struct ns_common *ns = get_proc_ns(file_inode(fd_file(f)));
|
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));
|
return get_net(container_of(ns, struct net, ns));
|
||||||
}
|
}
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return net;
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(get_net_ns_by_fd);
|
EXPORT_SYMBOL_GPL(get_net_ns_by_fd);
|
||||||
#endif
|
#endif
|
||||||
|
@ -241,31 +241,21 @@ SYSCALL_DEFINE3(landlock_create_ruleset,
|
|||||||
static struct landlock_ruleset *get_ruleset_from_fd(const int fd,
|
static struct landlock_ruleset *get_ruleset_from_fd(const int fd,
|
||||||
const fmode_t mode)
|
const fmode_t mode)
|
||||||
{
|
{
|
||||||
struct fd ruleset_f;
|
CLASS(fd, ruleset_f)(fd);
|
||||||
struct landlock_ruleset *ruleset;
|
struct landlock_ruleset *ruleset;
|
||||||
|
|
||||||
ruleset_f = fdget(fd);
|
if (fd_empty(ruleset_f))
|
||||||
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 (fd_file(ruleset_f)->f_op != &ruleset_fops) {
|
if (fd_file(ruleset_f)->f_op != &ruleset_fops)
|
||||||
ruleset = ERR_PTR(-EBADFD);
|
return ERR_PTR(-EBADFD);
|
||||||
goto out_fdput;
|
if (!(fd_file(ruleset_f)->f_mode & mode))
|
||||||
}
|
return ERR_PTR(-EPERM);
|
||||||
if (!(fd_file(ruleset_f)->f_mode & mode)) {
|
|
||||||
ruleset = ERR_PTR(-EPERM);
|
|
||||||
goto out_fdput;
|
|
||||||
}
|
|
||||||
ruleset = fd_file(ruleset_f)->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);
|
return ERR_PTR(-EINVAL);
|
||||||
goto out_fdput;
|
|
||||||
}
|
|
||||||
landlock_get_ruleset(ruleset);
|
landlock_get_ruleset(ruleset);
|
||||||
|
|
||||||
out_fdput:
|
|
||||||
fdput(ruleset_f);
|
|
||||||
return ruleset;
|
return ruleset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,11 +190,10 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
|
|||||||
{
|
{
|
||||||
struct kvm_vfio *kv = dev->private;
|
struct kvm_vfio *kv = dev->private;
|
||||||
struct kvm_vfio_file *kvf;
|
struct kvm_vfio_file *kvf;
|
||||||
struct fd f;
|
CLASS(fd, f)(fd);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
f = fdget(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
@ -220,9 +219,6 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
|
|||||||
kvm_vfio_update_coherency(dev);
|
kvm_vfio_update_coherency(dev);
|
||||||
|
|
||||||
mutex_unlock(&kv->lock);
|
mutex_unlock(&kv->lock);
|
||||||
|
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user