Commit b6ab5090 authored by Yu Jiaoliang's avatar Yu Jiaoliang Committed by Daniel Borkmann
Browse files

bpf: Use kmemdup_array instead of kmemdup for multiple allocation



Let the kmemdup_array() take care about multiplication and possible
overflows.

Signed-off-by: default avatarYu Jiaoliang <yujiaoliang@vivo.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240821073709.4067177-1-yujiaoliang@vivo.com
parent 1a437d35
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1265,7 +1265,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
	 * so we need to keep the user BPF around until the 2nd
	 * pass. At this time, the user BPF is stored in fp->insns.
	 */
	old_prog = kmemdup(fp->insns, old_len * sizeof(struct sock_filter),
	old_prog = kmemdup_array(fp->insns, old_len, sizeof(struct sock_filter),
				 GFP_KERNEL | __GFP_NOWARN);
	if (!old_prog) {
		err = -ENOMEM;