Patch "btrfs: send: limit number of clones and allocated memory size" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    btrfs: send: limit number of clones and allocated memory size

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     btrfs-send-limit-number-of-clones-and-allocated-memo.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit c853ef438e2e2941bb50c9affc3614a2c18817a1
Author: David Sterba <dsterba@xxxxxxxx>
Date:   Tue Jan 24 20:32:10 2023 +0100

    btrfs: send: limit number of clones and allocated memory size
    
    [ Upstream commit 33e17b3f5ab74af12aca58c515bc8424ff69a343 ]
    
    The arg->clone_sources_count is u64 and can trigger a warning when a
    huge value is passed from user space and a huge array is allocated.
    Limit the allocated memory to 8MiB (can be increased if needed), which
    in turn limits the number of clone sources to 8M / sizeof(struct
    clone_root) = 8M / 40 = 209715.  Real world number of clones is from
    tens to hundreds, so this is future proof.
    
    Reported-by: syzbot+4376a9a073770c173269@xxxxxxxxxxxxxxxxxxxxxxxxx
    Signed-off-by: David Sterba <dsterba@xxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 1c4b693ee4a3a..937b60ae576e0 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -7839,10 +7839,10 @@ long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
 	/*
 	 * Check that we don't overflow at later allocations, we request
 	 * clone_sources_count + 1 items, and compare to unsigned long inside
-	 * access_ok.
+	 * access_ok. Also set an upper limit for allocation size so this can't
+	 * easily exhaust memory. Max number of clone sources is about 200K.
 	 */
-	if (arg->clone_sources_count >
-	    ULONG_MAX / sizeof(struct clone_root) - 1) {
+	if (arg->clone_sources_count > SZ_8M / sizeof(struct clone_root)) {
 		ret = -EINVAL;
 		goto out;
 	}



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux