diff mbox series

[v2,08/16] btrfs: move file_start_write() to after permission hook

Message ID 20231122122715.2561213-9-amir73il@gmail.com (mailing list archive)
State New
Headers show
Series Tidy up file permission hooks | expand

Commit Message

Amir Goldstein Nov. 22, 2023, 12:27 p.m. UTC
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>
---
 fs/btrfs/ioctl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Christoph Hellwig Nov. 23, 2023, 7:48 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Jan Kara Nov. 23, 2023, 4:54 p.m. UTC | #2
On Wed 22-11-23 14:27:07, Amir Goldstein wrote:
> 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>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/btrfs/ioctl.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index dfe257e1845b..0a7850c4be67 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4523,29 +4523,29 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
>  	if (ret < 0)
>  		goto out_acct;
>  
> -	file_start_write(file);
> -
>  	if (iov_iter_count(&iter) == 0) {
>  		ret = 0;
> -		goto out_end_write;
> +		goto out_iov;
>  	}
>  	pos = args.offset;
>  	ret = rw_verify_area(WRITE, file, &pos, args.len);
>  	if (ret < 0)
> -		goto out_end_write;
> +		goto out_iov;
>  
>  	init_sync_kiocb(&kiocb, file);
>  	ret = kiocb_set_rw_flags(&kiocb, 0);
>  	if (ret)
> -		goto out_end_write;
> +		goto out_iov;
>  	kiocb.ki_pos = pos;
>  
> +	file_start_write(file);
> +
>  	ret = btrfs_do_write_iter(&kiocb, &iter, &args);
>  	if (ret > 0)
>  		fsnotify_modify(file);
>  
> -out_end_write:
>  	file_end_write(file);
> +out_iov:
>  	kfree(iov);
>  out_acct:
>  	if (ret > 0)
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index dfe257e1845b..0a7850c4be67 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4523,29 +4523,29 @@  static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
 	if (ret < 0)
 		goto out_acct;
 
-	file_start_write(file);
-
 	if (iov_iter_count(&iter) == 0) {
 		ret = 0;
-		goto out_end_write;
+		goto out_iov;
 	}
 	pos = args.offset;
 	ret = rw_verify_area(WRITE, file, &pos, args.len);
 	if (ret < 0)
-		goto out_end_write;
+		goto out_iov;
 
 	init_sync_kiocb(&kiocb, file);
 	ret = kiocb_set_rw_flags(&kiocb, 0);
 	if (ret)
-		goto out_end_write;
+		goto out_iov;
 	kiocb.ki_pos = pos;
 
+	file_start_write(file);
+
 	ret = btrfs_do_write_iter(&kiocb, &iter, &args);
 	if (ret > 0)
 		fsnotify_modify(file);
 
-out_end_write:
 	file_end_write(file);
+out_iov:
 	kfree(iov);
 out_acct:
 	if (ret > 0)