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 file_start_write() to after permission hook

In vfs code, file_start_write() is usually called after the permission
hook in rw_verify_area(). vfs_dedupe_file_range_one() is an exception
to this rule.

In vfs_dedupe_file_range_one(), move file_start_write() to after the
the rw_verify_area() checks to make them "start-write-safe".

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-8-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
0b5263d1 dfad3705

+13 -8
+13 -8
fs/remap_range.c
··· 420 420 EXPORT_SYMBOL(vfs_clone_file_range); 421 421 422 422 /* Check whether we are allowed to dedupe the destination file */ 423 - static bool allow_file_dedupe(struct file *file) 423 + static bool may_dedupe_file(struct file *file) 424 424 { 425 425 struct mnt_idmap *idmap = file_mnt_idmap(file); 426 426 struct inode *inode = file_inode(file); ··· 445 445 WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP | 446 446 REMAP_FILE_CAN_SHORTEN)); 447 447 448 - ret = mnt_want_write_file(dst_file); 449 - if (ret) 450 - return ret; 451 - 452 448 /* 453 449 * This is redundant if called from vfs_dedupe_file_range(), but other 454 450 * callers need it and it's not performance sesitive... 455 451 */ 456 452 ret = remap_verify_area(src_file, src_pos, len, false); 457 453 if (ret) 458 - goto out_drop_write; 454 + return ret; 459 455 460 456 ret = remap_verify_area(dst_file, dst_pos, len, true); 461 457 if (ret) 462 - goto out_drop_write; 458 + return ret; 459 + 460 + /* 461 + * This needs to be called after remap_verify_area() because of 462 + * sb_start_write() and before may_dedupe_file() because the mount's 463 + * MAY_WRITE need to be checked with mnt_get_write_access_file() held. 464 + */ 465 + ret = mnt_want_write_file(dst_file); 466 + if (ret) 467 + return ret; 463 468 464 469 ret = -EPERM; 465 - if (!allow_file_dedupe(dst_file)) 470 + if (!may_dedupe_file(dst_file)) 466 471 goto out_drop_write; 467 472 468 473 ret = -EXDEV;