amdkfd: use calloc instead of kzalloc to avoid integer overflow
authorDave Airlie <airlied@redhat.com>
Thu, 11 Apr 2024 20:11:25 +0000 (06:11 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 12 Apr 2024 01:11:59 +0000 (11:11 +1000)
This uses calloc instead of doing the multiplication which might
overflow.

Cc: stable@vger.kernel.org
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

index f9631f4b1a02ca5121d7b382fe128c47c7718ec5..55aa74cbc5325e23451aa255dd5ce016e0aa4df8 100644 (file)
@@ -779,8 +779,8 @@ static int kfd_ioctl_get_process_apertures_new(struct file *filp,
         * nodes, but not more than args->num_of_nodes as that is
         * the amount of memory allocated by user
         */
-       pa = kzalloc((sizeof(struct kfd_process_device_apertures) *
-                               args->num_of_nodes), GFP_KERNEL);
+       pa = kcalloc(args->num_of_nodes, sizeof(struct kfd_process_device_apertures),
+                    GFP_KERNEL);
        if (!pa)
                return -ENOMEM;