From: Sasha Levin Date: Wed, 15 Nov 2023 14:37:42 +0000 (-0500) Subject: Fixes for 5.4 X-Git-Tag: v4.14.330~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da9093b341c92a006e7469668cac7baa19d20d6c;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 5.4 Signed-off-by: Sasha Levin --- diff --git a/queue-5.4/btrfs-use-u64-for-buffer-sizes-in-the-tree-search-io.patch b/queue-5.4/btrfs-use-u64-for-buffer-sizes-in-the-tree-search-io.patch new file mode 100644 index 00000000000..5bb47eb60bb --- /dev/null +++ b/queue-5.4/btrfs-use-u64-for-buffer-sizes-in-the-tree-search-io.patch @@ -0,0 +1,77 @@ +From de1665e67bca07f142ce005470b35e7ba4df475e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 13 Oct 2023 10:05:48 +0100 +Subject: btrfs: use u64 for buffer sizes in the tree search ioctls + +From: Filipe Manana + +[ Upstream commit dec96fc2dcb59723e041416b8dc53e011b4bfc2e ] + +In the tree search v2 ioctl we use the type size_t, which is an unsigned +long, to track the buffer size in the local variable 'buf_size'. An +unsigned long is 32 bits wide on a 32 bits architecture. The buffer size +defined in struct btrfs_ioctl_search_args_v2 is a u64, so when we later +try to copy the local variable 'buf_size' to the argument struct, when +the search returns -EOVERFLOW, we copy only 32 bits which will be a +problem on big endian systems. + +Fix this by using a u64 type for the buffer sizes, not only at +btrfs_ioctl_tree_search_v2(), but also everywhere down the call chain +so that we can use the u64 at btrfs_ioctl_tree_search_v2(). + +Fixes: cc68a8a5a433 ("btrfs: new ioctl TREE_SEARCH_V2") +Reported-by: Dan Carpenter +Link: https://lore.kernel.org/linux-btrfs/ce6f4bd6-9453-4ffe-ba00-cee35495e10f@moroto.mountain/ +Signed-off-by: Filipe Manana +Reviewed-by: David Sterba +Signed-off-by: David Sterba +Signed-off-by: Sasha Levin +--- + fs/btrfs/ioctl.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c +index 775245b148bb3..1575992d1f14c 100644 +--- a/fs/btrfs/ioctl.c ++++ b/fs/btrfs/ioctl.c +@@ -2110,7 +2110,7 @@ static noinline int key_in_sk(struct btrfs_key *key, + static noinline int copy_to_sk(struct btrfs_path *path, + struct btrfs_key *key, + struct btrfs_ioctl_search_key *sk, +- size_t *buf_size, ++ u64 *buf_size, + char __user *ubuf, + unsigned long *sk_offset, + int *num_found) +@@ -2242,7 +2242,7 @@ static noinline int copy_to_sk(struct btrfs_path *path, + + static noinline int search_ioctl(struct inode *inode, + struct btrfs_ioctl_search_key *sk, +- size_t *buf_size, ++ u64 *buf_size, + char __user *ubuf) + { + struct btrfs_fs_info *info = btrfs_sb(inode->i_sb); +@@ -2314,7 +2314,7 @@ static noinline int btrfs_ioctl_tree_search(struct file *file, + struct btrfs_ioctl_search_key sk; + struct inode *inode; + int ret; +- size_t buf_size; ++ u64 buf_size; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; +@@ -2348,8 +2348,8 @@ static noinline int btrfs_ioctl_tree_search_v2(struct file *file, + struct btrfs_ioctl_search_args_v2 args; + struct inode *inode; + int ret; +- size_t buf_size; +- const size_t buf_limit = SZ_16M; ++ u64 buf_size; ++ const u64 buf_limit = SZ_16M; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; +-- +2.42.0 + diff --git a/queue-5.4/series b/queue-5.4/series index 1b2952c6929..2ade113cf2e 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -128,3 +128,4 @@ spi-spi-zynq-qspi-add-spi-mem-to-driver-kconfig-depe.patch fbdev-imsttfb-fix-error-path-of-imsttfb_probe.patch fbdev-imsttfb-fix-a-resource-leak-in-probe.patch fbdev-fsl-diu-fb-mark-wr_reg_wa-static.patch +btrfs-use-u64-for-buffer-sizes-in-the-tree-search-io.patch