Skip to content

Commit 33e17b3

Browse files
committed
btrfs: send: limit number of clones and allocated memory size
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: [email protected] Signed-off-by: David Sterba <[email protected]>
1 parent eadd7de commit 33e17b3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/btrfs/send.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8072,10 +8072,10 @@ long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
80728072
/*
80738073
* Check that we don't overflow at later allocations, we request
80748074
* clone_sources_count + 1 items, and compare to unsigned long inside
8075-
* access_ok.
8075+
* access_ok. Also set an upper limit for allocation size so this can't
8076+
* easily exhaust memory. Max number of clone sources is about 200K.
80768077
*/
8077-
if (arg->clone_sources_count >
8078-
ULONG_MAX / sizeof(struct clone_root) - 1) {
8078+
if (arg->clone_sources_count > SZ_8M / sizeof(struct clone_root)) {
80798079
ret = -EINVAL;
80808080
goto out;
80818081
}

0 commit comments

Comments
 (0)