ptp: fix integer overflow in max_vclocks_store
authorDan Carpenter <dan.carpenter@linaro.org>
Mon, 17 Jun 2024 09:34:32 +0000 (12:34 +0300)
committerJakub Kicinski <kuba@kernel.org>
Tue, 18 Jun 2024 20:26:44 +0000 (13:26 -0700)
On 32bit systems, the "4 * max" multiply can overflow.  Use kcalloc()
to do the allocation to prevent this.

Fixes: 44c494c8e30e ("ptp: track available ptp vclocks information")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Heng Qi <hengqi@linux.alibaba.com>
Link: https://lore.kernel.org/r/ee8110ed-6619-4bd7-9024-28c1f2ac24f4@moroto.mountain
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/ptp/ptp_sysfs.c

index a15460aaa03b3a069b6f2f68967b04f47cb52d77..6b1b8f57cd9510f269c86dd89a7a74f277f6916b 100644 (file)
@@ -296,8 +296,7 @@ static ssize_t max_vclocks_store(struct device *dev,
        if (max < ptp->n_vclocks)
                goto out;
 
-       size = sizeof(int) * max;
-       vclock_index = kzalloc(size, GFP_KERNEL);
+       vclock_index = kcalloc(max, sizeof(int), GFP_KERNEL);
        if (!vclock_index) {
                err = -ENOMEM;
                goto out;