bpf: Switch to krealloc_array()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 29 Apr 2024 12:00:05 +0000 (15:00 +0300)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 29 Apr 2024 23:13:14 +0000 (16:13 -0700)
Let the krealloc_array() copy the original data and
check for a multiplication overflow.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240429120005.3539116-1-andriy.shevchenko@linux.intel.com
kernel/bpf/core.c

index a8ca6dd6e614be55f3840bff1bf25801d913cc87..99b8b1c9a248ca43bed5717e40b933a730ce61fc 100644 (file)
@@ -850,7 +850,7 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
                return -EINVAL;
        }
 
-       tab = krealloc(tab, size * sizeof(*poke), GFP_KERNEL);
+       tab = krealloc_array(tab, size, sizeof(*poke), GFP_KERNEL);
        if (!tab)
                return -ENOMEM;