diff mbox series

[1/2] fs: require inode_owner_or_capable for F_SET_RW_HINT

Message ID 20241122122931.90408-2-hch@lst.de (mailing list archive)
State New
Headers show
Series [1/2] fs: require inode_owner_or_capable for F_SET_RW_HINT | expand

Commit Message

Christoph Hellwig Nov. 22, 2024, 12:29 p.m. UTC
F_SET_RW_HINT controls data placement in the file system and / or
device and should not be available to everyone who can read a given file.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/fcntl.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jan Kara Nov. 22, 2024, 12:45 p.m. UTC | #1
On Fri 22-11-24 13:29:24, Christoph Hellwig wrote:
> F_SET_RW_HINT controls data placement in the file system and / or
> device and should not be available to everyone who can read a given file.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Makes sense. Feel free to add:

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

								Honza

> ---
>  fs/fcntl.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/fcntl.c b/fs/fcntl.c
> index 22dd9dcce7ec..7fc6190da342 100644
> --- a/fs/fcntl.c
> +++ b/fs/fcntl.c
> @@ -375,6 +375,9 @@ static long fcntl_set_rw_hint(struct file *file, unsigned int cmd,
>  	u64 __user *argp = (u64 __user *)arg;
>  	u64 hint;
>  
> +	if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
> +		return -EPERM;
> +
>  	if (copy_from_user(&hint, argp, sizeof(hint)))
>  		return -EFAULT;
>  	if (!rw_hint_valid(hint))
> -- 
> 2.45.2
>
Christian Brauner Nov. 25, 2024, 2:16 p.m. UTC | #2
On Fri, Nov 22, 2024 at 01:29:24PM +0100, Christoph Hellwig wrote:
> F_SET_RW_HINT controls data placement in the file system and / or
> device and should not be available to everyone who can read a given file.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/fcntl.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/fcntl.c b/fs/fcntl.c
> index 22dd9dcce7ec..7fc6190da342 100644
> --- a/fs/fcntl.c
> +++ b/fs/fcntl.c
> @@ -375,6 +375,9 @@ static long fcntl_set_rw_hint(struct file *file, unsigned int cmd,
>  	u64 __user *argp = (u64 __user *)arg;
>  	u64 hint;
>  
> +	if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
> +		return -EPERM;
> +

Bah, nice catch.
Christian Brauner Nov. 25, 2024, 2:17 p.m. UTC | #3
On Fri, 22 Nov 2024 13:29:24 +0100, Christoph Hellwig wrote:
> F_SET_RW_HINT controls data placement in the file system and / or
> device and should not be available to everyone who can read a given file.
> 
> 

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/2] fs: require inode_owner_or_capable for F_SET_RW_HINT
      https://git.kernel.org/vfs/vfs/c/b6512519496e
diff mbox series

Patch

diff --git a/fs/fcntl.c b/fs/fcntl.c
index 22dd9dcce7ec..7fc6190da342 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -375,6 +375,9 @@  static long fcntl_set_rw_hint(struct file *file, unsigned int cmd,
 	u64 __user *argp = (u64 __user *)arg;
 	u64 hint;
 
+	if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
+		return -EPERM;
+
 	if (copy_from_user(&hint, argp, sizeof(hint)))
 		return -EFAULT;
 	if (!rw_hint_valid(hint))