Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <josef@toxicpanda.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/r/20231122122715.2561213-7-amir73il@gmail.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Amir Goldstein and committed by
Christian Brauner
dfad3705 d53471ba

+8 -8
+8 -8
fs/remap_range.c
··· 385 385 if (!file_in->f_op->remap_file_range) 386 386 return -EOPNOTSUPP; 387 387 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 - 396 388 ret = file_in->f_op->remap_file_range(file_in, pos_in, 397 389 file_out, pos_out, len, remap_flags); 398 390 if (ret < 0) ··· 401 409 loff_t len, unsigned int remap_flags) 402 410 { 403 411 loff_t ret; 412 + 413 + ret = remap_verify_area(file_in, pos_in, len, false); 414 + if (ret) 415 + return ret; 416 + 417 + ret = remap_verify_area(file_out, pos_out, len, true); 418 + if (ret) 419 + return ret; 404 420 405 421 file_start_write(file_out); 406 422 ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len,