]> git.itanic.dy.fi Git - linux-stable/commitdiff
bcachefs: chardev: fix an integer overflow (32 bit only)
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 14 Sep 2023 14:59:10 +0000 (17:59 +0300)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:14 +0000 (17:10 -0400)
On 32 bit systems, "sizeof(*arg) + replica_entries_bytes" can have an
integer overflow leading to memory corruption.  Use size_add() to
prevent this.

Fixes: b44dd3797034 ("bcachefs: Redo filesystem usage ioctls")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/chardev.c

index e5e9fddddfb5823d73b79d92104bbfacdc994e8a..51d6712677418863aa34d2f39d45a36f6e7ccc12 100644 (file)
@@ -421,7 +421,7 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
        if (get_user(replica_entries_bytes, &user_arg->replica_entries_bytes))
                return -EFAULT;
 
-       arg = kzalloc(sizeof(*arg) + replica_entries_bytes, GFP_KERNEL);
+       arg = kzalloc(size_add(sizeof(*arg), replica_entries_bytes), GFP_KERNEL);
        if (!arg)
                return -ENOMEM;