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.

btrfs: 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(). btrfs_ioctl_encoded_write() in an exception
to this rule.

Move file_start_write() to after the rw_verify_area() check in encoded
write to make the permission hook "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-9-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
2f4d8ad8 0b5263d1

+6 -6
+6 -6
fs/btrfs/ioctl.c
··· 4523 4523 if (ret < 0) 4524 4524 goto out_acct; 4525 4525 4526 - file_start_write(file); 4527 - 4528 4526 if (iov_iter_count(&iter) == 0) { 4529 4527 ret = 0; 4530 - goto out_end_write; 4528 + goto out_iov; 4531 4529 } 4532 4530 pos = args.offset; 4533 4531 ret = rw_verify_area(WRITE, file, &pos, args.len); 4534 4532 if (ret < 0) 4535 - goto out_end_write; 4533 + goto out_iov; 4536 4534 4537 4535 init_sync_kiocb(&kiocb, file); 4538 4536 ret = kiocb_set_rw_flags(&kiocb, 0); 4539 4537 if (ret) 4540 - goto out_end_write; 4538 + goto out_iov; 4541 4539 kiocb.ki_pos = pos; 4540 + 4541 + file_start_write(file); 4542 4542 4543 4543 ret = btrfs_do_write_iter(&kiocb, &iter, &args); 4544 4544 if (ret > 0) 4545 4545 fsnotify_modify(file); 4546 4546 4547 - out_end_write: 4548 4547 file_end_write(file); 4548 + out_iov: 4549 4549 kfree(iov); 4550 4550 out_acct: 4551 4551 if (ret > 0)