mirror of https://gitee.com/openkylin/linux.git
sysfs: Fail bin file mmap if vma close is implemented.
It is not reasonably possible to wrap vma->close(). To correctly wrap close would imply calling close on any vmas that remain when sysfs_remove_bin_file is called. Finding the proper lists walking them getting the locking right etc, requires deep knowledge of the mm subsystem and as such would require assistence from the mm subsystem to implement. That assistence does not currently exist. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
5fc6e9cbce
commit
a6849fa1f7
|
@ -190,23 +190,6 @@ static void bin_vma_open(struct vm_area_struct *vma)
|
||||||
sysfs_put_active(attr_sd);
|
sysfs_put_active(attr_sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bin_vma_close(struct vm_area_struct *vma)
|
|
||||||
{
|
|
||||||
struct file *file = vma->vm_file;
|
|
||||||
struct bin_buffer *bb = file->private_data;
|
|
||||||
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
|
|
||||||
|
|
||||||
if (!bb->vm_ops || !bb->vm_ops->close)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!sysfs_get_active(attr_sd))
|
|
||||||
return;
|
|
||||||
|
|
||||||
bb->vm_ops->close(vma);
|
|
||||||
|
|
||||||
sysfs_put_active(attr_sd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
||||||
{
|
{
|
||||||
struct file *file = vma->vm_file;
|
struct file *file = vma->vm_file;
|
||||||
|
@ -331,7 +314,6 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
|
||||||
|
|
||||||
static const struct vm_operations_struct bin_vm_ops = {
|
static const struct vm_operations_struct bin_vm_ops = {
|
||||||
.open = bin_vma_open,
|
.open = bin_vma_open,
|
||||||
.close = bin_vma_close,
|
|
||||||
.fault = bin_fault,
|
.fault = bin_fault,
|
||||||
.page_mkwrite = bin_page_mkwrite,
|
.page_mkwrite = bin_page_mkwrite,
|
||||||
.access = bin_access,
|
.access = bin_access,
|
||||||
|
@ -377,6 +359,14 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
|
||||||
if (bb->mmapped && bb->vm_ops != vma->vm_ops)
|
if (bb->mmapped && bb->vm_ops != vma->vm_ops)
|
||||||
goto out_put;
|
goto out_put;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It is not possible to successfully wrap close.
|
||||||
|
* So error if someone is trying to use close.
|
||||||
|
*/
|
||||||
|
rc = -EINVAL;
|
||||||
|
if (vma->vm_ops && vma->vm_ops->close)
|
||||||
|
goto out_put;
|
||||||
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
bb->mmapped = 1;
|
bb->mmapped = 1;
|
||||||
bb->vm_ops = vma->vm_ops;
|
bb->vm_ops = vma->vm_ops;
|
||||||
|
|
Loading…
Reference in New Issue