Skip to contentSkip to conversation

xfs: Add readpage() check up for mmap file at xfs_file_mmap()

PATCH In review Jeff Liu 2 participants 3 messages Jul 18, 2012 – Jul 19, 2012 XFS filesystem

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH 1/1 xfs: Add readpage() check up for mmap file at xfs_file_mmap()

Hello,

When studying XFS code, I found xfs_file_mmap() does not check whether a specific file has readpage() or not. Actually, I have no idea of which kind of file does not supply page reading function, but Btrfs/Ext4 as well as generic_file_mmap() all do this check at first, do we also need a defense here?

Thanks,
-Jeff

---
 fs/xfs/xfs_file.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
fs/xfs/xfs_file.c +5 -0
index 9f7ec15..92ad4a5 100644
@@ -945,6 +945,11 @@ xfs_file_mmap(
 	struct file	*filp,
 	struct vm_area_struct *vma)
 {
+	struct address_space *mapping = file->f_mapping;
+
+	if (!mapping->a_ops->readpage)
+		return -ENOEXEC;
+
 	vma->vm_ops = &xfs_file_vm_ops;
 	vma->vm_flags |= VM_CAN_NONLINEAR;
 
Signature · 6 lines
1.7.9

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 5 lines · Jeff Liu

Hello,

When studying XFS code, I found xfs_file_mmap() does not check whether a specific file has readpage() or not. Actually, I have no idea of which kind of file does not supply page reading function, but Btrfs/Ext4 as well as generic_file_mmap() all do this check at first, do we also need a defense here?

It's not needed. In generic_file_mmap it might make a little sense as any filesystem could use it, but even there's it's questionable because ->readpage is the only way to actually supposed mmap when using generic_file_mmap.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#2 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Jeff Liu

Hello,

When studying XFS code, I found xfs_file_mmap() does not check whether a specific file has readpage() or not. Actually, I have no idea of which kind of file does not supply page reading function, but Btrfs/Ext4 as well as generic_file_mmap() all do this check at first, do we also need a defense here?

It's not needed. In generic_file_mmap it might make a little sense as any filesystem could use it, but even there's it's questionable because ->readpage is the only way to actually supposed mmap when using generic_file_mmap.

Now I got it, thanks for the teaching.

Thanks,
-Jeff

Quoted 5 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs