Skip to content

Commit 81d23d2

Browse files
Dan Carpenterkuba-moo
authored andcommitted
ptp: fix integer overflow in max_vclocks_store
On 32bit systems, the "4 * max" multiply can overflow. Use kcalloc() to do the allocation to prevent this. Fixes: 44c494c ("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>
1 parent 88c67ae commit 81d23d2

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/ptp/ptp_sysfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ static ssize_t max_vclocks_store(struct device *dev,
296296
if (max < ptp->n_vclocks)
297297
goto out;
298298

299-
size = sizeof(int) * max;
300-
vclock_index = kzalloc(size, GFP_KERNEL);
299+
vclock_index = kcalloc(max, sizeof(int), GFP_KERNEL);
301300
if (!vclock_index) {
302301
err = -ENOMEM;
303302
goto out;

0 commit comments

Comments
 (0)