[PATCH 05/11] vfs: use inode_permission in copy_file_range()

Dave Chinner
2018-12-03T08:34:40Z

From: Dave Chinner <dchinner@redhat.com>

Similar to FI_DEDUPERANGE, make copy_file_range() check that we have
write permissions to the destination inode.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
mm/filemap.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/mm/filemap.c b/mm/filemap.c
index 0a170425935b..876df5275514 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3013,6 +3013,11 @@ int generic_copy_file_checks(struct file *file_in, loff_t pos_in,
(file_out->f_flags & O_APPEND))
return -EBADF;

+ /* may sure we really are allowed to write to the destination inode */
+ ret = inode_permission(inode_out, MAY_WRITE);
+ if (ret < 0)
+ return ret;
+
/* Ensure offsets don't wrap. */
if (pos_in + count < pos_in || pos_out + count < pos_out)
return -EOVERFLOW;
--
2.19.1