Skip to content

Commit dfad370

Browse files
amir73ilbrauner
authored andcommitted
remap_range: move permission hooks out of do_clone_file_range()
In many of the vfs helpers, file permission hook is called before taking sb_start_write(), making them "start-write-safe". do_clone_file_range() is an exception to this rule. do_clone_file_range() has two callers - vfs_clone_file_range() and overlayfs. Move remap_verify_area() checks from do_clone_file_range() out to vfs_clone_file_range() to make them "start-write-safe". Overlayfs already has calls to rw_verify_area() with the same security permission hooks as remap_verify_area() has. The rest of the checks in remap_verify_area() are irrelevant for overlayfs that calls do_clone_file_range() offset 0 and positive length. This is needed for fanotify "pre content" events. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent d53471b commit dfad370

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

fs/remap_range.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,6 @@ loff_t do_clone_file_range(struct file *file_in, loff_t pos_in,
385385
if (!file_in->f_op->remap_file_range)
386386
return -EOPNOTSUPP;
387387

388-
ret = remap_verify_area(file_in, pos_in, len, false);
389-
if (ret)
390-
return ret;
391-
392-
ret = remap_verify_area(file_out, pos_out, len, true);
393-
if (ret)
394-
return ret;
395-
396388
ret = file_in->f_op->remap_file_range(file_in, pos_in,
397389
file_out, pos_out, len, remap_flags);
398390
if (ret < 0)
@@ -410,6 +402,14 @@ loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in,
410402
{
411403
loff_t ret;
412404

405+
ret = remap_verify_area(file_in, pos_in, len, false);
406+
if (ret)
407+
return ret;
408+
409+
ret = remap_verify_area(file_out, pos_out, len, true);
410+
if (ret)
411+
return ret;
412+
413413
file_start_write(file_out);
414414
ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len,
415415
remap_flags);

0 commit comments

Comments
 (0)