]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: send: limit number of clones and allocated memory size
authorDavid Sterba <dsterba@suse.com>
Tue, 24 Jan 2023 19:32:10 +0000 (20:32 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Mar 2023 10:52:21 +0000 (11:52 +0100)
commitbedeac053ff6d6dbd186b15dc9f250eb7155bc51
tree50eb9cdfbf7cf9e25ab0ca5feb901533a153c0bd
parente298dcabd9e8a58a1790427a18df9d878ab7c4d7
btrfs: send: limit number of clones and allocated memory size

[ Upstream commit 892ac9d75bc7d9027691416fe197270793863404 ]

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@syzkaller.appspotmail.com
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/send.c