Skip to content

Commit a6849fa

Browse files
Eric W. Biedermangregkh
authored andcommitted
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>
1 parent 5fc6e9c commit a6849fa

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

‎fs/sysfs/bin.c‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,6 @@ static void bin_vma_open(struct vm_area_struct *vma)
190190
sysfs_put_active(attr_sd);
191191
}
192192

193-
static void bin_vma_close(struct vm_area_struct *vma)
194-
{
195-
struct file *file = vma->vm_file;
196-
struct bin_buffer *bb = file->private_data;
197-
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
198-
199-
if (!bb->vm_ops || !bb->vm_ops->close)
200-
return;
201-
202-
if (!sysfs_get_active(attr_sd))
203-
return;
204-
205-
bb->vm_ops->close(vma);
206-
207-
sysfs_put_active(attr_sd);
208-
}
209-
210193
static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
211194
{
212195
struct file *file = vma->vm_file;
@@ -331,7 +314,6 @@ static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
331314

332315
static const struct vm_operations_struct bin_vm_ops = {
333316
.open = bin_vma_open,
334-
.close = bin_vma_close,
335317
.fault = bin_fault,
336318
.page_mkwrite = bin_page_mkwrite,
337319
.access = bin_access,
@@ -377,6 +359,14 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
377359
if (bb->mmapped && bb->vm_ops != vma->vm_ops)
378360
goto out_put;
379361

362+
/*
363+
* It is not possible to successfully wrap close.
364+
* So error if someone is trying to use close.
365+
*/
366+
rc = -EINVAL;
367+
if (vma->vm_ops && vma->vm_ops->close)
368+
goto out_put;
369+
380370
rc = 0;
381371
bb->mmapped = 1;
382372
bb->vm_ops = vma->vm_ops;

0 commit comments

Comments
 (0)